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

Snapping support (via new View > Snap menu) #554

Merged
merged 15 commits into from
Apr 19, 2024
Merged

Conversation

tannerhelland
Copy link
Owner

Relates to #498, #539, #532, possibly others. Thank you to everyone who suggested this feature.

PhotoDemon can now automagically "snap" objects to common targets. Which targets are used for snapping can be set in the View > Snap to menu. Current options include canvas bounds, layers, and centerlines (e.g. the center of the document and layers). A master menu item (and associated hotkey) can quickly enable/disable all snapping behavior, if required.

The Tools > Options < Interface panel lets you set snap distance (in screen pixels, not image pixels - same as Photoshop). The current default is 8 screen pixels, which is the same as other photo editors.

Next up: I want to add an option to "view smart guides" (probably named something else in the final build). Photoshop uses this feature to show you which boundary is being snapped, as snapping can become confusing on images with many layers.

A menu is now provided (`View > Snap to canvas edge`), and custom snap distance is changeable via `Tools > Options > Interface`.

A lot of code is required to provide a UI for this feature, since snap settings need to be persistent between sessions, but still easily toggleable in a top-level menu.

Next up: actually implementing the snap feature (sigh).
...when moving a layer.  It works well!

This behavior can be toggled via `View > Snap to canvas edges`.  Minimum snap distance can be set via `Tools > Options > Interface`.

Still TODO:

1) Snapping when resizing (not moving) a layer
2) Anything involving selection tools

Relates to #498.
Snap-to-canvas-edge now works on all four layer corners when resizing via the move tool.

Importantly, snapping also works when the layer has non-destructive rotation or skew applied!

Relates to #498
Relates to #498

The `View` menu now provides a top-level `Snap` setting that lets the user toggle snapping completely on or completely off (without losing individual snap-to settings).

This matches Photoshop's behavior and is mapped to the same hotkey, `Ctrl+Shift+;`.
...when moving.

Layers with affine transforms are now snapped correctly!
Details in code comments; basically, this improves a rare edge-case where PSDs with many small 24-bit layers display unreliable transparency-around-each-layer behavior in Photoshop.
Rectangle, ellipse, and polygon selections now snap when moving individual points, specifically.  Snap when moving an entire selection is still TODO!

(Snap is not currently planned for lasso or magic wand selections.  For the lasso tool, I hope to add a magnetic lasso someday...)
...rectangular or elliptical selections.

Polygons are TODO next!
These will allow auto-snapping to centers of objects (and the document) and boundaries of other layers
For layers *and* selections!  This makes it trivial to snap a smaller layer to the center of the canvas (on either an edge of the smaller layer, or the center of the smaller layer).

In a rare bit of good engineering, I can add arbitrary snap targets whenever I want (e.g. next up: layer boundaries), and all objects automagically pick up the "snap" ability for those new targets.  No snap engine modifications are required when new snap targets get added.
Time to generate some localizations and get this feature merged!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] - Better Snap Points and Geometric analysis possible?
1 participant