1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47:35 +00:00

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.
This commit is contained in:
Mustafa Quraish 2021-09-12 22:15:26 -04:00 committed by Andreas Kling
parent c5b14fce54
commit c0373c3119
2 changed files with 10 additions and 1 deletions

View file

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

View file

@ -29,6 +29,7 @@ private:
RefPtr<GUI::Widget> 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 };