From c0373c3119aec5372bde632cda89e4cd3e944166 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sun, 12 Sep 2021 22:15:26 -0400 Subject: 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. --- Userland/Applications/PixelPaint/LineTool.cpp | 10 +++++++++- Userland/Applications/PixelPaint/LineTool.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) 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 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 }; -- cgit v1.2.3