JUCE v8.0.9
JUCE API
 
Loading...
Searching...
No Matches
juce::Animator Class Reference

Wrapper class for managing the lifetime of all the different animator kinds created through the builder classes. More...

#include <juce_Animator.h>

Collaboration diagram for juce::Animator:

Classes

struct  Compare
 Comparison function used by the implementation to store Animators in ordered collections. More...
 
class  Weak
 

Public Types

enum class  Status {
  idle ,
  inProgress ,
  finished
}
 The state of an Animator that determines how AnimatorUpdaters and other Animators will interact with it. More...
 

Public Member Functions

 Animator (std::shared_ptr< Impl >)
 
void complete () const
 Marks the Animator ready to be completed.
 
double getDurationMs () const
 Returns the total animation duration in milliseconds.
 
bool isComplete () const
 Returns true if the Animator has reached the point of completion either because complete() has been called on it, or in case of the ValueAnimator, if it reached a progress of >= 1.0.
 
Weak makeWeak () const
 
void start () const
 Marks the Animator ready for starting.
 
Status update (double timestampMs) const
 Called periodically for active Animators by the AnimatorUpdater classes.
 

Private Attributes

std::shared_ptr< Impl > ptr
 

Detailed Description

Wrapper class for managing the lifetime of all the different animator kinds created through the builder classes.

It uses reference counting. If you copy an Animator the resulting object will refer to the same underlying instance, and the underlying instance is guaranteed to remain valid for as long as you have an Animator object referencing it.

An Animator object can be registered with the AnimatorUpdater, which only stores a weak reference to the underlying instance. If an AnimatorUpdater references the underlying instance and it becomes deleted due to all Animator objects being deleted, the updater will automatically remove it from its queue, so manually removing it is not required.

See also
ValueAnimatorBuilder, AnimatorSetBuilder, AnimatorUpdater, VBlankAnimatorUpdater

@tags{Animations}

Member Enumeration Documentation

◆ Status

enum class juce::Animator::Status
strong

The state of an Animator that determines how AnimatorUpdaters and other Animators will interact with it.

Enumerator
idle 

The Animator is idle and its state is not progressing even if it is attached to an AnimatorUpdater.

inProgress 

The Animator is active and its state is progressing whenever its update function is called.

finished 

The Animator finished its run and its onCompletion callback may be called.

It requires no further calls to its update function.

Constructor & Destructor Documentation

◆ Animator()

juce::Animator::Animator ( std::shared_ptr< Impl >  )
explicit

Constructor. Used by the builder classes.

See also
ValueAnimatorBuilder, AnimatorSetBuilder

Member Function Documentation

◆ complete()

void juce::Animator::complete ( ) const

Marks the Animator ready to be completed.

ValueAnimators will be completed automatically when they reach a progress >= 1.0 unless they are infinitely running. AnimatorSets will also complete on their own when all of their constituent Animators complete.

Using this function you can fast track the completion of an Animator. After calling this function isComplete will return true, and it's guaranteed that you will receive an update callback with a progress value of 1.0. After this the onComplete callback will be executed.

◆ getDurationMs()

double juce::Animator::getDurationMs ( ) const

Returns the total animation duration in milliseconds.

◆ isComplete()

bool juce::Animator::isComplete ( ) const

Returns true if the Animator has reached the point of completion either because complete() has been called on it, or in case of the ValueAnimator, if it reached a progress of >= 1.0.

You typically don't need to call this function, because in any case a completed Animator will receive an update callback with a progress value of 1.0 and following that the on complete callback will be called.

◆ makeWeak()

Weak juce::Animator::makeWeak ( ) const
inline

Returns a weak reference to the underlying implementation. You can use Weak::lock() to obtain a strong reference as long as the underlying object has not been deleted.

◆ start()

void juce::Animator::start ( ) const

Marks the Animator ready for starting.

You must call this function to allow the Animator to move out of the idle state.

After calling this function the Animator's on start callback will be executed at the next update immediately followed by the first call to it's update function.

You can call this function before or after adding the Animator to an AnimatorUpdater. Until start() is called the Animator will just sit idly in the updater's queue.

◆ update()

Status juce::Animator::update ( double  timestampMs) const

Called periodically for active Animators by the AnimatorUpdater classes.

The passed in timestamp must be monotonically increasing. This allows the underlying Animator to follow its progression towards completion.

While you can call this function in special circumstances, you will generally want an AnimatorUpdater to do it. Using the VBlankAnimatorUpdater ensures that update is called in sync with the monitor's vertical refresh resulting in smooth animations.

See also
AnimatorUpdater, VBlankAnimatorUpdater

Member Data Documentation

◆ ptr

std::shared_ptr<Impl> juce::Animator::ptr
private

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