guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
animation.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <functional>
26
27#include "guillaume/ecs/component.hpp"
28#include "guillaume/motion/easing.hpp"
29
31{
32
61 {
62 public:
64 std::function<void(float)>;
66 std::function<void(void)>;
67
68 private:
69 float _duration { 0.0f };
70 float _elapsed { 0.0f };
71 bool _playing { false };
72 bool _looping { false };
73 motion::Easing _easing {
74 motion::Easing::Standard
75 };
76
77 SampleHandler _onSample {};
78 CompleteHandler _onComplete {};
79
80 public:
85 Animation(void);
86
90 ~Animation(void) = default;
91
96 float getDuration(void) const;
97
107 Animation &setDuration(float duration);
108
113 float getElapsed(void) const;
114
124 Animation &setElapsed(float elapsed);
125
131 float getProgress(void) const;
132
137 bool isPlaying(void) const;
138
148 Animation &play(void);
149
158 Animation &stop(void);
159
164 bool isLooping(void) const;
165
175 Animation &setLooping(bool looping);
176
182 motion::Easing getEasing(void) const;
183
193 Animation &setEasing(motion::Easing easing);
194
206
212
224
230
244 void advance(float deltaTime);
245 };
246
247} // namespace guillaume::components
float getProgress(void) const
Get how far the current run is, before easing.
Definition animation.cpp:66
void advance(float deltaTime)
Move the animation forward in time and call the handlers.
float getElapsed(void) const
Get the time spent in the current run.
Definition animation.cpp:51
bool isLooping(void) const
Check whether the animation starts again when it completes.
Definition animation.cpp:95
CompleteHandler getOnCompleteHandler(void) const
Get the callback run when the animation reaches its duration.
motion::Easing getEasing(void) const
Get the curve that turns the linear progress into the value passed to the sample handler.
Animation & setEasing(motion::Easing easing)
Set the curve that turns the linear progress into the value passed to the sample handler.
std::function< void(void)> CompleteHandler
Called on completion.
Definition animation.hpp:65
Animation & setDuration(float duration)
Set how long one run of the animation lasts.
Definition animation.cpp:41
Animation & setElapsed(float elapsed)
Move the animation to a point in time, without calling any handler.
Definition animation.cpp:56
SampleHandler getOnSampleHandler(void) const
Get the callback that applies the animation.
Animation(void)
Construct a stopped animation lasting the Material 3 Medium2 motion duration of the theme.
Definition animation.cpp:31
Animation & setOnSampleHandler(const SampleHandler &handler)
Store the callback that applies the animation.
Animation & play(void)
Start the animation from the beginning, even when it is already running.
Definition animation.cpp:79
float getDuration(void) const
Get how long one run of the animation lasts.
Definition animation.cpp:36
Animation & setLooping(bool looping)
Set whether the animation starts again when it completes.
Animation & setOnCompleteHandler(const CompleteHandler &handler)
Store the callback run when the animation reaches its duration.
~Animation(void)=default
Default destructor.
Animation & stop(void)
Stop the animation and bring the elapsed time back to 0.
Definition animation.cpp:87
bool isPlaying(void) const
Check whether the animation is running.
Definition animation.cpp:74
std::function< void(float)> SampleHandler
Receives the eased progress.
Definition animation.hpp:63
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
State. Every class here is plain data attached to an entity.