OpenBoard-org / OpenBoard

OpenBoard is a cross-platform interactive whiteboard application intended for use in a classroom setting.
https://openboard.ch/
GNU General Public License v3.0
2.24k stars 412 forks source link

Feat: snap to grid #1013

Open letsfindaway opened 1 week ago

letsfindaway commented 1 week ago

This pull request adds a snap-to-grid function when drawing lines and moving tools or objects and resizing objects. In detail it provides the following functions:

With the Shift key pressed, some points snap to the grid as follows:

The individual tools and objects behave as follows when the Shift key is pressed and the tool or object is moved:

The individual tools and objects behave as follows when the Shift key is pressed and the tool or object is resized:

When an object is in a rotated state, then the corners of the bounding rectangle of the rotated object define the points to snap.

For a Line, the snap points are not determined by the outline of the line, but by the actual line start and end points inside the outline. This works however only if the line is moved or resized in the same session where it was created. After a document was serialized and loaded again, the line property is lost and the line is handled like any other arbitrary drawing.

The implementation of the snap function is as follows:

When at some later time the flexible background definitions are implemented (PR #888), then only the single UBGraphicsScene::snap() function must be adapted. All the other logic is not affected.

This PR is related to the following issues: