mhh, I’m not sure, i could not reproduce it with this yet with tweaked Range-class, but the problems only occurs once in a while, and the changes will have no effect on the current behaviour.
The point is visibleRange.start should no be recalculated when deltaPixels not differ from the last deltaPixel in mouseDrag
These are exact values when the problem occurs :
visibleRange.start is oscillating between start=0.49714285714285722 and 0.49714285714285716
—> FIRST RANGE START CALCULATION IN void ScrollBar::mouseDrag (const MouseEvent& e)
[code]setCurrentRangeStart (dragStartRange + deltaPixels * (totalRange.getLength() - visibleRange.getLength()) / (thumbAreaSize - thumbSize)
dragStartRange = 0.90000000000000002
deltaPixels = -141
totalRange = {start=0.00000000000000000 end=1.0000000000000000 }
visibleRange = {start=0.49714285714285722 end=0.59714285714285720 }
thumbAreaSize = 355
thumbSize = 40
RESULT = newStart = 0.49714285714285716[/code]
—> SECOND RANGE START CALCULATION IN void ScrollBar::mouseDrag (const MouseEvent& e)
[code]setCurrentRangeStart (dragStartRange + deltaPixels * (totalRange.getLength() - visibleRange.getLength()) / (thumbAreaSize - thumbSize)
dragStartRange = 0.90000000000000002 (NOT CHANGED)
deltaPixels = -141 (NOT CHANGED)
totalRange = {start=0.00000000000000000 end=1.0000000000000000 } (NOT CHANGED)
visibleRange = {start=0.49714285714285716 end=0.59714285714285720 } (CHANGED!!!)
thumbAreaSize = 355 (NOT CHANGED)
thumbSize = 40 (NOT CHANGED)
RESULT = newStart = 0.49714285714285722[/code]
—> THIRD RANGE START CALCULATION IN void ScrollBar::mouseDrag (const MouseEvent& e)
(like the First)
[code]
—> 4th RANGE START CALCULATION IN void ScrollBar::mouseDrag (const MouseEvent& e)
[code]
—> 4th RANGE START CALCULATION IN void ScrollBar::mouseDrag (const MouseEvent& e)
- visibleRange { start = 0.49714285714285716
end = 0.59714285714285720 } [/code]
i think something like this would be a better solution:
[code]void ScrollBar::mouseDrag (const MouseEvent& e)
{
if (isDraggingThumb)
{
const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
if (deltaPixels!=lastDeltaPixels) //NEW
{
setCurrentRangeStart (dragStartRange
+ deltaPixels * (totalRange.getLength() - visibleRange.getLength())
/ (thumbAreaSize - thumbSize));
}
lastDeltaPixels=deltaPixels; //NEW
}
else
{
lastMousePos = (vertical) ? e.y : e.x;
}
}
void ScrollBar::mouseUp (const MouseEvent&)
{
lastDeltaPixels=0; //NEW
isDraggingThumb = false;
stopTimer();
repaint();
}