mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
PixelPaint: Pass raw mouse event to Tools and wrap them all in a struct
This commit adds a Tool::MouseEvent struct, which contains events that may be needed by tools: layer-relative, image-relative and raw (editor- relative) event. The raw event is used by ZoomTool to properly pan the view. This fixes a bug which caused image to snap out of sight.
This commit is contained in:
parent
635130ef76
commit
0224dc2882
28 changed files with 186 additions and 127 deletions
|
@ -25,35 +25,37 @@ BrushTool::~BrushTool()
|
|||
{
|
||||
}
|
||||
|
||||
void BrushTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&)
|
||||
void BrushTool::on_mousedown(Layer& layer, MouseEvent& event)
|
||||
{
|
||||
if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right)
|
||||
auto& layer_event = event.layer_event();
|
||||
if (layer_event.button() != GUI::MouseButton::Left && layer_event.button() != GUI::MouseButton::Right)
|
||||
return;
|
||||
|
||||
const int first_draw_opacity = 10;
|
||||
|
||||
for (int i = 0; i < first_draw_opacity; ++i)
|
||||
draw_point(layer.bitmap(), m_editor->color_for(event), event.position());
|
||||
draw_point(layer.bitmap(), m_editor->color_for(layer_event), layer_event.position());
|
||||
|
||||
layer.did_modify_bitmap(Gfx::IntRect::centered_on(event.position(), Gfx::IntSize { m_size * 2, m_size * 2 }));
|
||||
m_last_position = event.position();
|
||||
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();
|
||||
}
|
||||
|
||||
void BrushTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&)
|
||||
void BrushTool::on_mousemove(Layer& layer, MouseEvent& event)
|
||||
{
|
||||
if (!(event.buttons() & GUI::MouseButton::Left || event.buttons() & GUI::MouseButton::Right))
|
||||
auto& layer_event = event.layer_event();
|
||||
if (!(layer_event.buttons() & GUI::MouseButton::Left || layer_event.buttons() & GUI::MouseButton::Right))
|
||||
return;
|
||||
|
||||
draw_line(layer.bitmap(), m_editor->color_for(event), m_last_position, event.position());
|
||||
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, event.position()).inflated(m_size * 2, m_size * 2);
|
||||
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 = event.position();
|
||||
m_last_position = layer_event.position();
|
||||
m_was_drawing = true;
|
||||
}
|
||||
|
||||
void BrushTool::on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&)
|
||||
void BrushTool::on_mouseup(Layer&, MouseEvent&)
|
||||
{
|
||||
if (m_was_drawing) {
|
||||
m_editor->did_complete_action();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue