diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2021-09-07 21:29:32 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-09 11:35:50 +0200 |
commit | 30df74b015c1f8cd8904730eaa98014146b80ae2 (patch) | |
tree | be6bfa9a438b9290bc143d1be9255fe0bf7bf8d7 /Userland | |
parent | a0ac5c5fc22399dcb7614f0a485d42fca35ede0d (diff) | |
download | serenity-30df74b015c1f8cd8904730eaa98014146b80ae2.zip |
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 :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/PixelPaint/BrushTool.cpp | 9 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/BrushTool.h | 1 |
2 files changed, 10 insertions, 0 deletions
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); |