Skip to content

Commit 165d950

Browse files
hit testing works after multiple matricies have been applied
1 parent 88801ae commit 165d950

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Flamui/HitTester.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ public void HandleHitTest()
3333
}
3434
}
3535

36-
private void HitTest(Vector2 point)
36+
List<UiElement> hitElements = new();
37+
38+
private void HitTest(Vector2 originalPoint)
3739
{
38-
var hitElements = new List<UiElement>();
40+
var transformedPoint = originalPoint;
41+
42+
hitElements.Clear();
3943

4044
//from back to front
4145
foreach (var (_, value) in _window.LastRenderContext.CommandBuffers.OrderBy(x => x.Key))
@@ -44,19 +48,19 @@ private void HitTest(Vector2 point)
4448
{
4549
if (command.Type == CommandType.Matrix)
4650
{
47-
point = point.Multiply(command.Matrix.Invert());
51+
transformedPoint = originalPoint.Multiply(command.Matrix.Invert());
4852
}
4953
else if (command.Type == CommandType.Rect)
5054
{
5155
command.UiElement.Get().FinalOnScreenSize = command.Bounds;
52-
if (command.Bounds.ContainsPoint(point))
56+
if (command.Bounds.ContainsPoint(transformedPoint))
5357
{
5458
hitElements.Add(command.UiElement.Get());
5559
}
5660
}else if (command.Type == CommandType.Text)
5761
{
5862
command.UiElement.Get().FinalOnScreenSize = command.Bounds;
59-
if (command.Bounds.ContainsPoint(point))
63+
if (command.Bounds.ContainsPoint(transformedPoint))
6064
{
6165
hitElements.Add(command.UiElement.Get());
6266
}

0 commit comments

Comments
 (0)