1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a minimum velocity property to the ContinuousWithMomentum animated position behaviour and increased the minimum velocity of the viewport to avoid some jitter when the viewport animation is close to stand still

This commit is contained in:
hogliux 2017-08-30 15:53:04 +01:00
parent 9b30c2401a
commit d105d9418a
2 changed files with 13 additions and 2 deletions

View file

@ -56,6 +56,13 @@ namespace AnimatedPositionBehaviours
damping = 1.0 - newFriction;
}
/** Sets the minimum velocity of the movement. Any velocity that's slower than
this will stop the animation. The default is 0.05. */
void setMinimumVelocity (double newMinimumVelocityToUse) noexcept
{
minimumVelocity = newMinimumVelocityToUse;
}
/** Called by the AnimatedPosition class. This tells us the position and
velocity at which the user is about to release the object.
The velocity is measured in units/second.
@ -72,7 +79,7 @@ namespace AnimatedPositionBehaviours
{
velocity *= damping;
if (std::abs (velocity) < 0.05)
if (std::abs (velocity) < minimumVelocity)
velocity = 0;
return oldPos + velocity * elapsedSeconds;
@ -87,7 +94,7 @@ namespace AnimatedPositionBehaviours
}
private:
double velocity = 0, damping = 0.92;
double velocity = 0, damping = 0.92, minimumVelocity = 0.05;
};
//==============================================================================

View file

@ -191,6 +191,8 @@ struct Viewport::DragToScrollListener : private MouseListener,
viewport.contentHolder.addMouseListener (this, true);
offsetX.addListener (this);
offsetY.addListener (this);
offsetX.behaviour.setMinimumVelocity (60);
offsetY.behaviour.setMinimumVelocity (60);
}
~DragToScrollListener()
@ -209,6 +211,8 @@ struct Viewport::DragToScrollListener : private MouseListener,
if (doesMouseEventComponentBlockViewportDrag (e.eventComponent))
isViewportDragBlocked = true;
offsetX.setPosition (offsetX.getPosition());
offsetY.setPosition (offsetY.getPosition());
++numTouches;
}