Skip to content

LookGestureTracker ​

Inherits: RefCounted

Pure state machine behind the InputManager's mouse-look gestures. No nodes, no Input singleton, no scene access, so it is unit-tested headless (res://tests/run_tests.gd).

Description ​

Feed it presses, motion and releases; it returns a list of events (dictionaries): { type: EventType, kind: LookBinding.Kind, button: int, position: Vector2, delta: Vector2 } STARTED - a look gesture began (position = where the button was pressed) DELTA - look movement (delta = raw relative mouse motion, pixels) ENDED - a look gesture ended (position = where the button was pressed) CLICK - a drag-required gesture was released before it became a drag

Rules:

  • A button with a binding starts PENDING on press. If the binding does not require a drag it

becomes ACTIVE immediately, otherwise once the pointer moves past the drag threshold.

  • Only the highest-priority ACTIVE gesture receives DELTA events (LookBinding.priority), so

holding both buttons never applies the same motion twice.

  • Releasing a button only ends that button's gesture; other gestures carry on.

Methods ​

voidset_bindings( bindings: Array )
Arraypress( button_index: int, position: Vector2 )
Arraymotion( relative: Vector2, position: Vector2, drag_threshold: float )
Arrayrelease( button_index: int )
Arraycancel_all()
boolhas_active()
boolhas_any()
boolis_button_tracked( button_index: int )
Arrayget_tracked_buttons()
boolis_kind_active( kind: LookBinding.Kind )
Dictionarymerge_bindings( controller_bindings: Array, camera_bindings: Array, controller_exclusive_buttons: Array ) static

Enumerations ​

enum EventType ​

The options of event type: started, delta, ended, click.

  • STARTED = 0
  • DELTA = 1
  • ENDED = 2
  • CLICK = 3

enum Phase ​

The options of phase: pending, active.

  • PENDING = 0
  • ACTIVE = 1

Method descriptions ​

void set_bindings( bindings: Array ) ​

Replaces the binding table. Gestures that are already tracked keep running until released.

Array press( button_index: int, position: Vector2 ) ​

A button went down: starts tracking it. Gives the events the gesture causes.

Array motion( relative: Vector2, position: Vector2, drag_threshold: float ) ​

position is the pointer position (used for the drag threshold); relative the raw motion

Array release( button_index: int ) ​

A button went up. Gives the events the gesture causes.

Array cancel_all() ​

Ends everything (focus loss, pause, leaving the game state). Pending gestures are dropped silently.

bool has_active() ​

Is any gesture past its drag threshold (a look is on)?

bool has_any() ​

Any gesture pending or active

bool is_button_tracked( button_index: int ) ​

Is this button being tracked?

Array get_tracked_buttons() ​

The buttons that are tracked now.

bool is_kind_active( kind: LookBinding.Kind ) ​

Is a gesture of this kind on?

Dictionary merge_bindings( controller_bindings: Array, camera_bindings: Array, controller_exclusive_buttons: Array ) ​

Merges the controller's and the camera's claims into one binding table. Result: { bindings: Array[LookBinding] - one per button, to give to set_bindings() controller_kinds: Array - LookBinding.Kind values the controller should be told about camera_kinds: Array - LookBinding.Kind values the camera should be told about conflicts: Array[String] - human-readable problems (dropped claims), for a warning }

  • Both sides claiming the SAME button with the SAME kind is the normal shared case (e.g. RMB

CHARACTER_LOOK: the controller turns the body, the camera applies pitch). If either side requires a drag, the shared binding requires it.

  • A button the controller lists in controller_exclusive_buttons is the controller's own

(e.g. LMB drag-box select): the camera's claim on it is dropped.

  • Two different kinds on one button is a conflict: the controller's claim wins.