52template <
typename Behaviour>
79 grabbedPos = position;
155 double position = 0.0, grabbedPos = 0.0, releaseVelocity = 0.0;
157 Time lastUpdate, lastDrag;
160 static double getSpeed (
const Time last,
double lastPos,
165 return std::abs (v) > 0.2 ? v : 0.0;
168 void moveTo (
double newPos)
171 releaseVelocity = getSpeed (lastDrag, position, now,
newPos);
175 setPositionAndSendChange (
newPos);
189 void timerCallback()
override
192 auto elapsed =
jlimit (0.001, 0.020, (now - lastUpdate).inSeconds());
201 setPositionAndSendChange (
newPos);
Implement this class if you need to receive callbacks when the value of an AnimatedPosition changes.
virtual void positionChanged(AnimatedPosition &, double newPosition)=0
Called synchronously when an AnimatedPosition changes.
Models a 1-dimensional position that can be dragged around by the user, and which will then continue ...
Behaviour behaviour
The behaviour object.
void addListener(Listener *listener)
Adds a listener to be called when the value changes.
void endDrag()
Called after beginDrag() and drag() to indicate that the drag operation has now finished.
void setPosition(double newPosition)
Explicitly sets the position and stops any further movement.
double getPosition() const noexcept
Returns the current position.
void removeListener(Listener *listener)
Removes a previously-registered listener.
void nudge(double deltaFromCurrentPosition)
Called outside of a drag operation to cause a nudge in the specified direction.
void beginDrag()
Called to indicate that the object is now being controlled by a mouse-drag or similar operation.
void setLimits(Range< double > newRange) noexcept
Sets a range within which the value will be constrained.
void drag(double deltaFromStartOfDrag)
Called during a mouse-drag operation, to indicate that the mouse has moved.
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
void call(Callback &&callback)
Calls an invokable object for each listener in the list.
A general-purpose range object, that simply represents any linear range with a start and end point.
ValueType clipValue(const ValueType value) const noexcept
Returns the nearest value to the one supplied, which lies within the range.
Holds an absolute date and time.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
Makes repeated callbacks to a virtual method at a specified time interval.
void stopTimer() noexcept
Stops the timer.
void startTimerHz(int timerFrequencyHz) noexcept
Starts the timer with an interval specified in Hertz.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...