yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gui::CanvasTouchHandler Class Reference

Handles touch input integration for Canvas. More...

#include <canvas_touch_handler.h>

Collaboration diagram for yaze::gui::CanvasTouchHandler:

Classes

struct  Config
 Configuration for canvas touch behavior. More...
 

Public Member Functions

 CanvasTouchHandler ()=default
 
void Initialize (const std::string &canvas_id="")
 Initialize the touch handler.
 
void Update ()
 Update touch state each frame.
 
bool IsTouchActive () const
 Check if touch input is currently active.
 
bool IsTouchMode () const
 Check if we're in touch mode (vs mouse)
 
ImVec2 GetScrollOffset () const
 Get the current scroll/pan offset for the canvas.
 
float GetScale () const
 Get the current zoom scale.
 
ImVec2 GetZoomCenter () const
 Get the zoom center point (for pivot-based zooming)
 
void SetScrollOffset (ImVec2 offset)
 Set the scroll offset (e.g., from Canvas state)
 
void SetScale (float scale)
 Set the zoom scale.
 
void ApplyScrollDelta (ImVec2 delta)
 Apply a scroll delta (add to current offset)
 
void ApplyZoomDelta (float delta, ImVec2 center)
 Apply a zoom delta around a center point.
 
void Reset ()
 Reset to default state (no pan, 1.0 scale)
 
ConfigGetConfig ()
 Get configuration reference for modification.
 
const ConfigGetConfig () const
 
bool WasTapped () const
 Check if a tap gesture occurred this frame.
 
bool WasDoubleTapped () const
 Check if a double-tap gesture occurred this frame.
 
bool WasLongPressed () const
 Check if a long-press gesture occurred this frame.
 
ImVec2 GetGesturePosition () const
 Get the position of the last tap/gesture.
 
void ProcessForCanvas (ImVec2 canvas_p0, ImVec2 canvas_sz, bool is_hovered)
 Process touch gestures for the current canvas bounds.
 

Private Member Functions

void ProcessGesture (const GestureState &gesture)
 
void ProcessInertia ()
 
void ClampPanToBounds ()
 

Private Attributes

std::string canvas_id_
 
Config config_
 
ImVec2 scroll_offset_ = ImVec2(0, 0)
 
float current_scale_ = 1.0f
 
float target_scale_ = 1.0f
 
ImVec2 zoom_center_ = ImVec2(0, 0)
 
ImVec2 inertia_velocity_ = ImVec2(0, 0)
 
bool inertia_active_ = false
 
bool was_tapped_ = false
 
bool was_double_tapped_ = false
 
bool was_long_pressed_ = false
 
ImVec2 gesture_position_ = ImVec2(0, 0)
 
ImVec2 canvas_p0_ = ImVec2(0, 0)
 
ImVec2 canvas_sz_ = ImVec2(0, 0)
 
bool canvas_hovered_ = false
 
ImVec2 prev_pan_offset_ = ImVec2(0, 0)
 
float prev_scale_ = 1.0f
 

Detailed Description

Handles touch input integration for Canvas.

Bridges the TouchInput system with Canvas pan/zoom/interaction. Translates touch gestures into canvas operations and maintains smooth integration with mouse-based controls.

Usage:

// In canvas initialization or first frame
canvas_touch_handler_.Initialize();
// Each frame before canvas rendering
canvas_touch_handler_.Update();
// Apply touch transforms to canvas
if (canvas_touch_handler_.IsTouchActive()) {
scrolling = canvas_touch_handler_.GetScrollOffset();
scale = canvas_touch_handler_.GetScale();
}

Definition at line 32 of file canvas_touch_handler.h.

Constructor & Destructor Documentation

◆ CanvasTouchHandler()

yaze::gui::CanvasTouchHandler::CanvasTouchHandler ( )
default

Member Function Documentation

◆ Initialize()

void yaze::gui::CanvasTouchHandler::Initialize ( const std::string & canvas_id = "")

Initialize the touch handler.

Parameters
canvas_idCanvas identifier for unique state tracking

Definition at line 9 of file canvas_touch_handler.cc.

References canvas_id_, yaze::gui::TouchInput::Initialize(), and Reset().

Here is the call graph for this function:

◆ Update()

◆ IsTouchActive()

bool yaze::gui::CanvasTouchHandler::IsTouchActive ( ) const

Check if touch input is currently active.

Definition at line 53 of file canvas_touch_handler.cc.

References yaze::gui::TouchInput::IsTouchActive().

Here is the call graph for this function:

◆ IsTouchMode()

bool yaze::gui::CanvasTouchHandler::IsTouchMode ( ) const

Check if we're in touch mode (vs mouse)

Definition at line 57 of file canvas_touch_handler.cc.

References yaze::gui::TouchInput::IsTouchMode().

Here is the call graph for this function:

◆ GetScrollOffset()

ImVec2 yaze::gui::CanvasTouchHandler::GetScrollOffset ( ) const
inline

Get the current scroll/pan offset for the canvas.

Definition at line 91 of file canvas_touch_handler.h.

References scroll_offset_.

◆ GetScale()

float yaze::gui::CanvasTouchHandler::GetScale ( ) const
inline

Get the current zoom scale.

Definition at line 96 of file canvas_touch_handler.h.

References current_scale_.

◆ GetZoomCenter()

ImVec2 yaze::gui::CanvasTouchHandler::GetZoomCenter ( ) const
inline

Get the zoom center point (for pivot-based zooming)

Definition at line 101 of file canvas_touch_handler.h.

References zoom_center_.

◆ SetScrollOffset()

void yaze::gui::CanvasTouchHandler::SetScrollOffset ( ImVec2 offset)

Set the scroll offset (e.g., from Canvas state)

Definition at line 61 of file canvas_touch_handler.cc.

References prev_pan_offset_, and scroll_offset_.

◆ SetScale()

void yaze::gui::CanvasTouchHandler::SetScale ( float scale)

◆ ApplyScrollDelta()

void yaze::gui::CanvasTouchHandler::ApplyScrollDelta ( ImVec2 delta)

Apply a scroll delta (add to current offset)

Definition at line 72 of file canvas_touch_handler.cc.

References scroll_offset_.

◆ ApplyZoomDelta()

void yaze::gui::CanvasTouchHandler::ApplyZoomDelta ( float delta,
ImVec2 center )

◆ Reset()

void yaze::gui::CanvasTouchHandler::Reset ( )

Reset to default state (no pan, 1.0 scale)

Definition at line 94 of file canvas_touch_handler.cc.

References current_scale_, inertia_active_, inertia_velocity_, prev_pan_offset_, prev_scale_, yaze::gui::TouchInput::ResetCanvasState(), scroll_offset_, target_scale_, and zoom_center_.

Referenced by Initialize().

Here is the call graph for this function:

◆ GetConfig() [1/2]

Config & yaze::gui::CanvasTouchHandler::GetConfig ( )
inline

Get configuration reference for modification.

Definition at line 131 of file canvas_touch_handler.h.

References config_.

◆ GetConfig() [2/2]

const Config & yaze::gui::CanvasTouchHandler::GetConfig ( ) const
inline

Definition at line 132 of file canvas_touch_handler.h.

References config_.

◆ WasTapped()

bool yaze::gui::CanvasTouchHandler::WasTapped ( ) const
inline

Check if a tap gesture occurred this frame.

Definition at line 137 of file canvas_touch_handler.h.

References was_tapped_.

◆ WasDoubleTapped()

bool yaze::gui::CanvasTouchHandler::WasDoubleTapped ( ) const
inline

Check if a double-tap gesture occurred this frame.

Definition at line 142 of file canvas_touch_handler.h.

References was_double_tapped_.

◆ WasLongPressed()

bool yaze::gui::CanvasTouchHandler::WasLongPressed ( ) const
inline

Check if a long-press gesture occurred this frame.

Definition at line 147 of file canvas_touch_handler.h.

References was_long_pressed_.

◆ GetGesturePosition()

ImVec2 yaze::gui::CanvasTouchHandler::GetGesturePosition ( ) const
inline

Get the position of the last tap/gesture.

Definition at line 152 of file canvas_touch_handler.h.

References gesture_position_.

◆ ProcessForCanvas()

void yaze::gui::CanvasTouchHandler::ProcessForCanvas ( ImVec2 canvas_p0,
ImVec2 canvas_sz,
bool is_hovered )

Process touch gestures for the current canvas bounds.

Parameters
canvas_p0Canvas top-left position in screen coordinates
canvas_szCanvas size
is_hoveredWhether mouse/touch is over the canvas

Definition at line 108 of file canvas_touch_handler.cc.

References canvas_hovered_, canvas_p0_, and canvas_sz_.

◆ ProcessGesture()

◆ ProcessInertia()

void yaze::gui::CanvasTouchHandler::ProcessInertia ( )
private

◆ ClampPanToBounds()

Member Data Documentation

◆ canvas_id_

std::string yaze::gui::CanvasTouchHandler::canvas_id_
private

Definition at line 168 of file canvas_touch_handler.h.

Referenced by Initialize().

◆ config_

Config yaze::gui::CanvasTouchHandler::config_
private

◆ scroll_offset_

ImVec2 yaze::gui::CanvasTouchHandler::scroll_offset_ = ImVec2(0, 0)
private

◆ current_scale_

float yaze::gui::CanvasTouchHandler::current_scale_ = 1.0f
private

Definition at line 173 of file canvas_touch_handler.h.

Referenced by GetScale(), ProcessGesture(), Reset(), SetScale(), and Update().

◆ target_scale_

float yaze::gui::CanvasTouchHandler::target_scale_ = 1.0f
private

Definition at line 174 of file canvas_touch_handler.h.

Referenced by ApplyZoomDelta(), ProcessGesture(), Reset(), SetScale(), and Update().

◆ zoom_center_

ImVec2 yaze::gui::CanvasTouchHandler::zoom_center_ = ImVec2(0, 0)
private

Definition at line 175 of file canvas_touch_handler.h.

Referenced by ApplyZoomDelta(), GetZoomCenter(), ProcessGesture(), and Reset().

◆ inertia_velocity_

ImVec2 yaze::gui::CanvasTouchHandler::inertia_velocity_ = ImVec2(0, 0)
private

Definition at line 178 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), ProcessInertia(), and Reset().

◆ inertia_active_

bool yaze::gui::CanvasTouchHandler::inertia_active_ = false
private

Definition at line 179 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), ProcessInertia(), Reset(), and Update().

◆ was_tapped_

bool yaze::gui::CanvasTouchHandler::was_tapped_ = false
private

Definition at line 182 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), Update(), and WasTapped().

◆ was_double_tapped_

bool yaze::gui::CanvasTouchHandler::was_double_tapped_ = false
private

Definition at line 183 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), Update(), and WasDoubleTapped().

◆ was_long_pressed_

bool yaze::gui::CanvasTouchHandler::was_long_pressed_ = false
private

Definition at line 184 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), Update(), and WasLongPressed().

◆ gesture_position_

ImVec2 yaze::gui::CanvasTouchHandler::gesture_position_ = ImVec2(0, 0)
private

Definition at line 185 of file canvas_touch_handler.h.

Referenced by GetGesturePosition(), and ProcessGesture().

◆ canvas_p0_

ImVec2 yaze::gui::CanvasTouchHandler::canvas_p0_ = ImVec2(0, 0)
private

Definition at line 188 of file canvas_touch_handler.h.

Referenced by ProcessForCanvas(), and ProcessGesture().

◆ canvas_sz_

ImVec2 yaze::gui::CanvasTouchHandler::canvas_sz_ = ImVec2(0, 0)
private

Definition at line 189 of file canvas_touch_handler.h.

Referenced by ProcessForCanvas().

◆ canvas_hovered_

bool yaze::gui::CanvasTouchHandler::canvas_hovered_ = false
private

Definition at line 190 of file canvas_touch_handler.h.

Referenced by ProcessForCanvas(), and Update().

◆ prev_pan_offset_

ImVec2 yaze::gui::CanvasTouchHandler::prev_pan_offset_ = ImVec2(0, 0)
private

Definition at line 193 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), Reset(), SetScrollOffset(), and Update().

◆ prev_scale_

float yaze::gui::CanvasTouchHandler::prev_scale_ = 1.0f
private

Definition at line 194 of file canvas_touch_handler.h.

Referenced by ProcessGesture(), Reset(), SetScale(), and Update().


The documentation for this class was generated from the following files: