-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHitTest.cs
More file actions
42 lines (38 loc) · 1.11 KB
/
Copy pathHitTest.cs
File metadata and controls
42 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Windows;
using CSharpCodeAnalyst.Contracts;
using CSharpCodeAnalyst.TreeMap.TreeMap;
namespace CSharpCodeAnalyst.TreeMap.Common
{
internal sealed class HitTest
{
/// <summary>
/// The layout must have been calculated - pass the map the renderer produced.
/// </summary>
public IHierarchicalData? Hit(IHierarchicalData item, Point mousePos, TreeMapLayout layout)
{
var rect = layout.Get(item);
if (rect == null)
{
return null;
}
// We may find a more detailed hit deeper.
IHierarchicalData? best = null;
if (rect.IsHit(mousePos))
{
best = item;
if (item.IsLeafNode)
{
return item;
}
}
foreach (var child in item.Children)
{
if (layout.Get(child)?.IsHit(mousePos) == true)
{
return Hit(child, mousePos, layout);
}
}
return best;
}
}
}