Table of Contents

Class InputDispatcher

Namespace
FlowGraph.Avalonia.Input
Assembly
FlowGraph.Avalonia.dll

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

IReadOnlyList<IBehavior>

Processors

Gets all registered processors (for debugging).

public IReadOnlyList<IInputProcessor> Processors { get; }

Property Value

IReadOnlyList<IInputProcessor>

Methods

DispatchKeyDown(InputStateContext, KeyEventArgs, string)

Dispatches a key down event for keyboard shortcuts.

public StateTransitionResult DispatchKeyDown(InputStateContext context, KeyEventArgs e, string currentStateName = "Idle")

Parameters

context InputStateContext

The input state context.

e KeyEventArgs

The key event args.

currentStateName string

Name of the current state (for behavior filtering).

Returns

StateTransitionResult

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

context InputStateContext

The input state context.

e PointerEventArgs

The pointer event args.

canvasPosition Point

Position in canvas coordinates.

viewportPosition Point

Position in viewport coordinates.

currentStateName string

Name of the current state (for behavior filtering).

Returns

StateTransitionResult

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

context InputStateContext

The input state context.

e PointerPressedEventArgs

The pointer event args.

canvasPosition Point

Position in canvas coordinates.

viewportPosition Point

Position in viewport coordinates.

currentStateName string

Name of the current state (for behavior filtering).

Returns

StateTransitionResult

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

context InputStateContext

The input state context.

e PointerReleasedEventArgs

The pointer event args.

canvasPosition Point

Position in canvas coordinates.

viewportPosition Point

Position in viewport coordinates.

currentStateName string

Name of the current state (for behavior filtering).

Returns

StateTransitionResult

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

context InputStateContext

The input state context.

e PointerWheelEventArgs

The wheel event args.

viewportPosition Point

Position in viewport coordinates.

currentStateName string

Name of the current state (for behavior filtering).

Returns

StateTransitionResult

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

behavior IBehavior

RegisterProcessor(IInputProcessor)

Registers an input processor.

public void RegisterProcessor(IInputProcessor processor)

Parameters

processor IInputProcessor

SetGraph(Graph?)

Sets the current graph (for behavior attachment).

public void SetGraph(Graph? graph)

Parameters

graph Graph

SetHitTester(IGraphHitTester)

Sets the hit tester implementation.

public void SetHitTester(IGraphHitTester hitTester)

Parameters

hitTester IGraphHitTester

UnregisterBehavior(IBehavior)

Unregisters a behavior.

public bool UnregisterBehavior(IBehavior behavior)

Parameters

behavior IBehavior

Returns

bool

UnregisterProcessor(IInputProcessor)

Unregisters an input processor.

public bool UnregisterProcessor(IInputProcessor processor)

Parameters

processor IInputProcessor

Returns

bool