diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2021-09-12 22:15:26 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-13 13:43:53 +0200 |
commit | c0373c3119aec5372bde632cda89e4cd3e944166 (patch) | |
tree | 68b4fd9ed4f21d105d23243bc1f634850741c3c0 | |
parent | c5b14fce54fba549fd70f6b591f1222b9e699660 (diff) | |
download | serenity-c0373c3119aec5372bde632cda89e4cd3e944166.zip |
PixelPaint: Allowing drawing line from center, like other shapes
You could draw a Rectangle/Ellipse from the center by pressing down
the Alt key, but this was missing for lines. This commit adds it in
to keep consistency among the different shapes.
-rw-r--r-- | Userland/Applications/PixelPaint/LineTool.cpp | 10 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/LineTool.h | 1 |
2 files changed, 10 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/LineTool.cpp b/Userland/Applications/PixelPaint/LineTool.cpp index e73b5b2091..db673e0580 100644 --- a/Userland/Applications/PixelPaint/LineTool.cpp +++ b/Userland/Applications/PixelPaint/LineTool.cpp @@ -53,6 +53,7 @@ void LineTool::on_mousedown(Layer* layer, MouseEvent& event) m_drawing_button = layer_event.button(); + m_drag_start_position = layer_event.position(); m_line_start_position = layer_event.position(); m_line_end_position = layer_event.position(); @@ -85,10 +86,17 @@ void LineTool::on_mousemove(Layer* layer, MouseEvent& event) if (layer_event.shift()) { constexpr auto ANGLE_STEP = M_PI / 8; - m_line_end_position = constrain_line_angle(m_line_start_position, layer_event.position(), ANGLE_STEP); + m_line_end_position = constrain_line_angle(m_drag_start_position, layer_event.position(), ANGLE_STEP); } else { m_line_end_position = layer_event.position(); } + + if (layer_event.alt()) { + m_line_start_position = m_drag_start_position + (m_drag_start_position - m_line_end_position); + } else { + m_line_start_position = m_drag_start_position; + } + m_editor->update(); } diff --git a/Userland/Applications/PixelPaint/LineTool.h b/Userland/Applications/PixelPaint/LineTool.h index eafd6d1eca..fc99d07b1b 100644 --- a/Userland/Applications/PixelPaint/LineTool.h +++ b/Userland/Applications/PixelPaint/LineTool.h @@ -29,6 +29,7 @@ private: RefPtr<GUI::Widget> m_properties_widget; GUI::MouseButton m_drawing_button { GUI::MouseButton::None }; + Gfx::IntPoint m_drag_start_position; Gfx::IntPoint m_line_start_position; Gfx::IntPoint m_line_end_position; int m_thickness { 1 }; |