mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
PixelPaint: Make the LineTool previews work while zoomed in
This commit is contained in:
parent
53b859c5ad
commit
f57df29724
4 changed files with 31 additions and 15 deletions
|
@ -55,17 +55,19 @@ LineTool::~LineTool()
|
|||
{
|
||||
}
|
||||
|
||||
void LineTool::on_mousedown(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
|
||||
void LineTool::on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent&)
|
||||
{
|
||||
if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right)
|
||||
if (layer_event.button() != GUI::MouseButton::Left && layer_event.button() != GUI::MouseButton::Right)
|
||||
return;
|
||||
|
||||
if (m_drawing_button != GUI::MouseButton::None)
|
||||
return;
|
||||
|
||||
m_drawing_button = event.button();
|
||||
m_line_start_position = event.position();
|
||||
m_line_end_position = event.position();
|
||||
m_drawing_button = layer_event.button();
|
||||
|
||||
m_line_start_position = layer_event.position();
|
||||
m_line_end_position = layer_event.position();
|
||||
|
||||
m_editor->update();
|
||||
}
|
||||
|
||||
|
@ -79,16 +81,16 @@ void LineTool::on_mouseup(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&
|
|||
}
|
||||
}
|
||||
|
||||
void LineTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
|
||||
void LineTool::on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent&)
|
||||
{
|
||||
if (m_drawing_button == GUI::MouseButton::None)
|
||||
return;
|
||||
|
||||
if (!m_constrain_angle) {
|
||||
m_line_end_position = event.position();
|
||||
m_line_end_position = layer_event.position();
|
||||
} else {
|
||||
const float ANGLE_STEP = M_PI / 8.0f;
|
||||
m_line_end_position = constrain_line_angle(m_line_start_position, event.position(), ANGLE_STEP);
|
||||
m_line_end_position = constrain_line_angle(m_line_start_position, layer_event.position(), ANGLE_STEP);
|
||||
}
|
||||
m_editor->update();
|
||||
}
|
||||
|
@ -100,8 +102,9 @@ void LineTool::on_second_paint(const Layer& layer, GUI::PaintEvent& event)
|
|||
|
||||
GUI::Painter painter(*m_editor);
|
||||
painter.add_clip_rect(event.rect());
|
||||
painter.translate(layer.location());
|
||||
painter.draw_line(m_line_start_position, m_line_end_position, m_editor->color_for(m_drawing_button), m_thickness);
|
||||
auto preview_start = m_editor->layer_position_to_editor_position(layer, m_line_start_position).to_int_point();
|
||||
auto preview_end = m_editor->layer_position_to_editor_position(layer, m_line_end_position).to_int_point();
|
||||
painter.draw_line(preview_start, preview_end, m_editor->color_for(m_drawing_button), m_thickness);
|
||||
}
|
||||
|
||||
void LineTool::on_keydown(GUI::KeyEvent& event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue