@ue-too/board / index / TouchInputTracker
類別: TouchInputTracker
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:99
Production implementation of TouchContext that tracks multi-touch state.
備註
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.
範例
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()); // 2實作
建構函式
建構函式
new TouchInputTracker(
canvas):TouchInputTracker
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:107
參數
canvas
回傳
TouchInputTracker
存取器
alignCoordinateSystem
Getter 簽章
get alignCoordinateSystem():
boolean
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:151
Whether to use standard screen coordinate system (vs inverted Y-axis)
回傳
boolean
Setter 簽章
set alignCoordinateSystem(
value):void
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:155
Whether to use standard screen coordinate system (vs inverted Y-axis)
參數
value
boolean
回傳
void
Whether to use standard screen coordinate system (vs inverted Y-axis)
實作了
TouchContext.alignCoordinateSystem
canvas
Getter 簽章
get canvas():
Canvas
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:159
Canvas accessor for dimensions and coordinate transformations
回傳
Canvas accessor for dimensions and coordinate transformations
實作了
方法
addTouchPoints()
addTouchPoints(
points):void
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:112
Adds new touch points to tracking
參數
points
回傳
void
實作了
cleanup()
cleanup():
void
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:163
回傳
void
實作了
getCurrentTouchPointsCount()
getCurrentTouchPointsCount():
number
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:126
Returns the current number of active touch points
回傳
number
實作了
TouchContext.getCurrentTouchPointsCount
getInitialTouchPointsPositions()
getInitialTouchPointsPositions(
idents):TouchPoints[]
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:130
Retrieves the initial positions of specific touch points
參數
idents
number[]
回傳
實作了
TouchContext.getInitialTouchPointsPositions
removeTouchPoints()
removeTouchPoints(
identifiers):void
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:118
Removes touch points from tracking by identifier
參數
identifiers
number[]
回傳
void
實作了
TouchContext.removeTouchPoints
setup()
setup():
void
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:165
回傳
void
實作了
updateTouchPoints()
updateTouchPoints(
pointsMoved):void
定義於: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:143
Updates the current positions of touch points
參數
pointsMoved
回傳
void