2525// THE SOFTWARE.
2626
2727using System ;
28+ using System . Linq ;
2829using Pinta . Core ;
2930using Pinta . Gui . Widgets ;
3031
@@ -39,6 +40,8 @@ public sealed class CanvasWindow : Gtk.Grid
3940 private readonly Ruler horizontal_ruler ;
4041 private readonly Ruler vertical_ruler ;
4142 private readonly Gtk . ScrolledWindow scrolled_window ;
43+ private readonly Gtk . Widget ? horizontal_scrollbar ;
44+ private readonly Gtk . Widget ? vertical_scrollbar ;
4245 private readonly Gtk . EventControllerMotion motion_controller ;
4346 private readonly Gtk . GestureDrag drag_controller ;
4447 private readonly Gtk . GestureZoom gesture_zoom ;
@@ -143,6 +146,8 @@ public CanvasWindow (
143146 vertical_ruler = verticalRuler ;
144147 motion_controller = motionController ;
145148 drag_controller = dragController ;
149+ horizontal_scrollbar = scrolledWindow . GetHscrollbar ( ) ;
150+ vertical_scrollbar = scrolledWindow . GetVscrollbar ( ) ;
146151
147152 // --- Further initialization
148153
@@ -190,6 +195,7 @@ private void HandleMotion (
190195 current_canvas_pos = document . Workspace . ViewPointToCanvas ( viewPos ) ;
191196 horizontal_ruler . Position = current_canvas_pos . X ;
192197 vertical_ruler . Position = current_canvas_pos . Y ;
198+ UpdateScrollbarTargeting ( viewPos ) ;
193199
194200 // Forward mouse move events to the current tool when not dragging.
195201 if ( drag_controller . GetStartPoint ( out _ , out _ ) )
@@ -440,4 +446,16 @@ public bool DoKeyReleaseEvent (
440446
441447 return tools . DoKeyUp ( document , tool_args ) ;
442448 }
449+
450+ private void UpdateScrollbarTargeting ( PointD ? viewPos = null )
451+ {
452+ bool canTarget = viewPos is null
453+ || tools . CurrentTool ? . Handles . Any ( h => h . Active && h . ContainsPoint ( viewPos . Value ) ) != true ;
454+
455+ if ( horizontal_scrollbar is not null )
456+ horizontal_scrollbar . CanTarget = canTarget ;
457+
458+ if ( vertical_scrollbar is not null )
459+ vertical_scrollbar . CanTarget = canTarget ;
460+ }
443461}
0 commit comments