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 :^)
This commit is contained in:
Mustafa Quraish 2021-09-07 21:29:32 -04:00 committed by Andreas Kling
parent a0ac5c5fc2
commit 30df74b015
2 changed files with 10 additions and 0 deletions

View file

@ -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)

View file

@ -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);