Roller fix
This commit is contained in:
@@ -61,6 +61,11 @@ inline int multDivRoundClosest(int v, int n, int d)
|
|||||||
return divRoundClosest(v * n, d);
|
return divRoundClosest(v * n, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int mod(int k, int n)
|
||||||
|
{
|
||||||
|
return ((k %= n) < 0) ? k + n : k;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline T sgn(T a)
|
inline T sgn(T a)
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-7
@@ -68,7 +68,7 @@ class Roller: public Choice
|
|||||||
void paint(BitmapBuffer * dc) override
|
void paint(BitmapBuffer * dc) override
|
||||||
{
|
{
|
||||||
int32_t value = getValue();
|
int32_t value = getValue();
|
||||||
auto valuesCount = getValuesCount();
|
auto valuesCount = (int)getValuesCount();
|
||||||
if (valuesCount == 0) {
|
if (valuesCount == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -76,11 +76,10 @@ class Roller: public Choice
|
|||||||
int index = (scrollPositionY - ROLLER_LINE_HEIGHT + 1) / ROLLER_LINE_HEIGHT;
|
int index = (scrollPositionY - ROLLER_LINE_HEIGHT + 1) / ROLLER_LINE_HEIGHT;
|
||||||
coord_t y = index * ROLLER_LINE_HEIGHT;
|
coord_t y = index * ROLLER_LINE_HEIGHT;
|
||||||
coord_t yMax = scrollPositionY + 3 * ROLLER_LINE_HEIGHT;
|
coord_t yMax = scrollPositionY + 3 * ROLLER_LINE_HEIGHT;
|
||||||
while (index < 0)
|
index = mod(index, valuesCount);
|
||||||
index += valuesCount;
|
|
||||||
|
|
||||||
while (y < yMax) {
|
while (y < yMax) {
|
||||||
auto displayedValue = getValueFromIndex(index % valuesCount);
|
auto displayedValue = getValueFromIndex(index);
|
||||||
|
|
||||||
auto fgColor = DISABLE_COLOR;
|
auto fgColor = DISABLE_COLOR;
|
||||||
if (value == displayedValue) {
|
if (value == displayedValue) {
|
||||||
@@ -99,7 +98,9 @@ class Roller: public Choice
|
|||||||
dc->drawSolidHorizontalLine(0, y - 10, width(), DISABLE_COLOR);
|
dc->drawSolidHorizontalLine(0, y - 10, width(), DISABLE_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
index += 1;
|
if (++index == valuesCount)
|
||||||
|
index = 0;
|
||||||
|
|
||||||
y += ROLLER_LINE_HEIGHT;
|
y += ROLLER_LINE_HEIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,10 +168,9 @@ class Roller: public Choice
|
|||||||
lastScrollPositionY = scrollPositionY;
|
lastScrollPositionY = scrollPositionY;
|
||||||
|
|
||||||
auto valuesCount = getValuesCount();
|
auto valuesCount = getValuesCount();
|
||||||
auto newValue = getValueFromIndex((((scrollPositionY / ROLLER_LINE_HEIGHT) + 1) + valuesCount) % valuesCount);
|
auto newValue = getValueFromIndex(mod((scrollPositionY / ROLLER_LINE_HEIGHT) + 1, valuesCount));
|
||||||
|
|
||||||
setValue(newValue);
|
setValue(newValue);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user