JUCE
|
Models a 1-dimensional position that can be dragged around by the user, and which will then continue moving with a customisable physics behaviour when released. More...
Classes | |
class | Listener |
Implement this class if you need to receive callbacks when the value of an AnimatedPosition changes. More... | |
Public Member Functions | |
AnimatedPosition () | |
void | setLimits (Range< double > newRange) noexcept |
Sets a range within which the value will be constrained. More... | |
void | beginDrag () |
Called to indicate that the object is now being controlled by a mouse-drag or similar operation. More... | |
void | drag (double deltaFromStartOfDrag) |
Called during a mouse-drag operation, to indicate that the mouse has moved. More... | |
void | endDrag () |
Called after beginDrag() and drag() to indicate that the drag operation has now finished. More... | |
void | nudge (double deltaFromCurrentPosition) |
Called outside of a drag operation to cause a nudge in the specified direction. More... | |
double | getPosition () const noexcept |
Returns the current position. More... | |
void | setPosition (double newPosition) |
Explicitly sets the position and stops any further movement. More... | |
void | addListener (Listener *listener) |
Adds a listener to be called when the value changes. More... | |
void | removeListener (Listener *listener) |
Removes a previously-registered listener. More... | |
Public Attributes | |
Behaviour | behaviour |
The behaviour object. More... | |
Models a 1-dimensional position that can be dragged around by the user, and which will then continue moving with a customisable physics behaviour when released.
This is useful for things like scrollable views or objects that can be dragged and thrown around with the mouse/touch, and by writing your own behaviour class, you can customise the trajectory that it follows when released.
The class uses its own Timer to continuously change its value when a drag ends, and Listener objects can be registered to receive callbacks whenever the value changes.
The value is stored as a double, and can be used to represent whatever units you need.
The template parameter Behaviour must be a class that implements various methods to return the physics of the value's movement - you can use the classes provided for this in the AnimatedPositionBehaviours namespace, or write your own custom behaviour.
AnimatedPosition< Behaviour >::AnimatedPosition | ( | ) |
|
noexcept |
Sets a range within which the value will be constrained.
void AnimatedPosition< Behaviour >::beginDrag | ( | ) |
Called to indicate that the object is now being controlled by a mouse-drag or similar operation.
After calling this method, you should make calls to the drag() method each time the mouse drags the position around, and always be sure to finish with a call to endDrag() when the mouse is released, which allows the position to continue moving freely according to the specified behaviour.
References Timer::stopTimer().
void AnimatedPosition< Behaviour >::drag | ( | double | deltaFromStartOfDrag | ) |
Called during a mouse-drag operation, to indicate that the mouse has moved.
The delta is the difference between the position when beginDrag() was called and the new position that's required.
void AnimatedPosition< Behaviour >::endDrag | ( | ) |
Called after beginDrag() and drag() to indicate that the drag operation has now finished.
References Timer::startTimerHz().
void AnimatedPosition< Behaviour >::nudge | ( | double | deltaFromCurrentPosition | ) |
Called outside of a drag operation to cause a nudge in the specified direction.
This is intended for use by e.g. mouse-wheel events.
References Timer::startTimerHz().
|
noexcept |
Returns the current position.
void AnimatedPosition< Behaviour >::setPosition | ( | double | newPosition | ) |
Explicitly sets the position and stops any further movement.
This will cause a synchronous call to any listeners if the position actually changes.
References Timer::stopTimer().
void AnimatedPosition< Behaviour >::addListener | ( | Listener * | listener | ) |
Adds a listener to be called when the value changes.
void AnimatedPosition< Behaviour >::removeListener | ( | Listener * | listener | ) |
Removes a previously-registered listener.
Behaviour AnimatedPosition< Behaviour >::behaviour |
The behaviour object.
This is public to let you tweak any parameters that it provides.