2626
2727using System . Collections . Generic ;
2828using System . Linq ;
29- using Gtk ;
3029using Pinta . Core ;
3130
3231namespace Pinta . Gui . Widgets ;
3332
34- public sealed class PintaCanvas : DrawingArea
33+ public sealed class PintaCanvas : Gtk . DrawingArea
3534{
3635 private readonly CanvasRenderer cr ;
3736 private readonly Document document ;
@@ -40,8 +39,19 @@ public sealed class PintaCanvas : DrawingArea
4039
4140 public CanvasWindow CanvasWindow { get ; }
4241
43- public PintaCanvas ( CanvasWindow window , Document document , ICanvasGridService canvasGrid )
42+ private readonly ToolManager tools ;
43+
44+ public PintaCanvas (
45+ ActionManager actions ,
46+ ChromeManager chrome ,
47+ ToolManager tools ,
48+ WorkspaceManager workspace ,
49+ CanvasWindow window ,
50+ Document document ,
51+ ICanvasGridService canvasGrid )
4452 {
53+ this . tools = tools ;
54+
4555 CanvasWindow = window ;
4656 this . document = document ;
4757
@@ -84,60 +94,63 @@ public PintaCanvas (CanvasWindow window, Document document, ICanvasGridService c
8494 // if this click is on a canvas that isn't currently the ActiveDocument yet,
8595 // we need to go ahead and make it the active document for the tools
8696 // to use it, even though right after this the tab system would have switched it
87- if ( PintaCore . Workspace . ActiveDocument != document )
88- PintaCore . Actions . Window . SetActiveDocument ( document ) ;
97+ if ( workspace . ActiveDocument != document )
98+ actions . Window . SetActiveDocument ( document ) ;
8999
90- var window_point = new PointD ( args . X , args . Y ) ;
91- var canvas_point = document . Workspace . ViewPointToCanvas ( window_point ) ;
100+ PointD window_point = new ( args . X , args . Y ) ;
101+ PointD canvas_point = document . Workspace . ViewPointToCanvas ( window_point ) ;
92102
93- var tool_args = new ToolMouseEventArgs {
103+ ToolMouseEventArgs tool_args = new ( ) {
94104 State = click_controller . GetCurrentEventState ( ) ,
95105 MouseButton = click_controller . GetCurrentMouseButton ( ) ,
96106 PointDouble = canvas_point ,
97107 WindowPoint = window_point ,
98108 RootPoint = CanvasWindow . WindowMousePosition ,
99109 } ;
100110
101- PintaCore . Tools . DoMouseDown ( document , tool_args ) ;
111+ tools . DoMouseDown ( document , tool_args ) ;
102112 } ;
103113
104114 click_controller . OnReleased += ( _ , args ) => {
105- var window_point = new PointD ( args . X , args . Y ) ;
106- var canvas_point = document . Workspace . ViewPointToCanvas ( window_point ) ;
107115
108- var tool_args = new ToolMouseEventArgs {
116+ PointD window_point = new ( args . X , args . Y ) ;
117+ PointD canvas_point = document . Workspace . ViewPointToCanvas ( window_point ) ;
118+
119+ ToolMouseEventArgs tool_args = new ( ) {
109120 State = click_controller . GetCurrentEventState ( ) ,
110121 MouseButton = click_controller . GetCurrentMouseButton ( ) ,
111122 PointDouble = canvas_point ,
112123 WindowPoint = window_point ,
113124 RootPoint = CanvasWindow . WindowMousePosition ,
114125 } ;
115126
116- PintaCore . Tools . DoMouseUp ( document , tool_args ) ;
127+ tools . DoMouseUp ( document , tool_args ) ;
117128 } ;
118129
119130 AddController ( click_controller ) ;
120131
121132 // Give mouse move events to the current tool
122133 var motion_controller = Gtk . EventControllerMotion . New ( ) ;
123134 motion_controller . OnMotion += ( _ , args ) => {
124- var window_point = new PointD ( args . X , args . Y ) ;
125- var canvas_point = document . Workspace . ViewPointToCanvas ( window_point ) ;
135+
136+ PointD window_point = new ( args . X , args . Y ) ;
137+ PointD canvas_point = document . Workspace . ViewPointToCanvas ( window_point ) ;
126138
127139 if ( document . Workspace . PointInCanvas ( canvas_point ) )
128- PintaCore . Chrome . LastCanvasCursorPoint = canvas_point . ToInt ( ) ;
129-
130- if ( PintaCore . Tools . CurrentTool != null ) {
131- var tool_args = new ToolMouseEventArgs {
132- State = motion_controller . GetCurrentEventState ( ) ,
133- MouseButton = MouseButton . None ,
134- PointDouble = canvas_point ,
135- WindowPoint = window_point ,
136- RootPoint = CanvasWindow . WindowMousePosition ,
137- } ;
138-
139- PintaCore . Tools . DoMouseMove ( document , tool_args ) ;
140- }
140+ chrome . LastCanvasCursorPoint = canvas_point . ToInt ( ) ;
141+
142+ if ( tools . CurrentTool == null )
143+ return ;
144+
145+ ToolMouseEventArgs tool_args = new ( ) {
146+ State = motion_controller . GetCurrentEventState ( ) ,
147+ MouseButton = MouseButton . None ,
148+ PointDouble = canvas_point ,
149+ WindowPoint = window_point ,
150+ RootPoint = CanvasWindow . WindowMousePosition ,
151+ } ;
152+
153+ tools . DoMouseMove ( document , tool_args ) ;
141154 } ;
142155
143156 AddController ( motion_controller ) ;
@@ -147,13 +160,17 @@ public PintaCanvas (CanvasWindow window, Document document, ICanvasGridService c
147160
148161 private void Draw ( Cairo . Context context , int width , int height )
149162 {
150- var scale = document . Workspace . Scale ;
163+ double scale = document . Workspace . Scale ;
151164
152- var x = ( int ) document . Workspace . Offset . X ;
153- var y = ( int ) document . Workspace . Offset . Y ;
165+ int x = ( int ) document . Workspace . Offset . X ;
166+ int y = ( int ) document . Workspace . Offset . Y ;
154167
155168 // Translate our expose area for the whole drawingarea to just our canvas
156- var canvas_bounds = new RectangleI ( x , y , document . Workspace . ViewSize . Width , document . Workspace . ViewSize . Height ) ;
169+ RectangleI canvas_bounds = new (
170+ x ,
171+ y ,
172+ document . Workspace . ViewSize . Width ,
173+ document . Workspace . ViewSize . Height ) ;
157174
158175 if ( CairoExtensions . GetClipRectangle ( context , out RectangleI expose_rect ) )
159176 canvas_bounds = canvas_bounds . Intersect ( expose_rect ) ;
@@ -170,7 +187,7 @@ private void Draw (Cairo.Context context, int width, int height)
170187
171188 cr . Initialize ( document . ImageSize , document . Workspace . ViewSize ) ;
172189
173- var g = context ;
190+ Cairo . Context g = context ;
174191
175192 // Draw our canvas drop shadow
176193 g . DrawRectangle ( new RectangleD ( x - 1 , y - 1 , document . Workspace . ViewSize . Width + 2 , document . Workspace . ViewSize . Height + 2 ) , new Cairo . Color ( .5 , .5 , .5 ) , 1 ) ;
@@ -197,16 +214,20 @@ private void Draw (Cairo.Context context, int width, int height)
197214
198215 // Selection outline
199216 if ( document . Selection . Visible ) {
200- var tool_name = PintaCore . Tools . CurrentTool ? . GetType ( ) . Name ?? string . Empty ;
201- var fillSelection = tool_name . Contains ( "Select" ) && ! tool_name . Contains ( "Selected" ) ;
217+ string tool_name = tools . CurrentTool ? . GetType ( ) . Name ?? string . Empty ;
218+ bool fillSelection = tool_name . Contains ( "Select" ) && ! tool_name . Contains ( "Selected" ) ;
202219 document . Selection . Draw ( g , scale , fillSelection ) ;
203220 }
204221
205- if ( PintaCore . Tools . CurrentTool is not null ) {
222+ if ( tools . CurrentTool is not null ) {
223+
206224 g . Save ( ) ;
225+
207226 g . ResetClip ( ) ; // Don't clip the control at the edge of the image.
208227 g . Translate ( - x , - y ) ;
209- DrawHandles ( g , PintaCore . Tools . CurrentTool . Handles ) ;
228+
229+ DrawHandles ( g , tools . CurrentTool . Handles ) ;
230+
210231 g . Restore ( ) ;
211232 }
212233
@@ -217,9 +238,8 @@ private void Draw (Cairo.Context context, int width, int height)
217238
218239 private static void DrawHandles ( Cairo . Context cr , IEnumerable < IToolHandle > controls )
219240 {
220- foreach ( var control in controls . Where ( c => c . Active ) ) {
241+ foreach ( var control in controls . Where ( c => c . Active ) )
221242 control . Draw ( cr ) ;
222- }
223243 }
224244
225245 private void SetRequisition ( Size size )
@@ -230,26 +250,30 @@ private void SetRequisition (Size size)
230250 QueueResize ( ) ;
231251 }
232252
233- public bool DoKeyPressEvent ( Gtk . EventControllerKey controller , Gtk . EventControllerKey . KeyPressedSignalArgs args )
253+ public bool DoKeyPressEvent (
254+ Gtk . EventControllerKey controller ,
255+ Gtk . EventControllerKey . KeyPressedSignalArgs args )
234256 {
235257 // Give the current tool a chance to handle the key press
236- var tool_args = new ToolKeyEventArgs {
258+ ToolKeyEventArgs tool_args = new ( ) {
237259 Event = controller . GetCurrentEvent ( ) ,
238260 Key = args . GetKey ( ) ,
239261 State = args . State ,
240262 } ;
241263
242- return PintaCore . Tools . DoKeyDown ( document , tool_args ) ;
264+ return tools . DoKeyDown ( document , tool_args ) ;
243265 }
244266
245- public bool DoKeyReleaseEvent ( Gtk . EventControllerKey controller , Gtk . EventControllerKey . KeyReleasedSignalArgs args )
267+ public bool DoKeyReleaseEvent (
268+ Gtk . EventControllerKey controller ,
269+ Gtk . EventControllerKey . KeyReleasedSignalArgs args )
246270 {
247- var tool_args = new ToolKeyEventArgs {
271+ ToolKeyEventArgs tool_args = new ( ) {
248272 Event = controller . GetCurrentEvent ( ) ,
249273 Key = args . GetKey ( ) ,
250274 State = args . State ,
251275 } ;
252276
253- return PintaCore . Tools . DoKeyUp ( document , tool_args ) ;
277+ return tools . DoKeyUp ( document , tool_args ) ;
254278 }
255279}
0 commit comments