Class InputStateBase
Base class for input states with default implementations.
public abstract class InputStateBase : IInputState
- Inheritance
-
InputStateBase
- Implements
- Derived
- Inherited Members
Properties
IsModal
Gets whether this state blocks other interactions.
public virtual bool IsModal { get; }
Property Value
Name
Gets the name of this state for debugging.
public abstract string Name { get; }
Property Value
Methods
CapturePointer(PointerEventArgs, IInputElement?)
Captures the pointer to the specified element.
protected static void CapturePointer(PointerEventArgs e, IInputElement? element)
Parameters
ePointerEventArgselementIInputElement
Enter(InputStateContext)
Called when entering this state.
public virtual void Enter(InputStateContext context)
Parameters
contextInputStateContext
Exit(InputStateContext)
Called when exiting this state.
public virtual void Exit(InputStateContext context)
Parameters
contextInputStateContext
GetCanvasPosition(InputStateContext, PointerEventArgs)
Gets the current pointer position in canvas coordinates.
[Obsolete("Use GetTypedCanvasPosition() instead. The typed method works in both Visual Tree and Direct Rendering modes.")]
protected static Point GetCanvasPosition(InputStateContext context, PointerEventArgs e)
Parameters
contextInputStateContextePointerEventArgs
Returns
- Point
Remarks
DEPRECATED: Use GetTypedCanvasPosition(InputStateContext, PointerEventArgs) instead. This method only works correctly in Visual Tree mode. The typed method handles both rendering modes correctly.
GetPointerPoint(InputStateContext, PointerEventArgs)
Gets the pointer point for button state information.
protected static PointerPoint GetPointerPoint(InputStateContext context, PointerEventArgs e)
Parameters
contextInputStateContextePointerEventArgs
Returns
- PointerPoint
GetScreenPosition(InputStateContext, PointerEventArgs)
Gets the current pointer position relative to the root panel (viewport coordinates).
[Obsolete("Use GetTypedViewportPosition() instead. Returns typed ViewportPoint that prevents coordinate confusion.")]
protected static Point GetScreenPosition(InputStateContext context, PointerEventArgs e)
Parameters
contextInputStateContextePointerEventArgs
Returns
- Point
Remarks
DEPRECATED: Use GetTypedViewportPosition(InputStateContext, PointerEventArgs) instead. This method returns an untyped Avalonia.Point which doesn't indicate whether it's in canvas or viewport coordinates, making it easy to accidentally pass to the wrong conversion method.
GetTypedCanvasPosition(InputStateContext, PointerEventArgs)
Gets the current pointer position in canvas coordinates.
protected static CanvasPoint GetTypedCanvasPosition(InputStateContext context, PointerEventArgs e)
Parameters
contextInputStateContextePointerEventArgs
Returns
Remarks
This is the preferred method for getting pointer positions when you need canvas coordinates. It uses the type-safe coordinate system and works correctly in both Visual Tree and Direct Rendering modes.
Use canvas coordinates for:
- Hit testing on the canvas
- Node/edge positions
- Selection box bounds
- Any position that needs to be stored or compared with node data
GetTypedViewportPosition(InputStateContext, PointerEventArgs)
Gets the current pointer position in viewport coordinates.
protected static ViewportPoint GetTypedViewportPosition(InputStateContext context, PointerEventArgs e)
Parameters
contextInputStateContextePointerEventArgs
Returns
Remarks
This is the preferred method for getting pointer positions when you need viewport coordinates. It uses the type-safe coordinate system and works correctly in both Visual Tree and Direct Rendering modes.
Use viewport coordinates for:
- Pan calculations (delta from last position)
- Auto-pan edge detection
- UI overlay positioning
- Any position relative to the visible screen area
HandleKeyDown(InputStateContext, KeyEventArgs)
Handles key down events.
public virtual StateTransitionResult HandleKeyDown(InputStateContext context, KeyEventArgs e)
Parameters
contextInputStateContexteKeyEventArgs
Returns
HandlePointerMoved(InputStateContext, PointerEventArgs)
Handles pointer moved events.
public virtual StateTransitionResult HandlePointerMoved(InputStateContext context, PointerEventArgs e)
Parameters
contextInputStateContextePointerEventArgs
Returns
HandlePointerPressed(InputStateContext, PointerPressedEventArgs, Control?)
Handles pointer pressed events.
public virtual StateTransitionResult HandlePointerPressed(InputStateContext context, PointerPressedEventArgs e, Control? source)
Parameters
contextInputStateContextePointerPressedEventArgssourceControl
Returns
HandlePointerReleased(InputStateContext, PointerReleasedEventArgs)
Handles pointer released events.
public virtual StateTransitionResult HandlePointerReleased(InputStateContext context, PointerReleasedEventArgs e)
Parameters
contextInputStateContextePointerReleasedEventArgs
Returns
HandlePointerWheel(InputStateContext, PointerWheelEventArgs)
Handles pointer wheel events.
public virtual StateTransitionResult HandlePointerWheel(InputStateContext context, PointerWheelEventArgs e)
Parameters
contextInputStateContextePointerWheelEventArgs
Returns
HitTestCanvas(InputStateContext, Point)
Performs hit testing on the main canvas. The position must be in canvas coordinates (use GetCanvasPosition, not GetScreenPosition).
protected static IInputElement? HitTestCanvas(InputStateContext context, Point canvasPosition)
Parameters
contextInputStateContextcanvasPositionPoint
Returns
- IInputElement
HitTestForPort(InputStateContext, Point)
Performs hit testing on the main canvas specifically for finding ports. Skips edge paths and markers that might be blocking the port. The position must be in canvas coordinates.
protected static Control? HitTestForPort(InputStateContext context, Point canvasPosition)
Parameters
contextInputStateContextcanvasPositionPoint
Returns
- Control
ReleasePointer(PointerEventArgs)
Releases pointer capture.
protected static void ReleasePointer(PointerEventArgs e)
Parameters
ePointerEventArgs
ToAvaloniaPoint(CanvasPoint)
Converts a canvas point to an Avalonia Point for backward compatibility.
protected static Point ToAvaloniaPoint(CanvasPoint canvas)
Parameters
canvasCanvasPoint
Returns
- Point
ToAvaloniaPoint(ViewportPoint)
Converts a viewport point to an Avalonia Point for backward compatibility.
protected static Point ToAvaloniaPoint(ViewportPoint viewport)
Parameters
viewportViewportPoint
Returns
- Point
ToCanvasPoint(Point)
Converts an Avalonia Point to a CanvasPoint.
protected static CanvasPoint ToCanvasPoint(Point point)
Parameters
pointPoint
Returns
ToViewportPoint(Point)
Converts an Avalonia Point to a ViewportPoint.
protected static ViewportPoint ToViewportPoint(Point point)
Parameters
pointPoint
Returns
Update(InputStateContext, double)
Called each frame for states that need continuous updates (e.g., animations).
public virtual void Update(InputStateContext context, double deltaTime)
Parameters
contextInputStateContextdeltaTimedouble