yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
animator.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_ANIMATION_ANIMATOR_H_
2#define YAZE_APP_GUI_ANIMATION_ANIMATOR_H_
3
4#include <string>
5#include <unordered_map>
6#include <unordered_set>
7
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace gui {
12
13// Transition types for panel animations
14enum class TransitionType {
15 kNone,
16 kFade, // Simple alpha fade
17 kSlideLeft, // Slide in from left
18 kSlideRight, // Slide in from right
19 kSlideUp, // Slide in from bottom
20 kSlideDown, // Slide in from top
21 kScale, // Scale from center
22 kExpand // Expand from point
23};
24
25// Shared editor/workspace motion profile.
26enum class MotionProfile {
27 kSnappy = 0,
28 kStandard = 1,
29 kRelaxed = 2,
30};
31
32class Animator {
33 public:
34 // Static easing functions
35 static float Lerp(float a, float b, float t);
36 static float EaseOutCubic(float t);
37 static float EaseInOutCubic(float t);
38 static float EaseOutElastic(float t);
39 static float EaseOutBack(float t);
40 static ImVec4 LerpColor(ImVec4 a, ImVec4 b, float t);
41
42 // Basic animations
43 float Animate(const std::string& panel_id, const std::string& anim_id,
44 float target, float speed = 5.0f);
45 ImVec4 AnimateColor(const std::string& panel_id, const std::string& anim_id,
46 ImVec4 target, float speed = 5.0f);
47
48 // Panel transition animations
50 float alpha = 1.0f;
51 float offset_x = 0.0f;
52 float offset_y = 0.0f;
53 float scale = 1.0f;
54 bool is_complete = true;
55 };
56
57 // Start a panel transition (call when panel opens)
58 void BeginPanelTransition(const std::string& panel_id, TransitionType type);
59
60 // Update and get current transition state (call each frame)
61 PanelTransition UpdatePanelTransition(const std::string& panel_id,
62 float speed = 8.0f);
63
64 // Check if panel is currently transitioning
65 bool IsPanelTransitioning(const std::string& panel_id) const;
66
67 // Apply transition to ImGui window (call before/after Begin)
68 void ApplyPanelTransitionPre(const std::string& panel_id);
69 void ApplyPanelTransitionPost(const std::string& panel_id);
70
71 void ClearAnimationsForPanel(const std::string& panel_id);
72 void ClearAllAnimations();
73
74 bool IsEnabled() const;
75
77 bool reduced_motion() const { return reduced_motion_; }
79
80 static MotionProfile ClampMotionProfile(int raw_profile);
81
82 private:
84 float value = 0.0f;
85 ImVec4 color = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
86 bool has_value = false;
87 bool has_color = false;
88 };
89
92 float progress = 1.0f; // 0 = start, 1 = complete
93 bool active = false;
94 float initial_offset_x = 0.0f;
95 float initial_offset_y = 0.0f;
96 };
97
98 using AnimationMap = std::unordered_map<std::string, AnimationState>;
99
100 AnimationState& GetState(const std::string& panel_id,
101 const std::string& anim_id);
102 float ComputeStep(float speed) const;
103 float GetProfileSpeedMultiplier() const;
104 float ApplyTransitionEasing(float t) const;
105
106 std::unordered_map<std::string, AnimationMap> panels_;
107 std::unordered_map<std::string, PanelTransitionState> panel_transitions_;
108 std::unordered_set<std::string> pushed_transition_alpha_;
109
110 bool reduced_motion_ = false;
112};
113
115
116} // namespace gui
117} // namespace yaze
118
119#endif // YAZE_APP_GUI_ANIMATION_ANIMATOR_H_
static float EaseOutBack(float t)
Definition animator.cc:33
void ClearAnimationsForPanel(const std::string &panel_id)
Definition animator.cc:83
bool IsPanelTransitioning(const std::string &panel_id) const
Definition animator.cc:210
std::unordered_map< std::string, AnimationState > AnimationMap
Definition animator.h:98
static MotionProfile ClampMotionProfile(int raw_profile)
Definition animator.cc:95
float ComputeStep(float speed) const
Definition animator.cc:263
PanelTransition UpdatePanelTransition(const std::string &panel_id, float speed=8.0f)
Definition animator.cc:147
static float EaseInOutCubic(float t)
Definition animator.cc:21
void SetMotionPreferences(bool reduced_motion, MotionProfile profile)
Definition animator.cc:105
void ApplyPanelTransitionPre(const std::string &panel_id)
Definition animator.cc:215
AnimationState & GetState(const std::string &panel_id, const std::string &anim_id)
Definition animator.cc:258
float ApplyTransitionEasing(float t) const
Definition animator.cc:288
MotionProfile motion_profile() const
Definition animator.h:78
static float Lerp(float a, float b, float t)
Definition animator.cc:12
ImVec4 AnimateColor(const std::string &panel_id, const std::string &anim_id, ImVec4 target, float speed=5.0f)
Definition animator.cc:64
bool reduced_motion() const
Definition animator.h:77
static float EaseOutElastic(float t)
Definition animator.cc:26
static ImVec4 LerpColor(ImVec4 a, ImVec4 b, float t)
Definition animator.cc:40
std::unordered_set< std::string > pushed_transition_alpha_
Definition animator.h:108
float Animate(const std::string &panel_id, const std::string &anim_id, float target, float speed=5.0f)
Definition animator.cc:45
MotionProfile motion_profile_
Definition animator.h:111
float GetProfileSpeedMultiplier() const
Definition animator.cc:276
std::unordered_map< std::string, AnimationMap > panels_
Definition animator.h:106
void ApplyPanelTransitionPost(const std::string &panel_id)
Definition animator.cc:240
bool IsEnabled() const
Definition animator.cc:247
void BeginPanelTransition(const std::string &panel_id, TransitionType type)
Definition animator.cc:111
void ClearAllAnimations()
Definition animator.cc:89
static float EaseOutCubic(float t)
Definition animator.cc:16
std::unordered_map< std::string, PanelTransitionState > panel_transitions_
Definition animator.h:107
Animator & GetAnimator()
Definition animator.cc:301