Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jumpy token dragging and resizing #4946

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Sep 26, 2024

Identify the Bug or Feature request

Fixes #4855
Fixes #4365
Fixes #4844

Description of the Change

This fixes the jumps that happens when dragging tokens and resizing stamps in different situations.

Drag fixes. The key difference in dragging is that the drag is measured as displacement of the starting drag anchor (formerly called "drag offset" in code). This keeps things consistent whether snap-while-drag is enabled, whether the token is snap-to-grid, and regardless of the layout and rotation of the token. SelectionSet is also changed to accept points rather than working with offsets, since offsets require too much knowledge about the token layout to be very useful in that context. The drag anchor calculation had to be tweaked to properly account for the token layout.

Resize fixes. There were a few issues with resizing, including an incorrect calculation of the new dimensions for snap-to-grid stamps and incorrectly accounting for the token layout. It also lacked the ability to preserve the aspect ratio if the token was at all rotated. These have all been fixed by projecting the resize drag information into the token's rotated reference frame. A nice perk is that the logic is simpler while doing more, since it boils down to a couple key vector operations.

Both StampTool and PointerTool were refactored to encapsulate the drag and resize operations into inner classes (TokenDragOp, TokenResizeOp) so that extra state could conveniently be kept around. New debug rendering was also added to diagnose issues with dragging, and a new developer option was added to enable it.

Possible Drawbacks

None

Documentation Notes

N/A

Release Notes

  • Fixed a bug where tokens would jump a bit when starting to drag them if the Snap Token while dragging preference is enabled.
  • Fixed a bug where free-size snap-to-grid stamps would be resized to larger than they should be.

This change is Reviewable

Dragging operations are now encapsulated into special inner classes (`StampTool.TokenDragOp` and
`PointerTool.TokenDragOp`) which track all the stack needed for a drag operation. These classes also give a convenient
place to store some calculations that are necessary for dragging to work properly with modified token layouts.

The key difference in dragging now vs before is that a drag is a displacement from a starting `ZonePoint` to a
destination `ZonePoint`, which reflects the motion of the cursor. This displacement is then applied to the token's drag
anchor (formerly called drag offset) to decide where to move the token. Snap-to-grid is applied at the end of the drag
if needed. This enables smooth dragging to work without "hiccups", and allows the same for snap dragging when the token
layout has been shifted.

`SelectionSet` has been modified to accept the final point, rather than trying to work with offsets. The offset approach
pretty well required every component to keep track of which token is moving from where in order to figure out the same
thing: where should it end up. Now the caller can just say where the token should end up.

Similar to token dragging, the free resize of stamps had a similar "hiccup" bug that has been fixed. Resizes are now
encapsulated in `StampTool.TokenResizeOp` and works correctly whether or not the token is snap-to-grid, allows for
aspect ratio to be preserved for rotated tokens, and respects token layout.

To help with diagnosing issues during drags, new debug rendering was added to `PointerTool` and `StampTool` with a new
developer option to enable it.
@kwvanderlinde kwvanderlinde self-assigned this Sep 26, 2024
@kwvanderlinde kwvanderlinde marked this pull request as ready for review September 26, 2024 04:48
@cwisniew cwisniew merged commit d9647f1 into RPTools:develop Sep 26, 2024
4 checks passed
@kwvanderlinde kwvanderlinde deleted the bugfix/smooth-dragging branch September 26, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment