yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
canvas_touch_handler.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_CANVAS_CANVAS_TOUCH_HANDLER_H
2#define YAZE_APP_GUI_CANVAS_CANVAS_TOUCH_HANDLER_H
3
5#include "imgui/imgui.h"
6
7namespace yaze {
8namespace gui {
9
33 public:
37 struct Config {
38 // Scale limits
39 float min_scale = 0.25f;
40 float max_scale = 4.0f;
41
42 // Whether touch pan/zoom is enabled
43 bool enable_pan = true;
44 bool enable_zoom = true;
45
46 // Smooth animations
47 bool enable_smooth_zoom = true;
48 float zoom_smoothing = 0.2f;
49
50 // Inertia settings
51 bool enable_inertia = true;
52 float inertia_deceleration = 0.92f;
54
55 // Canvas boundaries (0 = no limits)
56 float max_pan_x = 0.0f;
57 float max_pan_y = 0.0f;
58 float min_pan_x = 0.0f;
59 float min_pan_y = 0.0f;
60 };
61
62 CanvasTouchHandler() = default;
63
68 void Initialize(const std::string& canvas_id = "");
69
76 void Update();
77
81 bool IsTouchActive() const;
82
86 bool IsTouchMode() const;
87
91 ImVec2 GetScrollOffset() const { return scroll_offset_; }
92
96 float GetScale() const { return current_scale_; }
97
101 ImVec2 GetZoomCenter() const { return zoom_center_; }
102
106 void SetScrollOffset(ImVec2 offset);
107
111 void SetScale(float scale);
112
116 void ApplyScrollDelta(ImVec2 delta);
117
121 void ApplyZoomDelta(float delta, ImVec2 center);
122
126 void Reset();
127
131 Config& GetConfig() { return config_; }
132 const Config& GetConfig() const { return config_; }
133
137 bool WasTapped() const { return was_tapped_; }
138
142 bool WasDoubleTapped() const { return was_double_tapped_; }
143
147 bool WasLongPressed() const { return was_long_pressed_; }
148
152 ImVec2 GetGesturePosition() const { return gesture_position_; }
153
161 void ProcessForCanvas(ImVec2 canvas_p0, ImVec2 canvas_sz, bool is_hovered);
162
163 private:
164 void ProcessGesture(const GestureState& gesture);
165 void ProcessInertia();
166 void ClampPanToBounds();
167
168 std::string canvas_id_;
170
171 // Current canvas transform state
172 ImVec2 scroll_offset_ = ImVec2(0, 0);
173 float current_scale_ = 1.0f;
174 float target_scale_ = 1.0f;
175 ImVec2 zoom_center_ = ImVec2(0, 0);
176
177 // Inertia state
178 ImVec2 inertia_velocity_ = ImVec2(0, 0);
179 bool inertia_active_ = false;
180
181 // Gesture state for this frame
182 bool was_tapped_ = false;
183 bool was_double_tapped_ = false;
184 bool was_long_pressed_ = false;
185 ImVec2 gesture_position_ = ImVec2(0, 0);
186
187 // Canvas bounds for gesture processing
188 ImVec2 canvas_p0_ = ImVec2(0, 0);
189 ImVec2 canvas_sz_ = ImVec2(0, 0);
190 bool canvas_hovered_ = false;
191
192 // Previous frame state for delta calculations
193 ImVec2 prev_pan_offset_ = ImVec2(0, 0);
194 float prev_scale_ = 1.0f;
195};
196
197} // namespace gui
198} // namespace yaze
199
200#endif // YAZE_APP_GUI_CANVAS_CANVAS_TOUCH_HANDLER_H
Handles touch input integration for Canvas.
bool WasTapped() const
Check if a tap gesture occurred this frame.
void SetScrollOffset(ImVec2 offset)
Set the scroll offset (e.g., from Canvas state)
Config & GetConfig()
Get configuration reference for modification.
void SetScale(float scale)
Set the zoom scale.
float GetScale() const
Get the current zoom scale.
bool IsTouchMode() const
Check if we're in touch mode (vs mouse)
void ApplyScrollDelta(ImVec2 delta)
Apply a scroll delta (add to current offset)
ImVec2 GetZoomCenter() const
Get the zoom center point (for pivot-based zooming)
void ProcessGesture(const GestureState &gesture)
void ApplyZoomDelta(float delta, ImVec2 center)
Apply a zoom delta around a center point.
void Update()
Update touch state each frame.
bool WasLongPressed() const
Check if a long-press gesture occurred this frame.
ImVec2 GetScrollOffset() const
Get the current scroll/pan offset for the canvas.
void Initialize(const std::string &canvas_id="")
Initialize the touch handler.
ImVec2 GetGesturePosition() const
Get the position of the last tap/gesture.
void Reset()
Reset to default state (no pan, 1.0 scale)
bool IsTouchActive() const
Check if touch input is currently active.
bool WasDoubleTapped() const
Check if a double-tap gesture occurred this frame.
void ProcessForCanvas(ImVec2 canvas_p0, ImVec2 canvas_sz, bool is_hovered)
Process touch gestures for the current canvas bounds.
Configuration for canvas touch behavior.
Gesture recognition result.
Definition touch_input.h:52