1.10
Public Member Functions | Protected Attributes | List of all members
Animation Class Reference

Animation class with configurable easing function. More...

#include <animation.h>

Inheritance diagram for Animation:
Inheritance graph
[legend]

Public Member Functions

 Animation (EasingScalar start, EasingScalar end, const AnimationCallback &callback, std::chrono::milliseconds duration, EasingFunc func=easing_linear)
 
EGT_NODISCARD EasingScalar current () const
 Get the current value.
 
void duration (std::chrono::milliseconds dur)
 
void easing_func (EasingFunc func)
 
EGT_NODISCARD EasingScalar ending () const
 Get the ending value.
 
void ending (EasingScalar end)
 
bool next () override
 Periodic call to the animation.
 
void resume () override
 Resume the animation from its current value.
 
void reverse (bool rev)
 
void rounding (bool enable)
 Should the value be rounded?
 
void start () override
 Start the animation from its start value.
 
EGT_NODISCARD EasingScalar starting () const
 Get the starting value.
 
void starting (EasingScalar start)
 
void stop () override
 Stop the animation.
 
- Public Member Functions inherited from AnimationBase
 AnimationBase ()=default
 
 AnimationBase (AnimationBase &&) noexcept=default
 
 AnimationBase (const AnimationBase &)=delete
 
virtual ~AnimationBase () noexcept=default
 
void add_callback (AnimationCallback callback)
 Register a callback for the animation.
 
void clear_callbacks ()
 Clear all callbacks.
 
AnimationBaseoperator= (AnimationBase &&) noexcept=default
 
AnimationBaseoperator= (const AnimationBase &)=delete
 
virtual EGT_NODISCARD bool running () const
 Returns true if the animation is currently running.
 

Protected Attributes

EasingScalar m_current {0}
 Current value.
 
std::chrono::milliseconds m_duration {}
 Duration of the animation.
 
EasingFunc m_easing {easing_linear}
 Easing function.
 
EasingScalar m_elapsed {0}
 Keep track of the progress of the animation.
 
EasingScalar m_end {0}
 Ending value.
 
std::chrono::time_point< std::chrono::steady_clock > m_intermediate_time
 Absolute time used to track the animation time elapsed.
 
bool m_reverse {false}
 Is the animation running in reverse.
 
bool m_round {false}
 Should the dispatched value be rounded?
 
EasingScalar m_start {0}
 Starting value.
 
- Protected Attributes inherited from AnimationBase
std::vector< AnimationCallbackm_callbacks
 Registered callbacks for the animation.
 
bool m_running {false}
 The running state of the animation.
 

Detailed Description

Animation class with configurable easing function.

An Animation is a container that basically runs from a start value to an end value over a duration of time. For example, the first value of the animation will be the start value at duration 0 and the last value of the animation will be the end value at the duration total.

What happens between the start of the duration and the end of the duration, relative to time, is dictated by what's called an easing function. In other words, the easing function controls the skew of the animation value relative to time.

Usually, this class will not be used directly and instead one of the helper classes derived from this are easier to use, like

See also
PropertyAnimator.

Constructor & Destructor Documentation

◆ Animation()

Animation ( EasingScalar  start,
EasingScalar  end,
const AnimationCallback callback,
std::chrono::milliseconds  duration,
EasingFunc  func = easing_linear 
)
Parameters
[in]startThe starting value of the animation.
[in]endThe ending value of the animation.
[in]callbackCalled whenever the animation value changes. May be nullptr.
[in]durationThe duration of the animation.
[in]funcThe easing function to use.

Member Function Documentation

◆ current()

EGT_NODISCARD EasingScalar current ( ) const
inline

Get the current value.

◆ duration()

void duration ( std::chrono::milliseconds  dur)
inline
Note
Calling this while running is undefined behavior.

◆ easing_func()

void easing_func ( EasingFunc  func)
Note
Calling this while running is undefined behavior.

◆ ending() [1/2]

EGT_NODISCARD EasingScalar ending ( ) const
inline

Get the ending value.

◆ ending() [2/2]

void ending ( EasingScalar  end)
inline
Note
Calling this while running is undefined behavior.

◆ next()

bool next ( )
overridevirtual

Periodic call to the animation.

This must be called until it returns false. When it returns false, the animation is done.

Implements AnimationBase.

◆ resume()

void resume ( )
overridevirtual

Resume the animation from its current value.

Implements AnimationBase.

Reimplemented in AutoAnimation.

◆ reverse()

void reverse ( bool  rev)
inline
Note
Calling this while running is undefined behavior.

◆ rounding()

void rounding ( bool  enable)
inline

Should the value be rounded?

When set to true, the resulting value will be rounded to the nearest integer.

Parameters
[in]enableWhen true, rounding is enabled. It is false by default.

◆ start()

void start ( )
overridevirtual

Start the animation from its start value.

Implements AnimationBase.

Reimplemented in AutoAnimation.

◆ starting() [1/2]

EGT_NODISCARD EasingScalar starting ( ) const
inline

Get the starting value.

◆ starting() [2/2]

void starting ( EasingScalar  start)
inline
Note
Calling this while running is undefined behavior.

◆ stop()

void stop ( )
overridevirtual

Stop the animation.

Implements AnimationBase.

Reimplemented in AutoAnimation.

Member Data Documentation

◆ m_current

EasingScalar m_current {0}
protected

Current value.

◆ m_duration

std::chrono::milliseconds m_duration {}
protected

Duration of the animation.

◆ m_easing

EasingFunc m_easing {easing_linear}
protected

Easing function.

◆ m_elapsed

EasingScalar m_elapsed {0}
protected

Keep track of the progress of the animation.

◆ m_end

EasingScalar m_end {0}
protected

Ending value.

◆ m_intermediate_time

std::chrono::time_point<std::chrono::steady_clock> m_intermediate_time
protected

Absolute time used to track the animation time elapsed.

◆ m_reverse

bool m_reverse {false}
protected

Is the animation running in reverse.

◆ m_round

bool m_round {false}
protected

Should the dispatched value be rounded?

◆ m_start

EasingScalar m_start {0}
protected

Starting value.