VisualData.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Windows; 7 using System.Windows.Input; 8 using System.Windows.Media; 9 using System.Windows.Shapes; 10 11 namespace FancyZone_HitTest 12 { 13 public class VisualData 14 { 15 public Point RelativeMouseLocation { get; set; } 16 17 public Point CenterMass { get; set; } 18 19 public Point TopLeft { get; set; } 20 21 public double MouseDistanceFromCenter { get; set; } 22 23 public int Area { get; set; } 24 25 public string Name { get; set; } 26 27 public double DistanceFromEdge { get; set; } 28 29 public double DistanceFromEdgePercentage { get; set; } 30 31 public VisualData(Shape item, MouseEventArgs e, Visual root) 32 { 33 Name = item.Name; 34 35 int width = (int)Math.Floor(item.ActualWidth); 36 int height = (int)Math.Floor(item.ActualHeight); 37 38 TopLeft = Utilities.GetPosition(item, root); 39 CenterMass = new Point(width / 2, height / 2); 40 Area = width * height; 41 RelativeMouseLocation = e.GetPosition(item); 42 MouseDistanceFromCenter = Point.Subtract(RelativeMouseLocation, CenterMass).Length; 43 44 var mouseX = Math.Floor(RelativeMouseLocation.X); 45 var mouseY = Math.Floor(RelativeMouseLocation.Y); 46 47 var horDist = (RelativeMouseLocation.X < CenterMass.X) ? RelativeMouseLocation.X : width - mouseX; 48 var vertDist = (RelativeMouseLocation.Y < CenterMass.Y) ? RelativeMouseLocation.Y : height - mouseY; 49 50 var isHorCalc = horDist < vertDist; 51 DistanceFromEdge = Math.Floor(isHorCalc ? horDist : vertDist); 52 53 if (isHorCalc) 54 { 55 DistanceFromEdgePercentage = (width - DistanceFromEdge) / width; 56 } 57 else 58 { 59 DistanceFromEdgePercentage = (height - DistanceFromEdge) / height; 60 } 61 } 62 } 63 }