@ue-too/board / TouchInputTracker
Class: TouchInputTracker
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:99
Production implementation of TouchContext that tracks multi-touch state.
Remarks
This class maintains a map of active touch points, storing their initial positions to enable gesture recognition. The state machine uses this context to:
- Calculate pan deltas (difference between initial and current midpoint)
- Calculate zoom factors (change in distance between two touch points)
- Determine gesture type (pan vs zoom based on relative magnitudes)
Touch Point Lifecycle:
addTouchPoints: Called on touchstart to register new touchesupdateTouchPoints: Called on touchmove to update current positionsremoveTouchPoints: Called on touchend/touchcancel to unregister touches
The initial positions are preserved until the touch ends, allowing continuous calculation of deltas throughout the gesture.
Example
const canvasProxy = new CanvasProxy(canvasElement);
const context = new TouchInputTracker(canvasProxy);
const stateMachine = createTouchInputStateMachine(context);
// When a two-finger touch starts
context.addTouchPoints([
{ident: 0, x: 100, y: 200},
{ident: 1, x: 300, y: 200}
]);
console.log(context.getCurrentTouchPointsCount()); // 2Implements
Constructors
Constructor
new TouchInputTracker(
canvas):TouchInputTracker
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:107
Parameters
canvas
Returns
TouchInputTracker
Accessors
alignCoordinateSystem
Get Signature
get alignCoordinateSystem():
boolean
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:151
Whether to use standard screen coordinate system (vs inverted Y-axis)
Returns
boolean
Set Signature
set alignCoordinateSystem(
value):void
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:155
Whether to use standard screen coordinate system (vs inverted Y-axis)
Parameters
value
boolean
Returns
void
Whether to use standard screen coordinate system (vs inverted Y-axis)
Implementation of
TouchContext.alignCoordinateSystem
canvas
Get Signature
get canvas():
Canvas
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:159
Canvas accessor for dimensions and coordinate transformations
Returns
Canvas accessor for dimensions and coordinate transformations
Implementation of
Methods
addTouchPoints()
addTouchPoints(
points):void
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:112
Adds new touch points to tracking
Parameters
points
Returns
void
Implementation of
cleanup()
cleanup():
void
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:163
Returns
void
Implementation of
getCurrentTouchPointsCount()
getCurrentTouchPointsCount():
number
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:126
Returns the current number of active touch points
Returns
number
Implementation of
TouchContext.getCurrentTouchPointsCount
getInitialTouchPointsPositions()
getInitialTouchPointsPositions(
idents):TouchPoints[]
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:130
Retrieves the initial positions of specific touch points
Parameters
idents
number[]
Returns
Implementation of
TouchContext.getInitialTouchPointsPositions
removeTouchPoints()
removeTouchPoints(
identifiers):void
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:118
Removes touch points from tracking by identifier
Parameters
identifiers
number[]
Returns
void
Implementation of
TouchContext.removeTouchPoints
setup()
setup():
void
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:165
Returns
void
Implementation of
updateTouchPoints()
updateTouchPoints(
pointsMoved):void
Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:143
Updates the current positions of touch points
Parameters
pointsMoved
Returns
void