Table of Contents

Class DirectRendererHitTester

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

Adapts DirectCanvasRenderer hit testing to the IGraphHitTester interface.

public class DirectRendererHitTester : IGraphHitTester
Inheritance
DirectRendererHitTester
Implements
Inherited Members

Remarks

This adapter bridges the gap between the existing DirectCanvasRenderer hit testing (which returns separate results per element type) and the new unified IGraphHitTester interface (which returns a single GraphHitTestResult).

Coordinate Space: DirectCanvasRenderer expects screen/viewport coordinates and converts internally. This adapter expects canvas coordinates and converts to screen coordinates for the renderer.

Priority Order (determines actual hit priority):

  1. Node resize handles (highest - small targets on selected nodes)
  2. Shape resize handles (small targets on selected shapes)
  3. Edge endpoint handles (for reconnection)
  4. Ports (small targets)
  5. Nodes
  6. Edges
  7. Shapes (lowest - background elements)

Note: Since this hit tester returns a single topmost result, the InputDispatcher processor priorities are not used for determining which element is hit. Priority is enforced entirely by this class's if/else chain ordering.

Constructors

DirectRendererHitTester(Func<DirectCanvasRenderer?>, ViewportState)

Creates a new hit tester that wraps a DirectCanvasRenderer.

public DirectRendererHitTester(Func<DirectCanvasRenderer?> getRenderer, ViewportState viewport)

Parameters

getRenderer Func<DirectCanvasRenderer>

Function to get the current renderer (may be null if not initialized).

viewport ViewportState

The viewport state for coordinate conversion.

Properties

InputCoordinateSpace

The coordinate space expected for hit test inputs.

Standard implementations expect Canvas coordinates. Callers using screen coordinates (e.g., from pointer events) must convert using ScreenToCanvas(double, double) first.

public CoordinateSpace InputCoordinateSpace { get; }

Property Value

CoordinateSpace

Methods

HitTest(Point)

Performs a comprehensive hit test against all graph elements.

public GraphHitTestResult HitTest(Point canvasPosition)

Parameters

canvasPosition Point

Returns

GraphHitTestResult

The hit test result identifying what was hit. If nothing specific was hit, returns a result with Canvas.

HitTest(Point, params HitTargetType[])

Performs a hit test filtering to specific element types.

public GraphHitTestResult HitTest(Point position, params HitTargetType[] targetTypes)

Parameters

position Point

Position to test.

targetTypes HitTargetType[]

Which element types to consider.

Returns

GraphHitTestResult

The hit test result, only matching specified types.

HitTest(Point, double, double, double)

Performs a hit test with custom tolerance values.

public GraphHitTestResult HitTest(Point position, double nodeTolerance = 0, double edgeTolerance = 5, double portTolerance = 8)

Parameters

position Point

Position to test.

nodeTolerance double

Extra tolerance for node bounds.

edgeTolerance double

Extra tolerance for edge paths.

portTolerance double

Extra tolerance for port targets.

Returns

GraphHitTestResult

The hit test result.