Adding Toggles
This week started with me trying to add alignment snapping toggles to Inkscape. This took some time as at first I could not figure out how Gio::Actions are set up but finally by following how other toggles were implemented I was able to get this to work.
In the present state of the MR the following toggles exist:
-
Toggle Alignment Snapping option in Snap Controllers Toolbar
- Toggle snapping to other nodes in the same path while editing paths as a sub-option
- Snapping to page corners and midpoint if Toggle Snapping to Page Border option is enabled
Icons for these still need to be designed.
Bug Fixes
Last week there was a bug where the nodes of the object being transformed were
also being snapped. This was an easy fix by just passing the Bounding Box points
as Snap Source points in Seltrans
and adding some toggle checks.
Snap Priority
It is highly probable that when we look for potential snap positions, an alignment
snap positon is the closest. This can be annoying when you are trying to snap to
other locations (a corner for example). To fix this I modified the SnappedPoint::findBestSnap()
function to give priority to all other snap locations over Alignment Snap positions.
Viewport
While aligment snapping, looking for all the items in the document can be resource intensive. Hence its makes sense to only look for items that are currently visible in the viewport. This reduces the number of points we need to check and also enhances the UX as you will no longer snap to an object you can not see in the viewport.
Constraints
Constraint movements are pretty useful and Alignment Snapping now takes them into
account. While Ctrl
is pressed the object only moves in either Horizontal or
Vertical direction. If the object is being moved in the Y direction, it will not
snap to alignment guides that are vertical. Similarly if it is being moved in X
direction, it will not snap to Horizontal guides.
Horizontal and Vertical Lines
Objects will now snap to points of intersection of two alignment guides. Hence you can now simultaneously align objects vertically and horizontally with respect to two neighbouring objects.
Snap Indicators
With the work of actually finding and snapping to alignment locations almost done,
this week I also started looking into the implementation of SnapIndicator
class.
The behaviour of Alignment Snap Indicators is very different from that of the
conventional Snap Indicators in Inkscape, in that the alignment indicators disappear
when an object is ungrabbed and opposed to other snap indicators that have a set
lifetime.
Next Up
Next week I will look into better understanding how canvas works in Inkscape and try to figure out a nice way to display the Alignment Indicators that behave as described above.