Skip to content

Commit 98a293f

Browse files
committed
Fix overlay scrollbar intercepting clicks on selection handles at image edges (#2200)
1 parent c15162a commit 98a293f

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

Pinta.Core/Classes/IToolHandle.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public interface IToolHandle
1414
/// </summary>
1515
public bool Active { get; }
1616

17+
/// <summary>
18+
/// Tests whether the window point is inside the handle's area.
19+
/// </summary>
20+
public bool ContainsPoint (PointD windowPoint);
21+
1722
/// <summary>
1823
/// Draw the handle onto the canvas widget.
1924
/// This is in window space, so CanvasPointToWindow() should be used to transform a canvas position

Pinta.Gui.Widgets/Widgets/Canvas/CanvasWindow.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// THE SOFTWARE.
2626

2727
using System;
28+
using System.Linq;
2829
using Pinta.Core;
2930
using 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
}

Pinta.Tools/Handles/LineHandle.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public LineHandle (IWorkspaceService workspace)
3232
handles = [new MoveHandle (workspace), new MoveHandle (workspace)];
3333
}
3434

35+
public bool ContainsPoint (PointD windowPoint)
36+
=> handles.Any (c => c.ContainsPoint (windowPoint));
37+
3538
public void Draw (Snapshot snapshot)
3639
{
3740
foreach (MoveHandle handle in handles) {

Pinta.Tools/Handles/RectangleHandle.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public RectangleHandle (IWorkspaceService workspace)
5454
#region IToolHandle Implementation
5555
public bool Active { get; set; }
5656

57+
public bool ContainsPoint (PointD windowPoint)
58+
=> handles.Values.Any (c => c.ContainsPoint (windowPoint));
59+
5760
public void Draw (Gtk.Snapshot snapshot)
5861
{
5962
foreach (MoveHandle handle in handles.Values)

0 commit comments

Comments
 (0)