1- using System . Windows ;
21using System . Windows . Controls ;
32using System . Windows . Input ;
43using System . Windows . Media ;
54using System . Windows . Shapes ;
65using Microsoft . Extensions . Logging ;
6+ using Point = System . Windows . Point ;
7+ using Brush = System . Windows . Media . Brush ;
8+ using Brushes = System . Windows . Media . Brushes ;
9+ using Color = System . Windows . Media . Color ;
10+ using ColorConverter = System . Windows . Media . ColorConverter ;
711
812namespace GhostDraw . Tools ;
913
1014/// <summary>
1115/// Straight line drawing tool - click two points to draw a line
1216/// </summary>
13- public class LineTool : IDrawingTool
17+ public class LineTool ( ILogger < LineTool > logger ) : IDrawingTool
1418{
15- private readonly ILogger < LineTool > _logger ;
19+ private readonly ILogger < LineTool > _logger = logger ;
1620 private Line ? _currentLine ;
1721 private Point ? _lineStartPoint ;
1822 private bool _isCreatingLine = false ;
1923 private string _currentColor = "#FF0000" ;
2024 private double _currentThickness = 3.0 ;
2125
22- public LineTool ( ILogger < LineTool > logger )
23- {
24- _logger = logger ;
25- }
26-
2726 public void OnMouseDown ( Point position , Canvas canvas )
2827 {
2928 if ( ! _isCreatingLine )
@@ -61,42 +60,47 @@ public void OnActivated()
6160 public void OnDeactivated ( )
6261 {
6362 _logger . LogDebug ( "Line tool deactivated" ) ;
64- CancelCurrentLine ( ) ;
63+ if ( _currentLine != null )
64+ {
65+ _currentLine = null ;
66+ _lineStartPoint = null ;
67+ _isCreatingLine = false ;
68+ }
6569 }
6670
6771 public void OnColorChanged ( string colorHex )
6872 {
6973 _currentColor = colorHex ;
70-
74+
7175 // Update in-progress line color if one exists
7276 if ( _currentLine != null )
7377 {
7478 _currentLine . Stroke = CreateBrushFromHex ( colorHex ) ;
7579 }
76-
80+
7781 _logger . LogDebug ( "Line color changed to {Color}" , colorHex ) ;
7882 }
7983
8084 public void OnThicknessChanged ( double thickness )
8185 {
8286 _currentThickness = thickness ;
83-
87+
8488 // Update in-progress line thickness if one exists
8589 if ( _currentLine != null )
8690 {
8791 _currentLine . StrokeThickness = thickness ;
8892 }
89-
93+
9094 _logger . LogDebug ( "Line thickness changed to {Thickness}" , thickness ) ;
9195 }
9296
9397 private void StartNewLine ( Point startPoint , Canvas canvas )
9498 {
9599 _lineStartPoint = startPoint ;
96100 _isCreatingLine = true ;
97-
101+
98102 var brush = CreateBrushFromHex ( _currentColor ) ;
99-
103+
100104 _currentLine = new Line
101105 {
102106 X1 = startPoint . X ,
@@ -108,7 +112,7 @@ private void StartNewLine(Point startPoint, Canvas canvas)
108112 StrokeStartLineCap = PenLineCap . Round ,
109113 StrokeEndLineCap = PenLineCap . Round
110114 } ;
111-
115+
112116 canvas . Children . Add ( _currentLine ) ;
113117 _logger . LogInformation ( "Line started at ({X:F0}, {Y:F0})" , startPoint . X , startPoint . Y ) ;
114118 }
@@ -119,17 +123,15 @@ private void FinishLine(Point endPoint)
119123 {
120124 _currentLine . X2 = endPoint . X ;
121125 _currentLine . Y2 = endPoint . Y ;
122-
126+
123127 _logger . LogInformation ( "Line finished at ({X:F0}, {Y:F0})" , endPoint . X , endPoint . Y ) ;
124128 }
125-
129+
126130 _currentLine = null ;
127131 _lineStartPoint = null ;
128132 _isCreatingLine = false ;
129133 }
130134
131-
132-
133135 private Brush CreateBrushFromHex ( string colorHex )
134136 {
135137 try
0 commit comments