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

Touch input handling system for iPad and tablet browsers. More...

#include <touch_input.h>

Static Public Member Functions

static void Initialize ()
 Initialize the touch input system.
 
static void Shutdown ()
 Shutdown and cleanup touch input system.
 
static void Update ()
 Process touch events for the current frame.
 
static bool IsTouchActive ()
 Check if touch input is currently being used.
 
static bool IsTouchMode ()
 Check if we're in touch mode (vs mouse mode)
 
static GestureState GetCurrentGesture ()
 Get the current gesture state.
 
static TouchPoint GetTouchPoint (int index)
 Get raw touch point data.
 
static int GetActiveTouchCount ()
 Get number of active touch points.
 
static void SetPanZoomEnabled (bool enabled)
 Enable or disable pan/zoom gestures for canvas.
 
static bool IsPanZoomEnabled ()
 Check if pan/zoom is enabled.
 
static ImVec2 GetPanOffset ()
 Get cumulative pan offset from touch gestures.
 
static float GetZoomLevel ()
 Get cumulative zoom level from pinch gestures.
 
static float GetRotation ()
 Get rotation angle from two-finger rotation.
 
static ImVec2 GetZoomCenter ()
 Get the zoom center point in screen coordinates.
 
static void ApplyPanOffset (ImVec2 offset)
 Apply pan offset to the current value.
 
static void SetZoomLevel (float zoom)
 Set the zoom level directly.
 
static void SetPanOffset (ImVec2 offset)
 Set the pan offset directly.
 
static void ResetCanvasState ()
 Reset canvas transform state.
 
static TouchConfigGetConfig ()
 Get the current touch configuration.
 
static void SetGestureCallback (std::function< void(const GestureState &)> callback)
 Set gesture callback.
 

Static Public Attributes

static constexpr int kMaxTouchPoints = 10
 Maximum number of simultaneous touch points supported.
 

Private Member Functions

 TouchInput ()=delete
 

Static Private Member Functions

static void UpdateGestureRecognition ()
 
static void ProcessInertia ()
 
static void TranslateToImGuiEvents ()
 
static double GetCurrentTime ()
 
static void InitializePlatform ()
 
static void ShutdownPlatform ()
 

Detailed Description

Touch input handling system for iPad and tablet browsers.

Provides gesture recognition and touch event handling for the yaze editor. Integrates with ImGui's input system and the Canvas pan/zoom functionality.

Features:

  • Single tap: Translates to left mouse click
  • Double tap: Context menu or zoom-to-fit
  • Long press: Context menu activation
  • Two-finger pan: Canvas scrolling
  • Pinch to zoom: Canvas zoom in/out
  • Two-finger rotate: Optional sprite rotation

Usage:

// Initialize once at startup
// Call each frame before ImGui::NewFrame()
// Check touch state in your code
// Handle gesture...
}
// Get canvas transform values
ImVec2 pan = TouchInput::GetPanOffset();
float zoom = TouchInput::GetZoomLevel();
static ImVec2 GetPanOffset()
Get cumulative pan offset from touch gestures.
static void Initialize()
Initialize the touch input system.
static bool IsTouchActive()
Check if touch input is currently being used.
static float GetZoomLevel()
Get cumulative zoom level from pinch gestures.
static GestureState GetCurrentGesture()
Get the current gesture state.
static void Update()
Process touch events for the current frame.

Definition at line 137 of file touch_input.h.

Constructor & Destructor Documentation

◆ TouchInput()

yaze::gui::TouchInput::TouchInput ( )
privatedelete

Member Function Documentation

◆ Initialize()

void yaze::gui::TouchInput::Initialize ( )
static

Initialize the touch input system.

Sets up touch event handlers. On web builds, this registers JavaScript callbacks for touch events. On native builds, it configures SDL touch support.

Definition at line 140 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::initialized, InitializePlatform(), LOG_INFO, and yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::touch_points.

Referenced by yaze::gui::CanvasTouchHandler::Initialize().

Here is the call graph for this function:

◆ Shutdown()

void yaze::gui::TouchInput::Shutdown ( )
static

Shutdown and cleanup touch input system.

Definition at line 160 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::initialized, LOG_INFO, and ShutdownPlatform().

Here is the call graph for this function:

◆ Update()

◆ IsTouchActive()

bool yaze::gui::TouchInput::IsTouchActive ( )
static

Check if touch input is currently being used.

Returns
true if any touch points are active

Definition at line 198 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::active_touch_count.

Referenced by yaze::gui::CanvasTouchHandler::IsTouchActive(), and yaze::gui::CanvasTouchHandler::Update().

◆ IsTouchMode()

bool yaze::gui::TouchInput::IsTouchMode ( )
static

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

Returns true if the last input was from touch, even if no touches are currently active. Used for UI adaptation (larger hit targets, etc.)

Returns
true if touch mode is active

Definition at line 202 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::touch_mode.

Referenced by yaze::gui::CanvasTouchHandler::IsTouchMode().

◆ GetCurrentGesture()

GestureState yaze::gui::TouchInput::GetCurrentGesture ( )
static

Get the current gesture state.

Returns
Current gesture recognition result

Definition at line 206 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::current_gesture.

Referenced by yaze::gui::CanvasTouchHandler::Update().

◆ GetTouchPoint()

TouchPoint yaze::gui::TouchInput::GetTouchPoint ( int index)
static

Get raw touch point data.

Parameters
indexTouch point index (0 to kMaxTouchPoints-1)
Returns
Touch point data, or inactive touch if index invalid

Definition at line 210 of file touch_input.cc.

References kMaxTouchPoints, and yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::touch_points.

◆ GetActiveTouchCount()

int yaze::gui::TouchInput::GetActiveTouchCount ( )
static

Get number of active touch points.

Returns
Number of currently active touches

Definition at line 217 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::active_touch_count.

◆ SetPanZoomEnabled()

void yaze::gui::TouchInput::SetPanZoomEnabled ( bool enabled)
static

Enable or disable pan/zoom gestures for canvas.

Parameters
enabledWhether to process pan/zoom gestures

Definition at line 221 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::pan_zoom_enabled.

◆ IsPanZoomEnabled()

bool yaze::gui::TouchInput::IsPanZoomEnabled ( )
static

Check if pan/zoom is enabled.

Returns
true if pan/zoom gestures are being processed

Definition at line 225 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::pan_zoom_enabled.

◆ GetPanOffset()

ImVec2 yaze::gui::TouchInput::GetPanOffset ( )
static

Get cumulative pan offset from touch gestures.

This value accumulates pan translations. Reset with ResetCanvasState().

Returns
Pan offset in pixels

Definition at line 229 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::pan_offset.

Referenced by yaze::gui::CanvasTouchHandler::ProcessGesture().

◆ GetZoomLevel()

float yaze::gui::TouchInput::GetZoomLevel ( )
static

Get cumulative zoom level from pinch gestures.

Starts at 1.0. Multiply your canvas scale by this value.

Returns
Zoom level (1.0 = no zoom, >1.0 = zoomed in, <1.0 = zoomed out)

Definition at line 233 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::zoom_level.

Referenced by yaze::gui::CanvasTouchHandler::ProcessGesture().

◆ GetRotation()

float yaze::gui::TouchInput::GetRotation ( )
static

Get rotation angle from two-finger rotation.

Returns
Rotation in radians

Definition at line 237 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::rotation.

◆ GetZoomCenter()

ImVec2 yaze::gui::TouchInput::GetZoomCenter ( )
static

Get the zoom center point in screen coordinates.

Use this as the pivot point when applying zoom transformations.

Returns
Center point of the pinch gesture

Definition at line 241 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::zoom_center.

Referenced by yaze::gui::CanvasTouchHandler::ProcessGesture().

◆ ApplyPanOffset()

void yaze::gui::TouchInput::ApplyPanOffset ( ImVec2 offset)
static

Apply pan offset to the current value.

Parameters
offsetPan offset to apply

Definition at line 245 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::pan_offset.

◆ SetZoomLevel()

void yaze::gui::TouchInput::SetZoomLevel ( float zoom)
static

Set the zoom level directly.

Parameters
zoomNew zoom level

Definition at line 250 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::config, and yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::zoom_level.

◆ SetPanOffset()

void yaze::gui::TouchInput::SetPanOffset ( ImVec2 offset)
static

Set the pan offset directly.

Parameters
offsetNew pan offset

Definition at line 255 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::pan_offset.

◆ ResetCanvasState()

◆ GetConfig()

TouchConfig & yaze::gui::TouchInput::GetConfig ( )
static

Get the current touch configuration.

Returns
Reference to configuration struct

Definition at line 267 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::config.

◆ SetGestureCallback()

void yaze::gui::TouchInput::SetGestureCallback ( std::function< void(const GestureState &)> callback)
static

Set gesture callback.

Optional callback invoked when gestures are recognized.

Parameters
callbackFunction to call with gesture state

Definition at line 271 of file touch_input.cc.

References yaze::gui::anonymous_namespace{touch_input.cc}::TouchInputState::gesture_callback.

◆ UpdateGestureRecognition()

◆ ProcessInertia()

void yaze::gui::TouchInput::ProcessInertia ( )
staticprivate

◆ TranslateToImGuiEvents()

void yaze::gui::TouchInput::TranslateToImGuiEvents ( )
staticprivate

◆ GetCurrentTime()

double yaze::gui::TouchInput::GetCurrentTime ( )
staticprivate

Definition at line 570 of file touch_input.cc.

◆ InitializePlatform()

void yaze::gui::TouchInput::InitializePlatform ( )
staticprivate

Definition at line 731 of file touch_input.cc.

References LOG_INFO.

Referenced by Initialize().

◆ ShutdownPlatform()

void yaze::gui::TouchInput::ShutdownPlatform ( )
staticprivate

Definition at line 738 of file touch_input.cc.

Referenced by Shutdown().

Member Data Documentation

◆ kMaxTouchPoints

constexpr int yaze::gui::TouchInput::kMaxTouchPoints = 10
staticconstexpr

Maximum number of simultaneous touch points supported.

Definition at line 142 of file touch_input.h.

Referenced by GetTouchPoint().


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