LMMS
Loading...
Searching...
No Matches
juce::AnimatedPosition< Behaviour > Class Template Reference

#include <juce_AnimatedPosition.h>

Inheritance diagram for juce::AnimatedPosition< Behaviour >:
juce::Timer

Classes

class  Listener

Public Member Functions

 AnimatedPosition ()
void setLimits (Range< double > newRange) noexcept
void beginDrag ()
void drag (double deltaFromStartOfDrag)
void endDrag ()
void nudge (double deltaFromCurrentPosition)
double getPosition () const noexcept
void setPosition (double newPosition)
void addListener (Listener *listener)
void removeListener (Listener *listener)

Public Attributes

Behaviour behaviour

Private Member Functions

void moveTo (double newPos)
void setPositionAndSendChange (double newPosition)
void timerCallback () override
Private Member Functions inherited from juce::Timer
virtual ~Timer ()
void startTimer (int intervalInMilliseconds) noexcept
void startTimerHz (int timerFrequencyHz) noexcept
void stopTimer () noexcept
bool isTimerRunning () const noexcept
int getTimerInterval () const noexcept
 Timer () noexcept
 Timer (const Timer &) noexcept

Static Private Member Functions

static double getSpeed (const Time last, double lastPos, const Time now, double newPos)
Static Private Member Functions inherited from juce::Timer
static void JUCE_CALLTYPE callAfterDelay (int milliseconds, std::function< void()> functionToCall)
static void JUCE_CALLTYPE callPendingTimersSynchronously ()

Private Attributes

double position = 0.0
double grabbedPos = 0.0
double releaseVelocity = 0.0
Range< double > range
Time lastUpdate
Time lastDrag
ListenerList< Listenerlisteners

Detailed Description

template<typename Behaviour>
class juce::AnimatedPosition< Behaviour >

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.

See also
AnimatedPositionBehaviours::ContinuousWithMomentum, AnimatedPositionBehaviours::SnapToPageBoundaries

@tags{GUI}

Constructor & Destructor Documentation

◆ AnimatedPosition()

template<typename Behaviour>
juce::AnimatedPosition< Behaviour >::AnimatedPosition ( )
inline

Member Function Documentation

◆ addListener()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::addListener ( Listener * listener)
inline

Adds a listener to be called when the value changes.

◆ beginDrag()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::beginDrag ( )
inline

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.

◆ drag()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::drag ( double deltaFromStartOfDrag)
inline

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.

◆ endDrag()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::endDrag ( )
inline

Called after beginDrag() and drag() to indicate that the drag operation has now finished.

◆ getPosition()

template<typename Behaviour>
double juce::AnimatedPosition< Behaviour >::getPosition ( ) const
inlinenoexcept

Returns the current position.

◆ getSpeed()

template<typename Behaviour>
double juce::AnimatedPosition< Behaviour >::getSpeed ( const Time last,
double lastPos,
const Time now,
double newPos )
inlinestaticprivate

◆ moveTo()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::moveTo ( double newPos)
inlineprivate

◆ nudge()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::nudge ( double deltaFromCurrentPosition)
inline

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.

◆ removeListener()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::removeListener ( Listener * listener)
inline

Removes a previously-registered listener.

◆ setLimits()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::setLimits ( Range< double > newRange)
inlinenoexcept

Sets a range within which the value will be constrained.

◆ setPosition()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::setPosition ( double newPosition)
inline

Explicitly sets the position and stops any further movement. This will cause a synchronous call to any listeners if the position actually changes.

◆ setPositionAndSendChange()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::setPositionAndSendChange ( double newPosition)
inlineprivate

◆ timerCallback()

template<typename Behaviour>
void juce::AnimatedPosition< Behaviour >::timerCallback ( )
inlineoverrideprivatevirtual

The user-defined callback routine that actually gets called periodically.

It's perfectly ok to call startTimer() or stopTimer() from within this callback to change the subsequent intervals.

Implements juce::Timer.

Member Data Documentation

◆ behaviour

template<typename Behaviour>
Behaviour juce::AnimatedPosition< Behaviour >::behaviour

The behaviour object. This is public to let you tweak any parameters that it provides.

◆ grabbedPos

template<typename Behaviour>
double juce::AnimatedPosition< Behaviour >::grabbedPos = 0.0
private

◆ lastDrag

template<typename Behaviour>
Time juce::AnimatedPosition< Behaviour >::lastDrag
private

◆ lastUpdate

template<typename Behaviour>
Time juce::AnimatedPosition< Behaviour >::lastUpdate
private

◆ listeners

template<typename Behaviour>
ListenerList<Listener> juce::AnimatedPosition< Behaviour >::listeners
private

◆ position

template<typename Behaviour>
double juce::AnimatedPosition< Behaviour >::position = 0.0
private

◆ range

template<typename Behaviour>
Range<double> juce::AnimatedPosition< Behaviour >::range
private

◆ releaseVelocity

template<typename Behaviour>
double juce::AnimatedPosition< Behaviour >::releaseVelocity = 0.0
private

The documentation for this class was generated from the following file: