1.10 |
Animation class with configurable easing function. More...
#include <animation.h>
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. | |
AnimationBase & | operator= (AnimationBase &&) noexcept=default |
AnimationBase & | operator= (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< AnimationCallback > | m_callbacks |
Registered callbacks for the animation. | |
bool | m_running {false} |
The running state of the animation. | |
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
Animation | ( | EasingScalar | start, |
EasingScalar | end, | ||
const AnimationCallback & | callback, | ||
std::chrono::milliseconds | duration, | ||
EasingFunc | func = easing_linear |
||
) |
[in] | start | The starting value of the animation. |
[in] | end | The ending value of the animation. |
[in] | callback | Called whenever the animation value changes. May be nullptr. |
[in] | duration | The duration of the animation. |
[in] | func | The easing function to use. |
|
inline |
Get the current value.
|
inline |
void easing_func | ( | EasingFunc | func | ) |
|
inline |
Get the ending value.
|
inline |
|
overridevirtual |
Periodic call to the animation.
This must be called until it returns false. When it returns false, the animation is done.
Implements AnimationBase.
|
overridevirtual |
Resume the animation from its current value.
Implements AnimationBase.
Reimplemented in AutoAnimation.
|
inline |
|
inline |
Should the value be rounded?
When set to true, the resulting value will be rounded to the nearest integer.
[in] | enable | When true, rounding is enabled. It is false by default. |
|
overridevirtual |
|
inline |
Get the starting value.
|
inline |
|
overridevirtual |
|
protected |
Current value.
|
protected |
Duration of the animation.
|
protected |
Easing function.
|
protected |
Keep track of the progress of the animation.
|
protected |
Ending value.
|
protected |
Absolute time used to track the animation time elapsed.
|
protected |
Is the animation running in reverse.
|
protected |
Should the dispatched value be rounded?
|
protected |
Starting value.