pencil2d / pencil

Pencil2D is an easy, intuitive tool to make 2D hand-drawn animations. Pencil2D is open source and cross-platform.
http://pencil2d.org
GNU General Public License v2.0
1.47k stars 273 forks source link

Canvas Cursor changes visual size when view is rotated #1868

Closed HeCorr closed 3 months ago

HeCorr commented 3 months ago

Issue Summary

When the canvas is rotated, the Canvas Cursor (the circle) of drawing tools appears to be larger than it should be, peaking at 45° increments (45°, 135°, 225°, 315°).

The actual drawing width is not affected.

### Expected Results I expected the Canvas Cursor to stay the same size at any rotation angle. ### Video or Image Reference https://github.com/user-attachments/assets/b90664d3-8418-46ca-9275-728923659d7f ### Steps to reproduce 1. Launch Pencil2D 2. Select the Brush tool 3. Set it's Width to 50 and Feather to 1 4. Rest your cursor over the canvas 5. Press the `Rotate Clockwise` shortcut key repeatedly ### System Information + Pencil2D Version: `Nightly Build Jun 17 2024` + Operating System: `Windows 10` + RAM Size: `64 GB`
HeCorr commented 3 months ago

After some quick debugging it seems that updateRect ends up having a size of 72x72 when the view is at 45° and 50x50 (the brush width) at 0° and 100% zoom.

Unfortunately I'm not very familiar with that part of the code so I don't think I can fix this one.

HeCorr commented 3 months ago

scribblemaniac looked into this and it seems the issue is caused by this call to viewTransform.mapRect() in CanvasCursorPainter::preparePainter():

When you map a rect with a transform that contains a rotation, it will return the minimum bounding box that contains the rotated rectangle, which is larger than the original rectangle. Here's the first result in an image search that demonstrates what's happening. If the red rectangle is the original bounds of the brush cursor when rotated, the black rectangle is the result of mapRect:

image