Louvre  v2.12.0-1
C++ library for Wayland compositors
Public Types | Public Member Functions | Static Public Member Functions | List of all members
LAnimation Class Reference

Time-based animations. More...

+ Inheritance diagram for LAnimation:

Public Types

using Callback = std::function< void(LAnimation *)>
 

Public Member Functions

 LAnimation (UInt32 durationMs=0, const Callback &onUpdate=nullptr, const Callback &onFinish=nullptr) noexcept
 Creates a reusable animation. More...
 
 ~LAnimation ()
 Destructor for the LAnimation class. More...
 
void setOnUpdateCallback (const Callback &onUpdate) noexcept
 Sets the onUpdate() callback handler function. More...
 
void setOnFinishCallback (const Callback &onFinish) noexcept
 Sets the onFinish() callback handler function. More...
 
void setDuration (UInt32 durationMs) noexcept
 Sets the duration of the animation in milliseconds. More...
 
UInt32 duration () const noexcept
 Returns the duration of the animation in milliseconds. More...
 
Float64 value () const noexcept
 Returns a number linearly interpolated from 0.0 to 1.0. More...
 
void start () noexcept
 Starts the animation. More...
 
void stop ()
 Halts the animation before its duration is reached. More...
 
bool running () const noexcept
 Checks if the animation is currently running. More...
 
- Public Member Functions inherited from LObject
 LObject (const LObject &) noexcept
 Copy constructor. More...
 
LObjectoperator= (const LObject &) noexcept
 Assignment operator (each object has its own individual LWeak reference count). More...
 
void setUserData (UIntPtr data) const noexcept
 Store an unsigned integer value/pointer. More...
 
UIntPtr userData () const noexcept
 Retrieves the stored unsigned integer value/pointer. More...
 

Static Public Member Functions

static void oneShot (UInt32 durationMs, const Callback &onUpdate=nullptr, const Callback &onFinish=nullptr) noexcept
 Creates and launches a one-time animation with automatic cleanup. More...
 

Additional Inherited Members

- Protected Member Functions inherited from LObject
 LObject () noexcept=default
 Constructor of the LObject class. More...
 
virtual ~LObject () noexcept
 Destructor of the LObject class. More...
 
void notifyDestruction () noexcept
 Notifies the object destruction. More...
 

Detailed Description

Time-based animations.

This class can be used for animating object parameters such as positions, color, opacity, etc. It has a fixed duration in milliseconds, and is synchronized with each initialized output's render loop.
After started, the onUpdate() callback is triggered before each LOutput::paintGL() call, allowing you to access the value() property, which is a 64-bit floating-point number linearly interpolated from 0.0 to 1.0, indicating the completion percentage of the animation.

Note
It is essential to manually invoke LOutput::repaint() on the outputs you are animating; otherwise, the onUpdate() callback may not be invoked.

After the animation finishes, the onFinish() callback is triggered, and the value() property has a value of 1.0.

Member Typedef Documentation

◆ Callback

using Callback = std::function<void(LAnimation*)>

Callback function type used to handle the onUpdate() and onFinish() events.

Constructor & Destructor Documentation

◆ LAnimation()

LAnimation ( UInt32  durationMs = 0,
const Callback onUpdate = nullptr,
const Callback onFinish = nullptr 
)
noexcept

Creates a reusable animation.

Creates an animation without starting it immediately.

Parameters
durationMsThe duration of the animation in milliseconds.
onUpdateA callback function triggered each time the value() property changes. nullptr can be passed if not used.
onFinishA callback function triggered once the value() property reaches 1.0. nullptr can be passed if not used.

◆ ~LAnimation()

~LAnimation ( )

Destructor for the LAnimation class.

Destroys an animation object. If the animation is currently running at the time of destruction, the onFinish() callback is invoked immediately before the object is destroyed.

Member Function Documentation

◆ oneShot()

void oneShot ( UInt32  durationMs,
const Callback onUpdate = nullptr,
const Callback onFinish = nullptr 
)
staticnoexcept

Creates and launches a one-time animation with automatic cleanup.

The oneShot() method creates and starts an animation immediately, and it is automatically destroyed once finished.

Parameters
durationMsThe duration of the animation in milliseconds.
onUpdateA callback function triggered each time the value() property changes. nullptr can be passed if not used.
onFinishA callback function triggered once the value() property reaches 1.0. nullptr can be passed if not used.

◆ setOnUpdateCallback()

void setOnUpdateCallback ( const Callback onUpdate)
noexcept

Sets the onUpdate() callback handler function.

This method allows you to set the callback function that will be called when an update event occurs.

Parameters
onUpdateA reference to the callback function. Pass nullptr to disable the callback.

◆ setOnFinishCallback()

void setOnFinishCallback ( const Callback onFinish)
noexcept

Sets the onFinish() callback handler function.

This method allows you to set the callback function that will be called when the animaion finishes or stop() is called.

Parameters
onFinishA reference to the callback function. Pass nullptr to disable the callback.

◆ setDuration()

void setDuration ( UInt32  durationMs)
inlinenoexcept

Sets the duration of the animation in milliseconds.

Use this method to specify the duration of the animation in milliseconds.

Note
It is not permissible to invoke this method while the animation is in progress, and attempting to do so will yield no results.
Parameters
durationMsThe duration of the animation in milliseconds.

◆ duration()

UInt32 duration ( ) const
inlinenoexcept

Returns the duration of the animation in milliseconds.

Use this method to retrieve the duration of the animation in milliseconds.

Returns
The duration of the animation in milliseconds.

◆ value()

Float64 value ( ) const
inlinenoexcept

Returns a number linearly interpolated from 0.0 to 1.0.

This method returns a value indicating the percentage of completion of the animation. The value is linearly interpolated between 0.0 (start of the animation) and 1.0 (end of the animation).

Returns
The interpolated completion value ranging from 0.0 to 1.0.

◆ start()

void start ( )
noexcept

Starts the animation.

If the animation is already running, calling this method a no-op.

◆ stop()

void stop ( )

Halts the animation before its duration is reached.

The stop() method can be used to stop the animation before its duration is reached. If called before the animation finishes, the onFinish() callback is triggered immediately, and the value() property is set to 1.0.

◆ running()

bool running ( ) const
inlinenoexcept

Checks if the animation is currently running.

Returns
true if running, false otherwise.