diff --git a/Userland/Applications/PixelPaint/BrushTool.cpp b/Userland/Applications/PixelPaint/BrushTool.cpp index 45bf8e7c6a..0a07f921ac 100644 --- a/Userland/Applications/PixelPaint/BrushTool.cpp +++ b/Userland/Applications/PixelPaint/BrushTool.cpp @@ -25,8 +25,11 @@ BrushTool::~BrushTool() { } -void BrushTool::on_mousedown(Layer& layer, MouseEvent& event) +void BrushTool::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; @@ -34,28 +37,31 @@ void BrushTool::on_mousedown(Layer& layer, MouseEvent& event) const int first_draw_opacity = 10; for (int i = 0; i < first_draw_opacity; ++i) - draw_point(layer.bitmap(), m_editor->color_for(layer_event), layer_event.position()); + draw_point(layer->bitmap(), m_editor->color_for(layer_event), layer_event.position()); - layer.did_modify_bitmap(Gfx::IntRect::centered_on(layer_event.position(), Gfx::IntSize { m_size * 2, m_size * 2 })); + 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, MouseEvent& event) +void BrushTool::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)) return; - draw_line(layer.bitmap(), m_editor->color_for(layer_event), m_last_position, layer_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, layer_event.position()).inflated(m_size * 2, m_size * 2); - layer.did_modify_bitmap(modified_rect); + layer->did_modify_bitmap(modified_rect); m_last_position = layer_event.position(); m_was_drawing = true; } -void BrushTool::on_mouseup(Layer&, MouseEvent&) +void BrushTool::on_mouseup(Layer*, MouseEvent&) { if (m_was_drawing) { m_editor->did_complete_action(); diff --git a/Userland/Applications/PixelPaint/BrushTool.h b/Userland/Applications/PixelPaint/BrushTool.h index 6938c4a3c9..943988afff 100644 --- a/Userland/Applications/PixelPaint/BrushTool.h +++ b/Userland/Applications/PixelPaint/BrushTool.h @@ -15,9 +15,9 @@ public: BrushTool(); virtual ~BrushTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } diff --git a/Userland/Applications/PixelPaint/BucketTool.cpp b/Userland/Applications/PixelPaint/BucketTool.cpp index 7ccf39cbff..6afab1d1a8 100644 --- a/Userland/Applications/PixelPaint/BucketTool.cpp +++ b/Userland/Applications/PixelPaint/BucketTool.cpp @@ -70,18 +70,21 @@ static void flood_fill(Gfx::Bitmap& bitmap, Gfx::IntPoint const& start_position, } } -void BucketTool::on_mousedown(Layer& layer, MouseEvent& event) +void BucketTool::on_mousedown(Layer* layer, MouseEvent& event) { - auto& layer_event = event.layer_event(); - if (!layer.rect().contains(layer_event.position())) + if (!layer) return; - GUI::Painter painter(layer.bitmap()); - auto target_color = layer.bitmap().get_pixel(layer_event.x(), layer_event.y()); + auto& layer_event = event.layer_event(); + if (!layer->rect().contains(layer_event.position())) + return; - flood_fill(layer.bitmap(), layer_event.position(), target_color, m_editor->color_for(layer_event), m_threshold); + GUI::Painter painter(layer->bitmap()); + auto target_color = layer->bitmap().get_pixel(layer_event.x(), layer_event.y()); - layer.did_modify_bitmap(); + flood_fill(layer->bitmap(), layer_event.position(), target_color, m_editor->color_for(layer_event), m_threshold); + + layer->did_modify_bitmap(); m_editor->did_complete_action(); } diff --git a/Userland/Applications/PixelPaint/BucketTool.h b/Userland/Applications/PixelPaint/BucketTool.h index 2d569b2c79..e9844fc146 100644 --- a/Userland/Applications/PixelPaint/BucketTool.h +++ b/Userland/Applications/PixelPaint/BucketTool.h @@ -15,7 +15,7 @@ public: BucketTool(); virtual ~BucketTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; virtual GUI::Widget* get_properties_widget() override; private: diff --git a/Userland/Applications/PixelPaint/EllipseTool.cpp b/Userland/Applications/PixelPaint/EllipseTool.cpp index 1ae5fc3734..50e1bbd2d9 100644 --- a/Userland/Applications/PixelPaint/EllipseTool.cpp +++ b/Userland/Applications/PixelPaint/EllipseTool.cpp @@ -40,8 +40,11 @@ void EllipseTool::draw_using(GUI::Painter& painter, Gfx::IntRect const& ellipse_ } } -void EllipseTool::on_mousedown(Layer&, MouseEvent& event) +void EllipseTool::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; @@ -55,10 +58,13 @@ void EllipseTool::on_mousedown(Layer&, MouseEvent& event) m_editor->update(); } -void EllipseTool::on_mouseup(Layer& layer, MouseEvent& event) +void EllipseTool::on_mouseup(Layer* layer, MouseEvent& event) { + if (!layer) + return; + if (event.layer_event().button() == m_drawing_button) { - GUI::Painter painter(layer.bitmap()); + GUI::Painter painter(layer->bitmap()); draw_using(painter, Gfx::IntRect::from_two_points(m_ellipse_start_position, m_ellipse_end_position)); m_drawing_button = GUI::MouseButton::None; m_editor->update(); @@ -66,7 +72,7 @@ void EllipseTool::on_mouseup(Layer& layer, MouseEvent& event) } } -void EllipseTool::on_mousemove(Layer&, MouseEvent& event) +void EllipseTool::on_mousemove(Layer*, MouseEvent& event) { if (m_drawing_button == GUI::MouseButton::None) return; @@ -75,15 +81,15 @@ void EllipseTool::on_mousemove(Layer&, MouseEvent& event) m_editor->update(); } -void EllipseTool::on_second_paint(Layer const& layer, GUI::PaintEvent& event) +void EllipseTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) { - if (m_drawing_button == GUI::MouseButton::None) + if (!layer || m_drawing_button == GUI::MouseButton::None) return; GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); - auto preview_start = m_editor->layer_position_to_editor_position(layer, m_ellipse_start_position).to_type(); - auto preview_end = m_editor->layer_position_to_editor_position(layer, m_ellipse_end_position).to_type(); + auto preview_start = m_editor->layer_position_to_editor_position(*layer, m_ellipse_start_position).to_type(); + auto preview_end = m_editor->layer_position_to_editor_position(*layer, m_ellipse_end_position).to_type(); draw_using(painter, Gfx::IntRect::from_two_points(preview_start, preview_end)); } diff --git a/Userland/Applications/PixelPaint/EllipseTool.h b/Userland/Applications/PixelPaint/EllipseTool.h index b7ba0af6b0..08b22a245d 100644 --- a/Userland/Applications/PixelPaint/EllipseTool.h +++ b/Userland/Applications/PixelPaint/EllipseTool.h @@ -17,10 +17,10 @@ public: EllipseTool(); virtual ~EllipseTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; - virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; + virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } 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; diff --git a/Userland/Applications/PixelPaint/EraseTool.h b/Userland/Applications/PixelPaint/EraseTool.h index fe46032d19..683c1f1b81 100644 --- a/Userland/Applications/PixelPaint/EraseTool.h +++ b/Userland/Applications/PixelPaint/EraseTool.h @@ -18,9 +18,9 @@ public: EraseTool(); virtual ~EraseTool() override; - virtual void on_mousedown(Layer&, MouseEvent& event) override; - virtual void on_mousemove(Layer&, MouseEvent& event) override; - virtual void on_mouseup(Layer&, MouseEvent& event) override; + virtual void on_mousedown(Layer*, MouseEvent& event) override; + virtual void on_mousemove(Layer*, MouseEvent& event) override; + virtual void on_mouseup(Layer*, MouseEvent& event) override; virtual GUI::Widget* get_properties_widget() override; private: diff --git a/Userland/Applications/PixelPaint/GuideTool.cpp b/Userland/Applications/PixelPaint/GuideTool.cpp index b038e73d73..d27f6ebada 100644 --- a/Userland/Applications/PixelPaint/GuideTool.cpp +++ b/Userland/Applications/PixelPaint/GuideTool.cpp @@ -49,7 +49,7 @@ RefPtr GuideTool::closest_guide(const Gfx::IntPoint& point) return nullptr; } -void GuideTool::on_mousedown(Layer&, MouseEvent& event) +void GuideTool::on_mousedown(Layer*, MouseEvent& event) { if (!m_editor) return; @@ -85,7 +85,7 @@ void GuideTool::on_mousedown(Layer&, MouseEvent& event) } } -void GuideTool::on_mouseup(Layer&, MouseEvent&) +void GuideTool::on_mouseup(Layer*, MouseEvent&) { m_guide_origin = 0; m_event_origin = { 0, 0 }; @@ -104,7 +104,7 @@ void GuideTool::on_mouseup(Layer&, MouseEvent&) m_selected_guide = nullptr; } -void GuideTool::on_mousemove(Layer&, MouseEvent& event) +void GuideTool::on_mousemove(Layer*, MouseEvent& event) { if (!m_selected_guide) return; @@ -132,7 +132,7 @@ void GuideTool::on_mousemove(Layer&, MouseEvent& event) editor()->layers_did_change(); } -void GuideTool::on_context_menu(Layer&, GUI::ContextMenuEvent& event) +void GuideTool::on_context_menu(Layer*, GUI::ContextMenuEvent& event) { if (!m_editor) return; diff --git a/Userland/Applications/PixelPaint/GuideTool.h b/Userland/Applications/PixelPaint/GuideTool.h index c25b3f8666..eefa2a14bc 100644 --- a/Userland/Applications/PixelPaint/GuideTool.h +++ b/Userland/Applications/PixelPaint/GuideTool.h @@ -18,10 +18,10 @@ public: virtual ~GuideTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; - virtual void on_context_menu(Layer&, GUI::ContextMenuEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; + virtual void on_context_menu(Layer*, GUI::ContextMenuEvent&) override; virtual void on_tool_activation() override; diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 5c300564b5..83185f1f64 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -145,8 +145,8 @@ Gfx::FloatPoint ImageEditor::editor_position_to_image_position(Gfx::IntPoint con void ImageEditor::second_paint_event(GUI::PaintEvent& event) { - if (m_active_tool && m_active_layer) - m_active_tool->on_second_paint(*m_active_layer, event); + if (m_active_tool) + m_active_tool->on_second_paint(m_active_layer, event); } GUI::MouseEvent ImageEditor::event_with_pan_and_scale_applied(GUI::MouseEvent const& event) const @@ -194,13 +194,10 @@ void ImageEditor::mousedown_event(GUI::MouseEvent& event) } } - if (!m_active_layer) - return; - - auto layer_event = event_adjusted_for_layer(event, *m_active_layer); + auto layer_event = m_active_layer ? event_adjusted_for_layer(event, *m_active_layer) : event; auto image_event = event_with_pan_and_scale_applied(event); Tool::MouseEvent tool_event(Tool::MouseEvent::Action::MouseDown, layer_event, image_event, event); - m_active_tool->on_mousedown(*m_active_layer, tool_event); + m_active_tool->on_mousedown(m_active_layer.ptr(), tool_event); } void ImageEditor::mousemove_event(GUI::MouseEvent& event) @@ -215,13 +212,13 @@ void ImageEditor::mousemove_event(GUI::MouseEvent& event) return; } - if (!m_active_layer || !m_active_tool) + if (!m_active_tool) return; - auto layer_event = event_adjusted_for_layer(event, *m_active_layer); + auto layer_event = m_active_layer ? event_adjusted_for_layer(event, *m_active_layer) : event; auto image_event = event_with_pan_and_scale_applied(event); Tool::MouseEvent tool_event(Tool::MouseEvent::Action::MouseDown, layer_event, image_event, event); - m_active_tool->on_mousemove(*m_active_layer, tool_event); + m_active_tool->on_mousemove(m_active_layer.ptr(), tool_event); if (on_image_mouse_position_change) { on_image_mouse_position_change(image_event.position()); @@ -232,12 +229,12 @@ void ImageEditor::mouseup_event(GUI::MouseEvent& event) { set_override_cursor(m_active_cursor); - if (!m_active_layer || !m_active_tool) + if (!m_active_tool) return; - auto layer_event = event_adjusted_for_layer(event, *m_active_layer); + auto layer_event = m_active_layer ? event_adjusted_for_layer(event, *m_active_layer) : event; auto image_event = event_with_pan_and_scale_applied(event); Tool::MouseEvent tool_event(Tool::MouseEvent::Action::MouseDown, layer_event, image_event, event); - m_active_tool->on_mouseup(*m_active_layer, tool_event); + m_active_tool->on_mouseup(m_active_layer.ptr(), tool_event); } void ImageEditor::mousewheel_event(GUI::MouseEvent& event) @@ -248,9 +245,9 @@ void ImageEditor::mousewheel_event(GUI::MouseEvent& event) void ImageEditor::context_menu_event(GUI::ContextMenuEvent& event) { - if (!m_active_layer || !m_active_tool) + if (!m_active_tool) return; - m_active_tool->on_context_menu(*m_active_layer, event); + m_active_tool->on_context_menu(m_active_layer, event); } void ImageEditor::resize_event(GUI::ResizeEvent& event) diff --git a/Userland/Applications/PixelPaint/LineTool.cpp b/Userland/Applications/PixelPaint/LineTool.cpp index db32d323d1..e05a6dd1cd 100644 --- a/Userland/Applications/PixelPaint/LineTool.cpp +++ b/Userland/Applications/PixelPaint/LineTool.cpp @@ -38,8 +38,11 @@ LineTool::~LineTool() { } -void LineTool::on_mousedown(Layer&, MouseEvent& event) +void LineTool::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; @@ -55,20 +58,26 @@ void LineTool::on_mousedown(Layer&, MouseEvent& event) m_editor->update(); } -void LineTool::on_mouseup(Layer& layer, MouseEvent& event) +void LineTool::on_mouseup(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& layer_event = event.layer_event(); if (layer_event.button() == m_drawing_button) { - GUI::Painter painter(layer.bitmap()); + GUI::Painter painter(layer->bitmap()); painter.draw_line(m_line_start_position, m_line_end_position, m_editor->color_for(m_drawing_button), m_thickness); m_drawing_button = GUI::MouseButton::None; - layer.did_modify_bitmap(); + layer->did_modify_bitmap(); m_editor->did_complete_action(); } } -void LineTool::on_mousemove(Layer&, MouseEvent& event) +void LineTool::on_mousemove(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& layer_event = event.layer_event(); if (m_drawing_button == GUI::MouseButton::None) return; @@ -82,15 +91,15 @@ void LineTool::on_mousemove(Layer&, MouseEvent& event) m_editor->update(); } -void LineTool::on_second_paint(Layer const& layer, GUI::PaintEvent& event) +void LineTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) { - if (m_drawing_button == GUI::MouseButton::None) + if (!layer || m_drawing_button == GUI::MouseButton::None) return; GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); - auto preview_start = m_editor->layer_position_to_editor_position(layer, m_line_start_position).to_type(); - auto preview_end = m_editor->layer_position_to_editor_position(layer, m_line_end_position).to_type(); + auto preview_start = m_editor->layer_position_to_editor_position(*layer, m_line_start_position).to_type(); + auto preview_end = m_editor->layer_position_to_editor_position(*layer, m_line_end_position).to_type(); painter.draw_line(preview_start, preview_end, m_editor->color_for(m_drawing_button), m_thickness); } diff --git a/Userland/Applications/PixelPaint/LineTool.h b/Userland/Applications/PixelPaint/LineTool.h index f90786eeb4..eafd6d1eca 100644 --- a/Userland/Applications/PixelPaint/LineTool.h +++ b/Userland/Applications/PixelPaint/LineTool.h @@ -17,10 +17,10 @@ public: LineTool(); virtual ~LineTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; - virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; + virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } diff --git a/Userland/Applications/PixelPaint/MoveTool.cpp b/Userland/Applications/PixelPaint/MoveTool.cpp index f59bbaf2f2..54af91a280 100644 --- a/Userland/Applications/PixelPaint/MoveTool.cpp +++ b/Userland/Applications/PixelPaint/MoveTool.cpp @@ -23,21 +23,27 @@ MoveTool::~MoveTool() { } -void MoveTool::on_mousedown(Layer& layer, MouseEvent& event) +void MoveTool::on_mousedown(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& layer_event = event.layer_event(); auto& image_event = event.image_event(); if (layer_event.button() != GUI::MouseButton::Left) return; - if (!layer.rect().contains(layer_event.position())) + if (!layer->rect().contains(layer_event.position())) return; - m_layer_being_moved = layer; + m_layer_being_moved = *layer; m_event_origin = image_event.position(); - m_layer_origin = layer.location(); + m_layer_origin = layer->location(); } -void MoveTool::on_mousemove(Layer&, MouseEvent& event) +void MoveTool::on_mousemove(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& image_event = event.image_event(); if (!m_layer_being_moved) return; @@ -46,8 +52,11 @@ void MoveTool::on_mousemove(Layer&, MouseEvent& event) m_editor->layers_did_change(); } -void MoveTool::on_mouseup(Layer&, MouseEvent& event) +void MoveTool::on_mouseup(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& layer_event = event.layer_event(); if (layer_event.button() != GUI::MouseButton::Left) return; diff --git a/Userland/Applications/PixelPaint/MoveTool.h b/Userland/Applications/PixelPaint/MoveTool.h index bacb09c6c5..50a48163cd 100644 --- a/Userland/Applications/PixelPaint/MoveTool.h +++ b/Userland/Applications/PixelPaint/MoveTool.h @@ -15,9 +15,9 @@ public: MoveTool(); virtual ~MoveTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Move; } diff --git a/Userland/Applications/PixelPaint/PenTool.cpp b/Userland/Applications/PixelPaint/PenTool.cpp index 84d3f76580..86c1b1381f 100644 --- a/Userland/Applications/PixelPaint/PenTool.cpp +++ b/Userland/Applications/PixelPaint/PenTool.cpp @@ -24,20 +24,26 @@ PenTool::~PenTool() { } -void PenTool::on_mousedown(Layer& layer, MouseEvent& event) +void PenTool::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; - GUI::Painter painter(layer.bitmap()); + GUI::Painter painter(layer->bitmap()); painter.draw_line(layer_event.position(), layer_event.position(), m_editor->color_for(layer_event), m_thickness); - layer.did_modify_bitmap(Gfx::IntRect::centered_on(layer_event.position(), Gfx::IntSize { m_thickness + 2, m_thickness + 2 })); + layer->did_modify_bitmap(Gfx::IntRect::centered_on(layer_event.position(), Gfx::IntSize { m_thickness + 2, m_thickness + 2 })); m_last_drawing_event_position = layer_event.position(); } -void PenTool::on_mouseup(Layer&, MouseEvent& event) +void PenTool::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) { m_last_drawing_event_position = { -1, -1 }; @@ -45,12 +51,15 @@ void PenTool::on_mouseup(Layer&, MouseEvent& event) } } -void PenTool::on_mousemove(Layer& layer, MouseEvent& event) +void PenTool::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)) return; - GUI::Painter painter(layer.bitmap()); + GUI::Painter painter(layer->bitmap()); Gfx::IntRect changed_rect; if (m_last_drawing_event_position != Gfx::IntPoint(-1, -1)) { @@ -61,7 +70,7 @@ void PenTool::on_mousemove(Layer& layer, MouseEvent& event) changed_rect = Gfx::IntRect::from_two_points(layer_event.position(), layer_event.position()); } changed_rect.inflate(m_thickness + 2, m_thickness + 2); - layer.did_modify_bitmap(changed_rect); + layer->did_modify_bitmap(changed_rect); m_last_drawing_event_position = layer_event.position(); } diff --git a/Userland/Applications/PixelPaint/PenTool.h b/Userland/Applications/PixelPaint/PenTool.h index ab1c381802..e6430c5f9b 100644 --- a/Userland/Applications/PixelPaint/PenTool.h +++ b/Userland/Applications/PixelPaint/PenTool.h @@ -17,9 +17,9 @@ public: PenTool(); virtual ~PenTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } diff --git a/Userland/Applications/PixelPaint/PickerTool.cpp b/Userland/Applications/PixelPaint/PickerTool.cpp index d1ca6cfb9f..0fd91f9264 100644 --- a/Userland/Applications/PixelPaint/PickerTool.cpp +++ b/Userland/Applications/PixelPaint/PickerTool.cpp @@ -18,12 +18,15 @@ PickerTool::~PickerTool() { } -void PickerTool::on_mousedown(Layer& layer, MouseEvent& event) +void PickerTool::on_mousedown(Layer* layer, MouseEvent& event) { - auto& layer_event = event.layer_event(); - if (!layer.rect().contains(layer_event.position())) + if (!layer) return; - auto color = layer.bitmap().get_pixel(layer_event.position()); + + auto& layer_event = event.layer_event(); + if (!layer->rect().contains(layer_event.position())) + return; + auto color = layer->bitmap().get_pixel(layer_event.position()); if (layer_event.button() == GUI::MouseButton::Left) m_editor->set_primary_color(color); else if (layer_event.button() == GUI::MouseButton::Right) diff --git a/Userland/Applications/PixelPaint/PickerTool.h b/Userland/Applications/PixelPaint/PickerTool.h index 9afc7aaa1e..17074ebc48 100644 --- a/Userland/Applications/PixelPaint/PickerTool.h +++ b/Userland/Applications/PixelPaint/PickerTool.h @@ -15,7 +15,7 @@ public: PickerTool(); virtual ~PickerTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } }; diff --git a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp index 63e1829a78..df109511fe 100644 --- a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp +++ b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp @@ -26,7 +26,7 @@ RectangleSelectTool::~RectangleSelectTool() { } -void RectangleSelectTool::on_mousedown(Layer&, MouseEvent& event) +void RectangleSelectTool::on_mousedown(Layer*, MouseEvent& event) { auto& image_event = event.image_event(); if (image_event.button() != GUI::MouseButton::Left) @@ -40,7 +40,7 @@ void RectangleSelectTool::on_mousedown(Layer&, MouseEvent& event) m_editor->update(); } -void RectangleSelectTool::on_mousemove(Layer&, MouseEvent& event) +void RectangleSelectTool::on_mousemove(Layer*, MouseEvent& event) { auto& image_event = event.image_event(); if (!m_selecting) @@ -58,7 +58,7 @@ void RectangleSelectTool::on_mousemove(Layer&, MouseEvent& event) m_editor->update(); } -void RectangleSelectTool::on_mouseup(Layer&, MouseEvent& event) +void RectangleSelectTool::on_mouseup(Layer*, MouseEvent& event) { auto& image_event = event.image_event(); if (!m_selecting || image_event.button() != GUI::MouseButton::Left) @@ -124,7 +124,7 @@ void RectangleSelectTool::on_keyup(GUI::KeyEvent& key_event) m_moving_mode = MovingMode::None; } -void RectangleSelectTool::on_second_paint(Layer const&, GUI::PaintEvent& event) +void RectangleSelectTool::on_second_paint(Layer const*, GUI::PaintEvent& event) { if (!m_selecting) return; diff --git a/Userland/Applications/PixelPaint/RectangleSelectTool.h b/Userland/Applications/PixelPaint/RectangleSelectTool.h index f3f0fa33cd..1d8fc45907 100644 --- a/Userland/Applications/PixelPaint/RectangleSelectTool.h +++ b/Userland/Applications/PixelPaint/RectangleSelectTool.h @@ -19,12 +19,12 @@ public: RectangleSelectTool(); virtual ~RectangleSelectTool(); - virtual void on_mousedown(Layer&, MouseEvent& event) override; - virtual void on_mousemove(Layer&, MouseEvent& event) override; - virtual void on_mouseup(Layer&, MouseEvent& event) override; + virtual void on_mousedown(Layer*, MouseEvent& event) override; + virtual void on_mousemove(Layer*, MouseEvent& event) override; + virtual void on_mouseup(Layer*, MouseEvent& event) override; virtual void on_keydown(GUI::KeyEvent&) override; virtual void on_keyup(GUI::KeyEvent&) override; - virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override; + virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } diff --git a/Userland/Applications/PixelPaint/RectangleTool.cpp b/Userland/Applications/PixelPaint/RectangleTool.cpp index 9a736d1b80..c4e83931be 100644 --- a/Userland/Applications/PixelPaint/RectangleTool.cpp +++ b/Userland/Applications/PixelPaint/RectangleTool.cpp @@ -42,8 +42,11 @@ void RectangleTool::draw_using(GUI::Painter& painter, Gfx::IntRect const& rect) } } -void RectangleTool::on_mousedown(Layer&, MouseEvent& event) +void RectangleTool::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; @@ -57,20 +60,26 @@ void RectangleTool::on_mousedown(Layer&, MouseEvent& event) m_editor->update(); } -void RectangleTool::on_mouseup(Layer& layer, MouseEvent& event) +void RectangleTool::on_mouseup(Layer* layer, MouseEvent& event) { + if (!layer) + return; + if (event.layer_event().button() == m_drawing_button) { - GUI::Painter painter(layer.bitmap()); + GUI::Painter painter(layer->bitmap()); auto rect = Gfx::IntRect::from_two_points(m_rectangle_start_position, m_rectangle_end_position); draw_using(painter, rect); m_drawing_button = GUI::MouseButton::None; - layer.did_modify_bitmap(); + layer->did_modify_bitmap(); m_editor->did_complete_action(); } } -void RectangleTool::on_mousemove(Layer&, MouseEvent& event) +void RectangleTool::on_mousemove(Layer* layer, MouseEvent& event) { + if (!layer) + return; + if (m_drawing_button == GUI::MouseButton::None) return; @@ -78,16 +87,16 @@ void RectangleTool::on_mousemove(Layer&, MouseEvent& event) m_editor->update(); } -void RectangleTool::on_second_paint(Layer const& layer, GUI::PaintEvent& event) +void RectangleTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) { - if (m_drawing_button == GUI::MouseButton::None) + if (!layer || m_drawing_button == GUI::MouseButton::None) return; GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); auto rect = Gfx::IntRect::from_two_points( - m_editor->layer_position_to_editor_position(layer, m_rectangle_start_position).to_type(), - m_editor->layer_position_to_editor_position(layer, m_rectangle_end_position).to_type()); + m_editor->layer_position_to_editor_position(*layer, m_rectangle_start_position).to_type(), + m_editor->layer_position_to_editor_position(*layer, m_rectangle_end_position).to_type()); draw_using(painter, rect); } diff --git a/Userland/Applications/PixelPaint/RectangleTool.h b/Userland/Applications/PixelPaint/RectangleTool.h index 24170be97b..fad487cc9f 100644 --- a/Userland/Applications/PixelPaint/RectangleTool.h +++ b/Userland/Applications/PixelPaint/RectangleTool.h @@ -17,10 +17,10 @@ public: RectangleTool(); virtual ~RectangleTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; - virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; + virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } diff --git a/Userland/Applications/PixelPaint/SprayTool.cpp b/Userland/Applications/PixelPaint/SprayTool.cpp index b5b7fc8dc3..22a464cf4f 100644 --- a/Userland/Applications/PixelPaint/SprayTool.cpp +++ b/Userland/Applications/PixelPaint/SprayTool.cpp @@ -63,8 +63,11 @@ void SprayTool::paint_it() layer->did_modify_bitmap(Gfx::IntRect::centered_on(m_last_pos, Gfx::IntSize(base_radius * 2, base_radius * 2))); } -void SprayTool::on_mousedown(Layer&, MouseEvent& event) +void SprayTool::on_mousedown(Layer* layer, MouseEvent& event) { + if (!layer) + return; + auto& layer_event = event.layer_event(); m_color = m_editor->color_for(layer_event); m_last_pos = layer_event.position(); @@ -72,8 +75,11 @@ void SprayTool::on_mousedown(Layer&, MouseEvent& event) paint_it(); } -void SprayTool::on_mousemove(Layer&, MouseEvent& event) +void SprayTool::on_mousemove(Layer* layer, MouseEvent& event) { + if (!layer) + return; + m_last_pos = event.layer_event().position(); if (m_timer->is_active()) { paint_it(); @@ -81,7 +87,7 @@ void SprayTool::on_mousemove(Layer&, MouseEvent& event) } } -void SprayTool::on_mouseup(Layer&, MouseEvent&) +void SprayTool::on_mouseup(Layer*, MouseEvent&) { if (m_timer->is_active()) { m_timer->stop(); diff --git a/Userland/Applications/PixelPaint/SprayTool.h b/Userland/Applications/PixelPaint/SprayTool.h index 7dcf37e306..9f08bdfb44 100644 --- a/Userland/Applications/PixelPaint/SprayTool.h +++ b/Userland/Applications/PixelPaint/SprayTool.h @@ -18,9 +18,9 @@ public: SprayTool(); virtual ~SprayTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; - virtual void on_mouseup(Layer&, MouseEvent&) override; - virtual void on_mousemove(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; } diff --git a/Userland/Applications/PixelPaint/Tool.h b/Userland/Applications/PixelPaint/Tool.h index d0573faf49..6466d051ae 100644 --- a/Userland/Applications/PixelPaint/Tool.h +++ b/Userland/Applications/PixelPaint/Tool.h @@ -48,12 +48,12 @@ public: GUI::MouseEvent& m_raw_event; }; - virtual void on_mousedown(Layer&, MouseEvent&) { } - virtual void on_mousemove(Layer&, MouseEvent&) { } - virtual void on_mouseup(Layer&, MouseEvent&) { } - virtual void on_context_menu(Layer&, GUI::ContextMenuEvent&) { } + virtual void on_mousedown(Layer*, MouseEvent&) { } + virtual void on_mousemove(Layer*, MouseEvent&) { } + virtual void on_mouseup(Layer*, MouseEvent&) { } + virtual void on_context_menu(Layer*, GUI::ContextMenuEvent&) { } virtual void on_tool_button_contextmenu(GUI::ContextMenuEvent&) { } - virtual void on_second_paint(Layer const&, GUI::PaintEvent&) { } + virtual void on_second_paint(Layer const*, GUI::PaintEvent&) { } virtual void on_keydown(GUI::KeyEvent&) { } virtual void on_keyup(GUI::KeyEvent&) { } virtual void on_tool_activation() { } diff --git a/Userland/Applications/PixelPaint/ZoomTool.cpp b/Userland/Applications/PixelPaint/ZoomTool.cpp index 64cc0dce0b..1fe473288a 100644 --- a/Userland/Applications/PixelPaint/ZoomTool.cpp +++ b/Userland/Applications/PixelPaint/ZoomTool.cpp @@ -20,7 +20,7 @@ ZoomTool::~ZoomTool() { } -void ZoomTool::on_mousedown(Layer&, MouseEvent& event) +void ZoomTool::on_mousedown(Layer*, MouseEvent& event) { auto& raw_event = event.raw_event(); if (raw_event.button() != GUI::MouseButton::Left && raw_event.button() != GUI::MouseButton::Right) diff --git a/Userland/Applications/PixelPaint/ZoomTool.h b/Userland/Applications/PixelPaint/ZoomTool.h index d42b779034..b81930ef0f 100644 --- a/Userland/Applications/PixelPaint/ZoomTool.h +++ b/Userland/Applications/PixelPaint/ZoomTool.h @@ -17,7 +17,7 @@ public: ZoomTool(); virtual ~ZoomTool() override; - virtual void on_mousedown(Layer&, MouseEvent&) override; + virtual void on_mousedown(Layer*, MouseEvent&) override; virtual GUI::Widget* get_properties_widget() override; private: