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
4#include <string>
5
7#include "imgui/imgui.h"
8
9namespace yaze {
10namespace gui {
11
35 public:
39 struct Config {
40 // Scale limits
41 float min_scale = 0.25f;
42 float max_scale = 4.0f;
43
44 // Whether touch pan/zoom is enabled
45 bool enable_pan = true;
46 bool enable_zoom = true;
47
48 // Smooth animations
49 bool enable_smooth_zoom = true;
50 float zoom_smoothing = 0.2f;
51
52 // Inertia settings
53 bool enable_inertia = true;
54 float inertia_deceleration = 0.92f;
56
57 // Canvas boundaries (0 = no limits)
58 float max_pan_x = 0.0f;
59 float max_pan_y = 0.0f;
60 float min_pan_x = 0.0f;
61 float min_pan_y = 0.0f;
62 };
63
64 CanvasTouchHandler() = default;
65
70 void Initialize(const std::string& canvas_id = "");
71
78 void Update();
79
83 bool IsTouchActive() const;
84
88 bool IsTouchMode() const;
89
93 ImVec2 GetScrollOffset() const { return scroll_offset_; }
94
98 float GetScale() const { return current_scale_; }
99
103 ImVec2 GetZoomCenter() const { return zoom_center_; }
104
108 void SetScrollOffset(ImVec2 offset);
109
113 void SetScale(float scale);
114
118 void ApplyScrollDelta(ImVec2 delta);
119
123 void ApplyZoomDelta(float delta, ImVec2 center);
124
128 void Reset();
129
133 Config& GetConfig() { return config_; }
134 const Config& GetConfig() const { return config_; }
135
139 bool WasTapped() const { return was_tapped_; }
140
144 bool WasDoubleTapped() const { return was_double_tapped_; }
145
149 bool WasLongPressed() const { return was_long_pressed_; }
150
154 ImVec2 GetGesturePosition() const { return gesture_position_; }
155
163 void ProcessForCanvas(ImVec2 canvas_p0, ImVec2 canvas_sz, bool is_hovered);
164
165 private:
166 void ProcessGesture(const GestureState& gesture);
167 void ProcessInertia();
168 void ClampPanToBounds();
169
170 std::string canvas_id_;
172
173 // Current canvas transform state
174 ImVec2 scroll_offset_ = ImVec2(0, 0);
175 float current_scale_ = 1.0f;
176 float target_scale_ = 1.0f;
177 ImVec2 zoom_center_ = ImVec2(0, 0);
178
179 // Inertia state
180 ImVec2 inertia_velocity_ = ImVec2(0, 0);
181 bool inertia_active_ = false;
182
183 // Gesture state for this frame
184 bool was_tapped_ = false;
185 bool was_double_tapped_ = false;
186 bool was_long_pressed_ = false;
187 ImVec2 gesture_position_ = ImVec2(0, 0);
188
189 // Canvas bounds for gesture processing
190 ImVec2 canvas_p0_ = ImVec2(0, 0);
191 ImVec2 canvas_sz_ = ImVec2(0, 0);
192 bool canvas_hovered_ = false;
193
194 // Previous frame state for delta calculations
195 ImVec2 prev_pan_offset_ = ImVec2(0, 0);
196 float prev_scale_ = 1.0f;
197};
198
199} // namespace gui
200} // namespace yaze
201
202#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