Class InputDispatcher
Coordinates input handling between behaviors, processors, and the state machine.
public class InputDispatcher
- Inheritance
-
InputDispatcher
- Inherited Members
Remarks
The InputDispatcher is the central coordinator for the hybrid input architecture:
Input Event (PointerPressed, etc.)
│
▼
┌───────────────────────┐
│ InputDispatcher │
└───────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌──────────┐ ┌────────────┐ ┌──────────┐
│ Behaviors │ │ HitTester │ │ State │
│ (before) │ │ │ │ Machine │
└──────────┘ └────────────┘ └──────────┘
│ │ │
│ ▼ │
│ GraphHitTestResult │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ InputProcessor │ │
│ │ (by hit type) │ │
│ └─────────────────┘ │
│ │ │
│ ▼ │
│ State Transition?──────────┘
│ │
▼ ▼
┌──────────┐ Result/New State
│ Behaviors │
│ (after) │
└──────────┘
Performance Optimizations (Gemini):
- HitTargetType is a [Flags] enum for O(1) bitmask checks
- Processor lookup uses pre-computed Dictionary for O(1) dispatch
- Behaviors support state-aware filtering via ActiveInStates
- Processor list sorted once on registration, not on every dispatch
Pointer Capture (Critical for Drag Operations):
When a processor starts a drag operation (e.g., NodeProcessor → DraggingState),
it MUST capture the pointer via e.Pointer.Capture(control). This ensures
the interaction state continues to receive events even if the mouse moves
outside the element's visual bounds. Without capture, fast mouse movements
would cause hit tests to return "Canvas" instead of the element being dragged.
Properties
Behaviors
Gets all registered behaviors (for debugging).
public IReadOnlyList<IBehavior> Behaviors { get; }
Property Value
Processors
Gets all registered processors (for debugging).
public IReadOnlyList<IInputProcessor> Processors { get; }
Property Value
Methods
DispatchKeyDown(InputStateContext, KeyEventArgs, string)
Dispatches a key down event for keyboard shortcuts.
public StateTransitionResult DispatchKeyDown(InputStateContext context, KeyEventArgs e, string currentStateName = "Idle")
Parameters
contextInputStateContextThe input state context.
eKeyEventArgsThe key event args.
currentStateNamestringName of the current state (for behavior filtering).
Returns
Remarks
Keyboard events don't use processors - they're handled globally. Note: Behavior keyboard hooks are not currently implemented as they require a framework-agnostic key representation. This handles keyboard shortcuts directly.
DispatchPointerMoved(InputStateContext, PointerEventArgs, Point, Point, string)
Dispatches a pointer moved event through the full pipeline.
public StateTransitionResult DispatchPointerMoved(InputStateContext context, PointerEventArgs e, Point canvasPosition, Point viewportPosition, string currentStateName = "Idle")
Parameters
contextInputStateContextThe input state context.
ePointerEventArgsThe pointer event args.
canvasPositionPointPosition in canvas coordinates.
viewportPositionPointPosition in viewport coordinates.
currentStateNamestringName of the current state (for behavior filtering).
Returns
DispatchPointerPressed(InputStateContext, PointerPressedEventArgs, Point, Point, string)
Dispatches a pointer pressed event through the full pipeline.
public StateTransitionResult DispatchPointerPressed(InputStateContext context, PointerPressedEventArgs e, Point canvasPosition, Point viewportPosition, string currentStateName = "Idle")
Parameters
contextInputStateContextThe input state context.
ePointerPressedEventArgsThe pointer event args.
canvasPositionPointPosition in canvas coordinates.
viewportPositionPointPosition in viewport coordinates.
currentStateNamestringName of the current state (for behavior filtering).
Returns
DispatchPointerReleased(InputStateContext, PointerReleasedEventArgs, Point, Point, string)
Dispatches a pointer released event through the full pipeline.
public StateTransitionResult DispatchPointerReleased(InputStateContext context, PointerReleasedEventArgs e, Point canvasPosition, Point viewportPosition, string currentStateName = "Idle")
Parameters
contextInputStateContextThe input state context.
ePointerReleasedEventArgsThe pointer event args.
canvasPositionPointPosition in canvas coordinates.
viewportPositionPointPosition in viewport coordinates.
currentStateNamestringName of the current state (for behavior filtering).
Returns
DispatchPointerWheel(InputStateContext, PointerWheelEventArgs, Point, string)
Dispatches a pointer wheel event for viewport zoom/pan.
public StateTransitionResult DispatchPointerWheel(InputStateContext context, PointerWheelEventArgs e, Point viewportPosition, string currentStateName = "Idle")
Parameters
contextInputStateContextThe input state context.
ePointerWheelEventArgsThe wheel event args.
viewportPositionPointPosition in viewport coordinates.
currentStateNamestringName of the current state (for behavior filtering).
Returns
Remarks
Unlike other pointer events, wheel events don't use hit testing or processors. They directly affect the viewport (zoom or pan) based on settings. Behaviors can still intercept or observe wheel events.
RegisterBehavior(IBehavior)
Registers a behavior.
public void RegisterBehavior(IBehavior behavior)
Parameters
behaviorIBehavior
RegisterProcessor(IInputProcessor)
Registers an input processor.
public void RegisterProcessor(IInputProcessor processor)
Parameters
processorIInputProcessor
SetGraph(Graph?)
Sets the current graph (for behavior attachment).
public void SetGraph(Graph? graph)
Parameters
graphGraph
SetHitTester(IGraphHitTester)
Sets the hit tester implementation.
public void SetHitTester(IGraphHitTester hitTester)
Parameters
hitTesterIGraphHitTester
UnregisterBehavior(IBehavior)
Unregisters a behavior.
public bool UnregisterBehavior(IBehavior behavior)
Parameters
behaviorIBehavior
Returns
UnregisterProcessor(IInputProcessor)
Unregisters an input processor.
public bool UnregisterProcessor(IInputProcessor processor)
Parameters
processorIInputProcessor