diff options
author | Maciej Zygmanowski <sppmacd@pm.me> | 2021-08-25 10:07:24 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-27 12:45:06 +0200 |
commit | 3ad9df152299fd2cf87b82e0029f4ed3169ae163 (patch) | |
tree | 33381b3e3eee096d00bfd34c49636c98f2614492 /Userland/Applications/PixelPaint/EraseTool.cpp | |
parent | 0224dc2882cfed4c5a00dea0217571ddadde9d62 (diff) | |
download | serenity-3ad9df152299fd2cf87b82e0029f4ed3169ae163.zip |
PixelPaint: Make Layer passed to tools a pointer
Some tools (e.g. ZoomTool) doesn't need layer to work. This commit
makes mouse events fire even if there is no layer. This fixes
a bug that ZoomTool didn't work when there is no layers.
Diffstat (limited to 'Userland/Applications/PixelPaint/EraseTool.cpp')
-rw-r--r-- | Userland/Applications/PixelPaint/EraseTool.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Userland/Applications/PixelPaint/EraseTool.cpp b/Userland/Applications/PixelPaint/EraseTool.cpp index 61258e2703..40ae7fcb8b 100644 --- a/Userland/Applications/PixelPaint/EraseTool.cpp +++ b/Userland/Applications/PixelPaint/EraseTool.cpp @@ -35,30 +35,39 @@ 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, MouseEvent& event) +void EraseTool::on_mousedown(Layer* layer, MouseEvent& event) { + if (!layer) + return; + 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(layer_event.position(), layer.rect()); - GUI::Painter painter(layer.bitmap()); + 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)); + layer->did_modify_bitmap(r.inflated(2, 2)); } -void EraseTool::on_mousemove(Layer& layer, MouseEvent& event) +void EraseTool::on_mousemove(Layer* layer, MouseEvent& event) { + if (!layer) + return; + 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()); + 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)); + layer->did_modify_bitmap(r.inflated(2, 2)); } } -void EraseTool::on_mouseup(Layer&, MouseEvent& event) +void EraseTool::on_mouseup(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& layer_event = event.layer_event(); if (layer_event.button() != GUI::MouseButton::Left && layer_event.button() != GUI::MouseButton::Right) return; |