Skip to content

Fix canvas cursor offset and tool misalignment (#2165) - #2390

Open
Vikyek wants to merge 1 commit into
PintaProject:masterfrom
Vikyek:fix/canvas-viewport-offset
Open

Vikyek wants to merge 1 commit into
PintaProject:masterfrom
Vikyek:fix/canvas-viewport-offset

Conversation

@Vikyek

@Vikyek Vikyek commented Nov 14, 2026

Copy link
Copy Markdown

Description of Changes

Fixes #2165 (regression introduced in fa6482f / PR #1929).

Root Cause

In PR #1929 (fa6482f0), the gesture drag and motion controllers were moved from Canvas to CanvasWindow (the parent Gtk.Grid) to receive drags starting outside the canvas, with coordinates translated via this.TranslateCoordinates (Canvas, rootPoint, out PointD viewPoint).

In GTK4, translating coordinates through intermediate container widgets (Gtk.ScrolledWindow / Gtk.Viewport) does not account for GtkViewport scroll adjustments or the centering margins (Halign / Valign = Center). When the window is unmaximized, resized, or scrolled, the translated coordinate drifts from the pointer position, causing tools to draw and interact with a significant offset from the cursor.

Solution

  • Attach dragController and motionController directly to canvas (PintaCanvas).
  • Because events are now handled directly on the canvas widget, event coordinates are already in canvas/widget space.
  • Remove intermediate TranslateCoordinates calls and pass rootPoint directly as viewPoint.

Testing & Verification

  • dotnet build: Built 14 projects with 0 errors and 0 warnings.
  • dotnet test: 901/901 unit tests passing across Pinta.Core.Tests (780 passed, 1 skipped) and Pinta.Effects.Tests (121 passed, 1 skipped).
  • Verified interactively on Arch Linux / Hyprland (Wayland):
    • Maximized, restored/unmaximized, and dynamically resized window.
    • Tested drawing with Pencil, Paintbrush, Eraser, Rectangle, and Selection tools.
    • Verified scrolling and zooming with rulers and pointer alignment matching precisely across canvas coordinates.

Checklist

…t#2165)

Fix cursor position and tool activation misalignment that occurs when
the canvas window is unmaximized, resized, or scrolled.

- Previously in fa6482f (PR PintaProject#1929), drag and motion controllers were
  moved to CanvasWindow to capture drags beginning outside the canvas.
- In GTK4, TranslateCoordinates through Gtk.ScrolledWindow / Gtk.Viewport
  does not account for GtkViewport scroll adjustments and Halign/Valign
  Center margins, causing coordinates to drift away from the actual cursor.
- Attach GestureDrag and EventControllerMotion directly to the canvas
  widget so events deliver native canvas-space coordinates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tools activate in the wrong cursor position if window is not maximized

1 participant