summaryrefslogtreecommitdiffstats
path: root/src/widget/wdisplay.cpp
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2014-01-04 12:51:55 -0500
committerRJ Ryan <rryan@mixxx.org>2014-01-04 12:51:55 -0500
commit75e4b2f487d36b555d80d3d3689b779014b47d62 (patch)
tree89c582f11cfae429a339c2ec1ca302c5005ab774 /src/widget/wdisplay.cpp
parent872e1d81a529e750fdee0233e708ce16caa3523b (diff)
Fix WKnob / WDisplay active pixmap calculation to bias towards the lower of the two middle pixmaps when there are an even number.
Diffstat (limited to 'src/widget/wdisplay.cpp')
-rw-r--r--src/widget/wdisplay.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp
index 7c325e598a..a77ba70ba0 100644
--- a/src/widget/wdisplay.cpp
+++ b/src/widget/wdisplay.cpp
@@ -108,7 +108,43 @@ void WDisplay::setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos,
}
int WDisplay::getActivePixmapIndex() const {
- return static_cast<int>(m_value * m_pixmaps.size());
+ // When there are an even number of pixmaps by convention we want a value of
+ // 0.5 to align to the lower of the two middle pixmaps. In Mixxx < 1.12.0 we
+ // accomplished this by the below formula:
+ // index = (m_value - 64.0/127.0) * (numPixmaps() - 1) + numPixmaps() / 2.0;
+
+ // But it's just as good to use m_value * numPixmaps() - epsilon. Using
+ // numPixmaps() instead of numPixmaps() - 1 ensures that every pixmap shares
+ // an equal slice of the value. Using m_value * (numPixmaps() - 1) gives an
+ // unequal slice of the value to the last pixmaps.
+
+ // Example:
+ // 3 pixmaps
+ // m_value * numPixmaps()
+ // idx: 0 1 2 3
+ // val: 0.0 ... 0.3 ... 0.6 ... 1.0
+ // Even distribution of value range, value 1 is out of bounds (3).
+
+ // m_value * (numPixmaps() - 1)
+ // idx: 0 1 2
+ // val: 0.0 ... 0.5 ... 1.0
+ // Pixmap 2 is only shown at value 1.
+
+ // floor(m_value * (numPixmaps() - 1) + 0.5)
+ // idx: 0 1 2
+ // val: 0.0 ... 0.25 ... 0.75 ... 1.0
+ // Pixmap 0 and Pixmap 2 only shown for 0.25 of value range
+
+ // 4 pixmaps
+ // m_value * numPixmaps()
+ // idx: 0 1 2 3 4
+ // val: 0.0 ... 0.25 ... 0.5 ... 0.75 ... 1.0
+ // Even distribution of value range, value 1 is out of bounds (4).
+
+ // Subtracting an epsilon prevents out of bound values at the end of the
+ // range and biases the middle value towards the lower of the 2 center
+ // pixmaps when there are an even number of pixmaps.
+ return static_cast<int>(m_value * numPixmaps() - 0.00001);
}
void WDisplay::paintEvent(QPaintEvent* ) {