Skip to content

Commit

Permalink
fix(navigation): improve logic to interrupt animation when mouse wheel
Browse files Browse the repository at this point in the history
moved
  • Loading branch information
jedwards1211 committed Aug 26, 2019
1 parent d43ba0b commit 63c2bb4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion breakout-main/src/main/java/org/breakout/BreakoutMainView.java
Expand Up @@ -878,6 +878,7 @@ public void mouseWheelMoved(MouseWheelEvent e) {
}

class StopAnimationMouseHandler extends MouseAdapter {
long lastWheelTime = 0;
double lastWheelRotation = Double.NaN;

@Override
Expand All @@ -887,16 +888,25 @@ public void mousePressed(MouseEvent e) {

@Override
public void mouseWheelMoved(MouseWheelEvent e) {
long time = System.currentTimeMillis();
double nextWheelRotation = e.getPreciseWheelRotation();
if (!cameraAnimationQueue.isEmpty()) {
// Mac OS generates decelerating scroll events after a flick,
// so we have to consider the following cases "real"
// user-initiated scroll events:
// * scroll reverses direction
// * scroll rotation increases
// * a short time has elapsed since previous scroll event
if (Math.signum(lastWheelRotation) != Math.signum(nextWheelRotation)
|| Math.abs(nextWheelRotation) > Math.abs(lastWheelRotation)) {
|| Math.abs(nextWheelRotation) > Math.abs(lastWheelRotation)
|| time - lastWheelTime > 250) {
removeUnprotectedCameraAnimations();
}
else {
e.consume();
}
}
lastWheelTime = time;
lastWheelRotation = nextWheelRotation;
}
}
Expand Down

0 comments on commit 63c2bb4

Please sign in to comment.