3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
7 using System.Threading.Tasks;
15 private const double PenThickness = 1.0;
16 private const double BoldPenThickness = 2.0;
17 private const double CircleRadius = 4.0;
18 private const double CircleRadiusSquared = CircleRadius * CircleRadius;
20 private Pen pen =
new Pen(Brushes.Blue, PenThickness);
21 private Pen boldPen =
new Pen(Brushes.Blue, BoldPenThickness);
23 private ReadOnlyCollection<Lane> lanes;
24 internal ReadOnlyCollection<Lane> Lanes {
set { lanes = value; } }
26 private Lane laneWithNearestStartPointToCursor = null;
34 protected override void Render(Point currentMouseLocation)
36 RenderPossibleLocations(currentMouseLocation);
39 internal void MouseMove(Point currentMouseLocation)
41 Render(currentMouseLocation);
44 internal Lane MouseLeftButtonUp()
46 if (laneWithNearestStartPointToCursor == null)
52 Lane laneWithNearestStartPointToCursorToReturn = laneWithNearestStartPointToCursor;
53 return laneWithNearestStartPointToCursorToReturn;
59 laneWithNearestStartPointToCursor = null;
60 using (DrawingContext dc = visual.RenderOpen())
66 internal void RenderPossibleLocations(Point? currentMouseLocation = null)
68 using (DrawingContext dc = visual.RenderOpen())
70 dynamic laneWithNearestStartPointToCursor = null;
71 foreach (
Lane lane
in lanes)
75 Point startPointOnCanvas = TransformRealWorldPoint(lane.
StartNode.Location);
76 dc.DrawEllipse(null, pen, startPointOnCanvas, CircleRadius, CircleRadius);
78 if (currentMouseLocation.HasValue)
80 double distanceFromStartPointToCursorSquared =
81 (startPointOnCanvas - currentMouseLocation.Value).LengthSquared;
83 if (distanceFromStartPointToCursorSquared < CircleRadiusSquared &&
84 (laneWithNearestStartPointToCursor == null ||
85 distanceFromStartPointToCursorSquared <
86 laneWithNearestStartPointToCursor.DistanceToStartPointSquared))
88 laneWithNearestStartPointToCursor =
new 91 DistanceToStartPointSquared = distanceFromStartPointToCursorSquared
97 if (laneWithNearestStartPointToCursor != null)
99 dc.DrawEllipse(null, boldPen,
100 TransformRealWorldPoint(laneWithNearestStartPointToCursor.
Lane.StartNode.Location),
101 CircleRadius, CircleRadius);
102 this.laneWithNearestStartPointToCursor = laneWithNearestStartPointToCursor.
Lane;
override void Render(Point currentMouseLocation)
Method defining render method to be implemented for all renderers. Current mouse location
Base class for drawing visual renderer.
StartNode StartNode
Node on the input end of lane.
Lane(Point startPoint, Point endPoint)
Lane constructor.