1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27: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:
Maciej Zygmanowski 2021-08-25 10:06:00 +02:00 committed by Andreas Kling
parent 635130ef76
commit 0224dc2882
28 changed files with 186 additions and 127 deletions

View file

@ -35,29 +35,32 @@ Gfx::IntRect EraseTool::build_rect(Gfx::IntPoint const& pos, Gfx::IntRect const&
return Gfx::IntRect(ex - eraser_radius, ey - eraser_radius, eraser_size, eraser_size).intersected(widget_rect);
}
void EraseTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&)
void EraseTool::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;
Gfx::IntRect r = build_rect(event.position(), layer.rect());
Gfx::IntRect r = build_rect(layer_event.position(), layer.rect());
GUI::Painter painter(layer.bitmap());
painter.clear_rect(r, get_color());
layer.did_modify_bitmap(r.inflated(2, 2));
}
void EraseTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&)
void EraseTool::on_mousemove(Layer& layer, MouseEvent& event)
{
if (event.buttons() & GUI::MouseButton::Left || event.buttons() & GUI::MouseButton::Right) {
Gfx::IntRect r = build_rect(event.position(), layer.rect());
auto& layer_event = event.layer_event();
if (layer_event.buttons() & GUI::MouseButton::Left || layer_event.buttons() & GUI::MouseButton::Right) {
Gfx::IntRect r = build_rect(layer_event.position(), layer.rect());
GUI::Painter painter(layer.bitmap());
painter.clear_rect(r, get_color());
layer.did_modify_bitmap(r.inflated(2, 2));
}
}
void EraseTool::on_mouseup(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
void EraseTool::on_mouseup(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;
m_editor->did_complete_action();
}