persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
UIAnimator.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
16
17#include <etl/vector.h>
18#include <functional>
19#include <memory>
20
25{
26 public:
27 static constexpr std::size_t MAX_ACTIVE_ANIMATIONS = 8;
28
29 template <typename T> UIPropertyAnimationBuilder<T> animate(T& target)
30 {
31 return UIPropertyAnimationBuilder<T>(target, this);
32 }
33
35 {
36 return UIPropertyAnimationBuilder<T>(target.get(), this);
37 }
38
40 {
41 return UISequenceBuilder(this);
42 }
43
44 UIAnimationHandle play(std::shared_ptr<UIAnimation> anim)
45 {
46 if (anim == nullptr)
47 {
48 return UIAnimationHandle();
49 }
50
51 if (updating)
52 {
53 if (!pendingPlay.full())
54 {
55 pendingPlay.push_back(anim);
56 }
57 return UIAnimationHandle(std::move(anim));
58 }
59
60 if (active.full())
61 {
62 return UIAnimationHandle();
63 }
64
65 active.push_back(anim);
66 return UIAnimationHandle(std::move(anim));
67 }
68
69 std::shared_ptr<UIAnimation> call(std::function<void()> fn)
70 {
71 return std::make_shared<UICallbackAnimation>(std::move(fn));
72 }
73
74 std::shared_ptr<UIAnimation> delay(int ms)
75 {
76 return std::make_shared<UIDelayAnimation>(ms);
77 }
78
82 void update(ae::q20_12_t dt)
83 {
84 updating = true;
85
86 for (auto it = active.begin(); it != active.end();)
87 {
88 if ((*it)->tick(dt))
89 {
90 it = active.erase(it);
91 }
92 else
93 {
94 ++it;
95 }
96 }
97
98 updating = false;
99
101 {
102 pendingCancelAll = false;
103 for (auto& a : active)
104 {
105 a->cancel();
106 }
107 active.clear();
108 pendingPlay.clear();
109 return;
110 }
111
112 for (auto& anim : pendingPlay)
113 {
114 if (!active.full() && anim != nullptr && !anim->isCancelled() && !anim->isDone())
115 {
116 active.push_back(anim);
117 }
118 }
119 pendingPlay.clear();
120 }
121
123 {
124 for (auto& a : active)
125 {
126 a->cancel();
127 }
128
129 if (updating)
130 {
131 pendingCancelAll = true;
132 return;
133 }
134
135 active.clear();
136 pendingPlay.clear();
137 }
138
139 private:
140 etl::vector<std::shared_ptr<UIAnimation>, MAX_ACTIVE_ANIMATIONS> active;
141 etl::vector<std::shared_ptr<UIAnimation>, MAX_ACTIVE_ANIMATIONS> pendingPlay;
142 bool updating = false;
143 bool pendingCancelAll = false;
144};
145
147{
148 if (owner == nullptr)
149 {
150 return UIAnimationHandle();
151 }
152 return owner->play(build());
153}
154
156{
157 if (owner == nullptr)
158 {
159 return UIAnimationHandle();
160 }
161 return owner->play(seq);
162}
Non-copyable wrapper around a value that UI tweens can target.
Weak handle used by callers to cancel/pause/query a running UI animation.
Base class for one UI animation step (property, delay, callback, sequence).
One-shot animation that invokes a callback on its first tick.
Animation that waits for a fixed duration before completing.
Tweens a single target value over time with easing and optional repeat.
Ordered groups of UI animations (sequential steps, parallel joins).
Owns a value of type T that property animations may write to.
Non-owning control handle for a UIAnimation managed by UIAnimator.
Owns and ticks active UI animations. Safe against cancel-during-tick.
std::shared_ptr< UIAnimation > delay(int ms)
UISequenceBuilder sequence()
void cancelAll()
void update(ae::q20_12_t dt)
Advances all active animations by dt seconds (Q20.12).
bool pendingCancelAll
etl::vector< std::shared_ptr< UIAnimation >, MAX_ACTIVE_ANIMATIONS > active
std::shared_ptr< UIAnimation > call(std::function< void()> fn)
UIAnimationHandle play(std::shared_ptr< UIAnimation > anim)
UIPropertyAnimationBuilder< T > animate(UIAnimated< T > &target)
UIPropertyAnimationBuilder< T > animate(T &target)
static constexpr std::size_t MAX_ACTIVE_ANIMATIONS
etl::vector< std::shared_ptr< UIAnimation >, MAX_ACTIVE_ANIMATIONS > pendingPlay
Fluent builder for UIPropertyAnimation. Must be started via a UIAnimator owner.
UIAnimationHandle start()
std::shared_ptr< UIAnimation > build() const
Fluent builder for UISequenceAnimation. Requires a UIAnimator to start.
std::shared_ptr< UISequenceAnimation > seq
UIAnimationHandle start()