letsfindaway / OpenBoard

I'm using this fork to contribute features and fixes to the upstream project. In order to create good pull requests, I'm rebasing my feature branches, squashing and reordering commits, etc. If you fork this repository be aware that my development branches may rewrite history without prior notice.
http://openboard.ch/
GNU General Public License v3.0
9 stars 0 forks source link

[Feature Request] Snap to grid #170

Closed letsfindaway closed 2 months ago

letsfindaway commented 8 months ago

Is your feature request related to a problem? Please describe.

When using a background grid it is often desirable to have items aligned to the grid: lines, the center and tip of the compass, axes, text etc. OTOH people also want those things without alignment, see e.g. #145.

Describe the solution you'd like

Users should be able to choose between aligned and unaligned positioning. I propose using a modifier key (preferred: Shift) to switch between aligned and unaligned positioning: Without the key, the items are not aligned. When this key is pressed while releasing the mouse button, alignment is enforced.

Snapping should be "live" while moving the mouse, so that the user sees the effect while positioning, just as it is for the "angle grip" function when drawing a line. It should not be as in the current Axes tool, where the effect is only visible after releasing the mouse.

Describe alternatives you've considered

There could be a dedicated button at the delegate for specific tools which switches between "magnetic" and normal mode.

Additional context

The solution should also work with the new configurable background grid #151. This means that the magnetic points have to be computed by the grid. I propose that each line of the grid has some magnetism. At a crossing, it doubles. This allows even an isometric grid to be magnetic in the way the user expects. There should be a configuration variable for the magnetic force.

The force should be a function of distance (in view coordinates) and vanish at some threshold distance. This would even allow a natural behavior at the millimeter grid. Taking this as an example we could even try to make the force depending on the width and alpha color value of the line.

As the proposed implementation depends on the configurable background it has to be implemented after or together with this feature. The UBBackgroundManager would get a new function

QPointF snap(const QPointF& point, double* force = nullptr) const;

computing the snap position and optionally returning the snap force. Argument and return value are in scene coordinates. Each object has to decide how to use this function. So snapping an image (all four corners?) could behave differently from snapping a line (line end points).

letsfindaway commented 8 months ago

Additional idea

This could even enhance the "grip" function from UBGraphicsScene, which helps aligning a line with angles of 0°, 45°, 90° etc. My proposal would be to extend the background grid specification by a set of snapping angles. Isometric grid could e.g. choose 30° and 60° and omit 45°.

The grip function should also only be active while the modifier key is pressed. Users have complained that they cannot draw "near horizontal" lines.

letsfindaway commented 5 months ago

The UBBackgroundManager::snap() function mentioned above for the flexible background could also be implemented in the UBGraphicsScene, which delegates it further to the UBBackgroundManager. This would allow to adapt all tools already before the flexible background is merged. The scene has all information necessary to perform this function and is easily accessible from each tool.

letsfindaway commented 5 months ago

Note: this comment is obsolete and will be updated later.

Now back from implementation to the user perspective.

Snapping behavior

Tool Draw Move Resize Rotate
Pen - - - -
Line Start/end at grid = = N/A
Ruler - Top 0 at grid - -
Protractor - 0 at grid - -
Triangle - 0 at grid - -
Compass - center at grid pen at grid -
Axes - 0/0 at grid - N/A
Objects - top/left at grid Each corner at grid Resized side at grid Snap to angle (15° steps)

Note that you cannot snap tools and objects during creation, because the shift key is interpreted at the drag source, which cannot be influenced by the drop target. And it is not a good option to tell the user to press the shift key only shortly before releasing the mouse key.

Line tool

For the line tool, we have some more special effects:

letsfindaway commented 5 months ago

TODOs

letsfindaway commented 5 months ago

Questions

letsfindaway commented 2 months ago

Discussion moved to PR, closing this one here.