From 30df74b015c1f8cd8904730eaa98014146b80ae2 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Tue, 7 Sep 2021 21:29:32 -0400 Subject: PixelPaint: Allow drawing line between 2 points with BrushTool Sometimes you want to draw a straight line between 2 points, but using the nice-looking brush we have instead of the hard line we would get using the LineTool. This patch adds the ability to click somewhere with the brush, and then Shift+click somewhere else to draw a line between the two points using the brush stroke. Seems like an obvious addition considering we already have a helper function to draw lines :^) --- Userland/Applications/PixelPaint/BrushTool.cpp | 9 +++++++++ Userland/Applications/PixelPaint/BrushTool.h | 1 + 2 files changed, 10 insertions(+) (limited to 'Userland') diff --git a/Userland/Applications/PixelPaint/BrushTool.cpp b/Userland/Applications/PixelPaint/BrushTool.cpp index 5eb63bf338..7591506521 100644 --- a/Userland/Applications/PixelPaint/BrushTool.cpp +++ b/Userland/Applications/PixelPaint/BrushTool.cpp @@ -34,6 +34,14 @@ void BrushTool::on_mousedown(Layer* layer, MouseEvent& event) if (layer_event.button() != GUI::MouseButton::Left && layer_event.button() != GUI::MouseButton::Right) return; + if (layer_event.shift() && m_has_clicked) { + draw_line(layer->bitmap(), m_editor->color_for(layer_event), m_last_position, layer_event.position()); + auto modified_rect = Gfx::IntRect::from_two_points(m_last_position, layer_event.position()).inflated(m_size * 2, m_size * 2); + layer->did_modify_bitmap(modified_rect); + m_last_position = layer_event.position(); + return; + } + const int first_draw_opacity = 10; for (int i = 0; i < first_draw_opacity; ++i) @@ -41,6 +49,7 @@ void BrushTool::on_mousedown(Layer* layer, MouseEvent& event) layer->did_modify_bitmap(Gfx::IntRect::centered_on(layer_event.position(), Gfx::IntSize { m_size * 2, m_size * 2 })); m_last_position = layer_event.position(); + m_has_clicked = true; } void BrushTool::on_mousemove(Layer* layer, MouseEvent& event) diff --git a/Userland/Applications/PixelPaint/BrushTool.h b/Userland/Applications/PixelPaint/BrushTool.h index 943988afff..0964d0d17e 100644 --- a/Userland/Applications/PixelPaint/BrushTool.h +++ b/Userland/Applications/PixelPaint/BrushTool.h @@ -26,6 +26,7 @@ private: int m_size { 20 }; int m_hardness { 80 }; bool m_was_drawing { false }; + bool m_has_clicked { false }; Gfx::IntPoint m_last_position; void draw_line(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& start, Gfx::IntPoint const& end); -- cgit v1.2.3