maoschanz / drawing

Simple image editor for Linux
https://maoschanz.github.io/drawing/
GNU General Public License v3.0
763 stars 98 forks source link

[Line tool] Bind SHIFT and ALT shortcuts at on_motion_on_area() as well #646

Open pedropaulosuzuki opened 1 month ago

pedropaulosuzuki commented 1 month ago

Use case

It makes drawing straight lines quicker and is aligned with the shortcut Inkscape uses, for example. It makes such that one does not need to click the line tool, then go to the line settings and change the toggle every time the user needs to draw a 45deg or 90deg line.

Suggested solution

Bind "CTRL Down" to the behavior "Line options > Line shape > Locked direction > True" and "CTRL Up" to the behavior of "Line options > Line shape > Locked direction > False" when the option is unmarked. (If the option is marked, then maybe invert the previous behavior? Or just do nothing).

Possible drawbacks

One more keybinding in the shortcuts page. Maybe section specific to the line tool? Should more keyboard shortcuts be added at some point in the future?

Possible alternatives

Continue using the settings option every time, which reduces productivity. Binding to other keys: MS Paint also has this feature, but they use SHIFT instead. I'd prefer if the Inkscape shortcut was followed, but I could understand if the community prefers another path.

Thanks everyone and have a good day!

pedropaulosuzuki commented 1 month ago

Found it:

It wasn't clear for me that SHIFT already does this, but only if you press it before drawing. I think a better behavior would be to be able to change it when holding/moving the tool, as it is more flexible.

On tool_line.py:

    def on_press_on_area(self, event, surface, event_x, event_y):
        self.set_common_values(event.button, event_x, event_y)

        self.update_modifier_state(event.state)
        if 'SHIFT' in self._modifier_keys:
            self._ortholock = not self._ortholock
        if 'ALT' in self._modifier_keys:
            self._use_outline = not self._use_outline

    def on_motion_on_area(self, event, surface, event_x, event_y, render=True):
        if not render:
            return
        operation = self.build_operation(event_x, event_y)
        self.do_tool_operation(operation)

    def on_release_on_area(self, event, surface, event_x, event_y):
        operation = self.build_operation(event_x, event_y)
        self.apply_operation(operation)

Then, maybe we could:

  1. Add this shortcut to the "Shortcuts" page.
  2. Allow the modifier state to happen at on_motion_on_area() as well.