Browse Source

Fix hit testing in RectangleNode.

There were two problems here:

- As #2370 describes we were tested against the rotated AABB of the rectangle
- We were hit-testing non-filled rectangles as filled rectangles

Fixes #2370
pull/2537/head
Steven Kirk 7 years ago
parent
commit
88f2bd791d
  1. 24
      src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs

24
src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs

@ -105,8 +105,28 @@ namespace Avalonia.Rendering.SceneGraph
}
}
// TODO: This doesn't respect CornerRadius yet.
/// <inheritdoc/>
public override bool HitTest(Point p) => Bounds.Contains(p);
public override bool HitTest(Point p)
{
// TODO: This doesn't respect CornerRadius yet.
if (Transform.HasInverse)
{
p *= Transform.Invert();
if (Brush != null)
{
var rect = Rect.Inflate((Pen?.Thickness / 2) ?? 0);
return rect.Contains(p);
}
else
{
var borderRect = Rect.Inflate((Pen?.Thickness / 2) ?? 0);
var emptyRect = Rect.Deflate((Pen?.Thickness / 2) ?? 0);
return borderRect.Contains(p) && !emptyRect.Contains(p);
}
}
return false;
}
}
}

Loading…
Cancel
Save