mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-19 09:17:38 +03:00
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:
parent
a0ac5c5fc2
commit
30df74b015
Notes:
sideshowbarker
2024-07-18 04:23:10 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/30df74b015c Pull-request: https://github.com/SerenityOS/serenity/pull/9887 Reviewed-by: https://github.com/danielledeleo
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user