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);
73 void ClearAllAnimations();
74
75 bool IsEnabled() const;
76
78 bool reduced_motion() const { return reduced_motion_; }
80
81 static MotionProfile ClampMotionProfile(int raw_profile);
82
83 private:
85 float value = 0.0f;
86 ImVec4 color = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
87 bool has_value = false;
88 bool has_color = false;
89 };
90
93 float progress = 1.0f; // 0 = start, 1 = complete
94 bool active = false;
95 float initial_offset_x = 0.0f;
96 float initial_offset_y = 0.0f;
97 };
98
99 using AnimationMap = std::unordered_map<std::string, AnimationState>;
100
101 AnimationState& GetState(const std::string& panel_id,
102 const std::string& anim_id);
103 float ComputeStep(float speed) const;
104 float GetProfileSpeedMultiplier() const;
105 float ApplyTransitionEasing(float t) const;
106
107 std::unordered_map<std::string, AnimationMap> panels_;
108 std::unordered_map<std::string, PanelTransitionState> panel_transitions_;
109 std::unordered_set<std::string> pushed_transition_alpha_;
110
111 bool reduced_motion_ = false;
113};
114
116
117} // namespace gui
118} // namespace yaze
119
120#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:225
std::unordered_map< std::string, AnimationState > AnimationMap
Definition animator.h:99
static MotionProfile ClampMotionProfile(int raw_profile)
Definition animator.cc:110
float ComputeStep(float speed) const
Definition animator.cc:280
PanelTransition UpdatePanelTransition(const std::string &panel_id, float speed=8.0f)
Definition animator.cc:162
static float EaseInOutCubic(float t)
Definition animator.cc:21
void SetMotionPreferences(bool reduced_motion, MotionProfile profile)
Definition animator.cc:120
void ApplyPanelTransitionPre(const std::string &panel_id)
Definition animator.cc:230
AnimationState & GetState(const std::string &panel_id, const std::string &anim_id)
Definition animator.cc:275
float ApplyTransitionEasing(float t) const
Definition animator.cc:305
MotionProfile motion_profile() const
Definition animator.h:79
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:78
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:109
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:112
float GetProfileSpeedMultiplier() const
Definition animator.cc:293
std::unordered_map< std::string, AnimationMap > panels_
Definition animator.h:107
void ClearWorkspaceTransitionState()
Definition animator.cc:89
void ApplyPanelTransitionPost(const std::string &panel_id)
Definition animator.cc:257
bool IsEnabled() const
Definition animator.cc:264
void BeginPanelTransition(const std::string &panel_id, TransitionType type)
Definition animator.cc:126
void ClearAllAnimations()
Definition animator.cc:104
static float EaseOutCubic(float t)
Definition animator.cc:16
std::unordered_map< std::string, PanelTransitionState > panel_transitions_
Definition animator.h:108
Animator & GetAnimator()
Definition animator.cc:318