From 3d50f40396a6b8000fa267d51144cd983c7d4fea Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 May 2020 00:08:47 +0200 Subject: [PATCH] PaintBrush: Add a "Move" tool for moving layers around :^) Tool mouse event handlers now receive both a layer-relative mouse event and the original event. This is needed for the move tool since it moves the layer and thereby changes the origin of future events every time it moves. --- Applications/PaintBrush/BucketTool.cpp | 2 +- Applications/PaintBrush/BucketTool.h | 2 +- Applications/PaintBrush/EllipseTool.cpp | 6 +- Applications/PaintBrush/EllipseTool.h | 6 +- Applications/PaintBrush/EraseTool.cpp | 4 +- Applications/PaintBrush/EraseTool.h | 4 +- Applications/PaintBrush/ImageEditor.cpp | 6 +- Applications/PaintBrush/LineTool.cpp | 6 +- Applications/PaintBrush/LineTool.h | 6 +- Applications/PaintBrush/Makefile | 1 + Applications/PaintBrush/MoveTool.cpp | 70 +++++++++++++++++++++++ Applications/PaintBrush/MoveTool.h | 50 ++++++++++++++++ Applications/PaintBrush/PenTool.cpp | 6 +- Applications/PaintBrush/PenTool.h | 6 +- Applications/PaintBrush/PickerTool.cpp | 2 +- Applications/PaintBrush/PickerTool.h | 2 +- Applications/PaintBrush/RectangleTool.cpp | 6 +- Applications/PaintBrush/RectangleTool.h | 6 +- Applications/PaintBrush/SprayTool.cpp | 6 +- Applications/PaintBrush/SprayTool.h | 6 +- Applications/PaintBrush/Tool.h | 6 +- Applications/PaintBrush/ToolboxWidget.cpp | 2 + 22 files changed, 167 insertions(+), 44 deletions(-) create mode 100644 Applications/PaintBrush/MoveTool.cpp create mode 100644 Applications/PaintBrush/MoveTool.h diff --git a/Applications/PaintBrush/BucketTool.cpp b/Applications/PaintBrush/BucketTool.cpp index 7c5bde56ec3fbe326ac76756268f69e8201a0c9e..d7aed49e4d2a6f5e07311860d114956df2595c1f 100644 --- a/Applications/PaintBrush/BucketTool.cpp +++ b/Applications/PaintBrush/BucketTool.cpp @@ -78,7 +78,7 @@ static void flood_fill(Gfx::Bitmap& bitmap, const Gfx::Point& start_position, Co } } -void BucketTool::on_mousedown(Layer& layer, GUI::MouseEvent& event) +void BucketTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (!layer.rect().contains(event.position())) return; diff --git a/Applications/PaintBrush/BucketTool.h b/Applications/PaintBrush/BucketTool.h index 8749025d1e5309d34cac19009433c7b7acc34415..8052f018dd1309a81448d79f39812bacbb59ac45 100644 --- a/Applications/PaintBrush/BucketTool.h +++ b/Applications/PaintBrush/BucketTool.h @@ -35,7 +35,7 @@ public: BucketTool(); virtual ~BucketTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; private: virtual const char* class_name() const override { return "BucketTool"; } diff --git a/Applications/PaintBrush/EllipseTool.cpp b/Applications/PaintBrush/EllipseTool.cpp index 661005bf2f8e3a555bca838a546a58d15d353f06..9dc39225be0a9e544932d41dac68cd328045811b 100644 --- a/Applications/PaintBrush/EllipseTool.cpp +++ b/Applications/PaintBrush/EllipseTool.cpp @@ -56,7 +56,7 @@ void EllipseTool::draw_using(GUI::Painter& painter) } } -void EllipseTool::on_mousedown(Layer&, GUI::MouseEvent& event) +void EllipseTool::on_mousedown(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right) return; @@ -70,7 +70,7 @@ void EllipseTool::on_mousedown(Layer&, GUI::MouseEvent& event) m_editor->update(); } -void EllipseTool::on_mouseup(Layer& layer, GUI::MouseEvent& event) +void EllipseTool::on_mouseup(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() == m_drawing_button) { GUI::Painter painter(layer.bitmap()); @@ -80,7 +80,7 @@ void EllipseTool::on_mouseup(Layer& layer, GUI::MouseEvent& event) } } -void EllipseTool::on_mousemove(Layer& layer, GUI::MouseEvent& event) +void EllipseTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (m_drawing_button == GUI::MouseButton::None) return; diff --git a/Applications/PaintBrush/EllipseTool.h b/Applications/PaintBrush/EllipseTool.h index 3638920bcd6d91178e1512b21a391b34e1b7c5af..3223404c91c51da03c2a5751d63d5250b79eb5cd 100644 --- a/Applications/PaintBrush/EllipseTool.h +++ b/Applications/PaintBrush/EllipseTool.h @@ -37,9 +37,9 @@ public: EllipseTool(); virtual ~EllipseTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; - virtual void on_mousemove(Layer&, GUI::MouseEvent&) override; - virtual void on_mouseup(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_contextmenu(GUI::ContextMenuEvent&) override; virtual void on_second_paint(GUI::PaintEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; diff --git a/Applications/PaintBrush/EraseTool.cpp b/Applications/PaintBrush/EraseTool.cpp index e1aa1c913cb535057a98f6a010ea637d0246f619..90403df340fa2a99799d14f5613c53192769be2c 100644 --- a/Applications/PaintBrush/EraseTool.cpp +++ b/Applications/PaintBrush/EraseTool.cpp @@ -53,7 +53,7 @@ Gfx::Rect EraseTool::build_rect(const Gfx::Point& pos, const Gfx::Rect& widget_r return Gfx::Rect(ex - eraser_radius, ey - eraser_radius, eraser_size, eraser_size).intersected(widget_rect); } -void EraseTool::on_mousedown(Layer& layer, GUI::MouseEvent& event) +void EraseTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right) return; @@ -63,7 +63,7 @@ void EraseTool::on_mousedown(Layer& layer, GUI::MouseEvent& event) m_editor->update(); } -void EraseTool::on_mousemove(Layer& layer, GUI::MouseEvent& event) +void EraseTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (!m_editor->rect().contains(event.position())) return; diff --git a/Applications/PaintBrush/EraseTool.h b/Applications/PaintBrush/EraseTool.h index 8384b8e8fee7ffb639f0c7fb5360e65a6f574a57..f610a80220eef7b08f3db93e33c161bbd19d1586 100644 --- a/Applications/PaintBrush/EraseTool.h +++ b/Applications/PaintBrush/EraseTool.h @@ -38,8 +38,8 @@ public: EraseTool(); virtual ~EraseTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; - virtual void on_mousemove(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_contextmenu(GUI::ContextMenuEvent&) override; private: diff --git a/Applications/PaintBrush/ImageEditor.cpp b/Applications/PaintBrush/ImageEditor.cpp index 99b5f3f91d7a4d2e9492b8d89de30a1615f48177..95018fdfe698fa043231b42647c62b914ca7174b 100644 --- a/Applications/PaintBrush/ImageEditor.cpp +++ b/Applications/PaintBrush/ImageEditor.cpp @@ -79,7 +79,7 @@ void ImageEditor::mousedown_event(GUI::MouseEvent& event) if (!m_active_layer || !m_active_tool) return; auto layer_event = event_adjusted_for_layer(event, *m_active_layer); - m_active_tool->on_mousedown(*m_active_layer, layer_event); + m_active_tool->on_mousedown(*m_active_layer, layer_event, event); } void ImageEditor::mousemove_event(GUI::MouseEvent& event) @@ -87,7 +87,7 @@ void ImageEditor::mousemove_event(GUI::MouseEvent& event) if (!m_active_layer || !m_active_tool) return; auto layer_event = event_adjusted_for_layer(event, *m_active_layer); - m_active_tool->on_mousemove(*m_active_layer, layer_event); + m_active_tool->on_mousemove(*m_active_layer, layer_event, event); } void ImageEditor::mouseup_event(GUI::MouseEvent& event) @@ -95,7 +95,7 @@ void ImageEditor::mouseup_event(GUI::MouseEvent& event) if (!m_active_layer || !m_active_tool) return; auto layer_event = event_adjusted_for_layer(event, *m_active_layer); - m_active_tool->on_mouseup(*m_active_layer, layer_event); + m_active_tool->on_mouseup(*m_active_layer, layer_event, event); } void ImageEditor::set_active_layer(Layer* layer) diff --git a/Applications/PaintBrush/LineTool.cpp b/Applications/PaintBrush/LineTool.cpp index e2a071334b50faeaaec5b44e6bb595e5eb00e58e..a714130cf1db776231a5ade533a26ea45900a549 100644 --- a/Applications/PaintBrush/LineTool.cpp +++ b/Applications/PaintBrush/LineTool.cpp @@ -56,7 +56,7 @@ LineTool::~LineTool() { } -void LineTool::on_mousedown(Layer&, GUI::MouseEvent& event) +void LineTool::on_mousedown(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right) return; @@ -70,7 +70,7 @@ void LineTool::on_mousedown(Layer&, GUI::MouseEvent& event) m_editor->update(); } -void LineTool::on_mouseup(Layer& layer, GUI::MouseEvent& event) +void LineTool::on_mouseup(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() == m_drawing_button) { GUI::Painter painter(layer.bitmap()); @@ -80,7 +80,7 @@ void LineTool::on_mouseup(Layer& layer, GUI::MouseEvent& event) } } -void LineTool::on_mousemove(Layer&, GUI::MouseEvent& event) +void LineTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (m_drawing_button == GUI::MouseButton::None) return; diff --git a/Applications/PaintBrush/LineTool.h b/Applications/PaintBrush/LineTool.h index a30286ac5e1afaa923d59bbe4ac32b128aca2ba4..ad64e4c1e2259c11558a70055522853c26d2a304 100644 --- a/Applications/PaintBrush/LineTool.h +++ b/Applications/PaintBrush/LineTool.h @@ -37,9 +37,9 @@ public: LineTool(); virtual ~LineTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; - virtual void on_mousemove(Layer&, GUI::MouseEvent&) override; - virtual void on_mouseup(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_contextmenu(GUI::ContextMenuEvent&) override; virtual void on_second_paint(GUI::PaintEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; diff --git a/Applications/PaintBrush/Makefile b/Applications/PaintBrush/Makefile index 8a88850c0a77e5b7443230230fce3480d9003bc4..c6514a09b4e631460fa193b7d840c3e0c170f79d 100644 --- a/Applications/PaintBrush/Makefile +++ b/Applications/PaintBrush/Makefile @@ -7,6 +7,7 @@ OBJS = \ Layer.o \ LayerModel.o \ LineTool.o \ + MoveTool.o \ PaintableWidget.o \ PaletteWidget.o \ PenTool.o \ diff --git a/Applications/PaintBrush/MoveTool.cpp b/Applications/PaintBrush/MoveTool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1b20125a7e196d2a4f4012d4d87f392c0bee625 --- /dev/null +++ b/Applications/PaintBrush/MoveTool.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "MoveTool.h" +#include "ImageEditor.h" +#include "Layer.h" +#include "PaintableWidget.h" +#include + +namespace PaintBrush { + +MoveTool::MoveTool() +{ +} + +MoveTool::~MoveTool() +{ +} + +void MoveTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent& original_event) +{ + if (event.button() != GUI::MouseButton::Left) + return; + if (!layer.rect().contains(event.position())) + return; + m_layer_being_moved = layer; + m_event_origin = original_event.position(); + m_layer_origin = layer.location(); +} + +void MoveTool::on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent& original_event) +{ + if (!m_layer_being_moved) + return; + auto delta = original_event.position() - m_event_origin; + m_layer_being_moved->set_location(m_layer_origin.translated(delta)); + m_editor->update(); +} + +void MoveTool::on_mouseup(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) +{ + if (event.button() != GUI::MouseButton::Left) + return; + m_layer_being_moved = nullptr; +} + +} diff --git a/Applications/PaintBrush/MoveTool.h b/Applications/PaintBrush/MoveTool.h new file mode 100644 index 0000000000000000000000000000000000000000..b4718dcb2bdaa224343512619d4fe592387a3cf7 --- /dev/null +++ b/Applications/PaintBrush/MoveTool.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "Tool.h" + +namespace PaintBrush { + +class MoveTool final : public Tool { +public: + MoveTool(); + virtual ~MoveTool() override; + + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + +private: + virtual const char* class_name() const override { return "MoveTool"; } + + RefPtr m_layer_being_moved; + Gfx::Point m_event_origin; + Gfx::Point m_layer_origin; +}; + +} diff --git a/Applications/PaintBrush/PenTool.cpp b/Applications/PaintBrush/PenTool.cpp index 2891bdba98450410addc00abc70c2c136b5e5af5..326db74100614b959ba9dc3c7df1f2056c3b898a 100644 --- a/Applications/PaintBrush/PenTool.cpp +++ b/Applications/PaintBrush/PenTool.cpp @@ -42,7 +42,7 @@ PenTool::~PenTool() { } -void PenTool::on_mousedown(Layer& layer, GUI::MouseEvent& event) +void PenTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right) return; @@ -53,13 +53,13 @@ void PenTool::on_mousedown(Layer& layer, GUI::MouseEvent& event) m_last_drawing_event_position = event.position(); } -void PenTool::on_mouseup(Layer&, GUI::MouseEvent& event) +void PenTool::on_mouseup(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() == GUI::MouseButton::Left || event.button() == GUI::MouseButton::Right) m_last_drawing_event_position = { -1, -1 }; } -void PenTool::on_mousemove(Layer& layer, GUI::MouseEvent& event) +void PenTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (!layer.rect().contains(event.position())) return; diff --git a/Applications/PaintBrush/PenTool.h b/Applications/PaintBrush/PenTool.h index b0c7c46f9a5eb0bc74685104244c790e8da0b55b..432410ba386ba8fd43e7097c16460c7c9f85516d 100644 --- a/Applications/PaintBrush/PenTool.h +++ b/Applications/PaintBrush/PenTool.h @@ -37,9 +37,9 @@ public: PenTool(); virtual ~PenTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; - virtual void on_mousemove(Layer&, GUI::MouseEvent&) override; - virtual void on_mouseup(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_contextmenu(GUI::ContextMenuEvent&) override; private: diff --git a/Applications/PaintBrush/PickerTool.cpp b/Applications/PaintBrush/PickerTool.cpp index 2994869dd8463915c5366a0b10cb1959ab1eb3d4..5af72c7935e7c1bc8592e291126f8c0f029507e9 100644 --- a/Applications/PaintBrush/PickerTool.cpp +++ b/Applications/PaintBrush/PickerTool.cpp @@ -39,7 +39,7 @@ PickerTool::~PickerTool() { } -void PickerTool::on_mousedown(Layer& layer, GUI::MouseEvent& event) +void PickerTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (!layer.rect().contains(event.position())) return; diff --git a/Applications/PaintBrush/PickerTool.h b/Applications/PaintBrush/PickerTool.h index 34e6afab247bbd988dbece755b914d92a32ee003..c9f682762e23f58fe8feb9bf48958ff42fe3634b 100644 --- a/Applications/PaintBrush/PickerTool.h +++ b/Applications/PaintBrush/PickerTool.h @@ -35,7 +35,7 @@ public: PickerTool(); virtual ~PickerTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; private: virtual const char* class_name() const override { return "PickerTool"; } diff --git a/Applications/PaintBrush/RectangleTool.cpp b/Applications/PaintBrush/RectangleTool.cpp index a7a30fa17abf5379a8ec85a6c4c4eba6c2adb0ed..d99a3e2de5ae12d5e7d33979a42039afd3820eeb 100644 --- a/Applications/PaintBrush/RectangleTool.cpp +++ b/Applications/PaintBrush/RectangleTool.cpp @@ -62,7 +62,7 @@ void RectangleTool::draw_using(GUI::Painter& painter) } } -void RectangleTool::on_mousedown(Layer&, GUI::MouseEvent& event) +void RectangleTool::on_mousedown(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right) return; @@ -76,7 +76,7 @@ void RectangleTool::on_mousedown(Layer&, GUI::MouseEvent& event) m_editor->update(); } -void RectangleTool::on_mouseup(Layer& layer, GUI::MouseEvent& event) +void RectangleTool::on_mouseup(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&) { if (event.button() == m_drawing_button) { GUI::Painter painter(layer.bitmap()); @@ -86,7 +86,7 @@ void RectangleTool::on_mouseup(Layer& layer, GUI::MouseEvent& event) } } -void RectangleTool::on_mousemove(Layer&, GUI::MouseEvent& event) +void RectangleTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (m_drawing_button == GUI::MouseButton::None) return; diff --git a/Applications/PaintBrush/RectangleTool.h b/Applications/PaintBrush/RectangleTool.h index 71871b4cb308027ec6847d20f6e98b8df9af0515..a34e3386b96c9de5137e267176eecbd5758e02eb 100644 --- a/Applications/PaintBrush/RectangleTool.h +++ b/Applications/PaintBrush/RectangleTool.h @@ -37,9 +37,9 @@ public: RectangleTool(); virtual ~RectangleTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; - virtual void on_mousemove(Layer&, GUI::MouseEvent&) override; - virtual void on_mouseup(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_contextmenu(GUI::ContextMenuEvent&) override; virtual void on_second_paint(GUI::PaintEvent&) override; virtual void on_keydown(GUI::KeyEvent&) override; diff --git a/Applications/PaintBrush/SprayTool.cpp b/Applications/PaintBrush/SprayTool.cpp index ff668002babe4b80cb5d0872384e9238b9f8e89f..5349ec3db5b6b00dc06fa276b726045b456280b0 100644 --- a/Applications/PaintBrush/SprayTool.cpp +++ b/Applications/PaintBrush/SprayTool.cpp @@ -82,7 +82,7 @@ void SprayTool::paint_it() } } -void SprayTool::on_mousedown(Layer&, GUI::MouseEvent& event) +void SprayTool::on_mousedown(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { if (!m_editor->rect().contains(event.position())) return; @@ -93,7 +93,7 @@ void SprayTool::on_mousedown(Layer&, GUI::MouseEvent& event) paint_it(); } -void SprayTool::on_mousemove(Layer&, GUI::MouseEvent& event) +void SprayTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) { m_last_pos = event.position(); if (m_timer->is_active()) { @@ -102,7 +102,7 @@ void SprayTool::on_mousemove(Layer&, GUI::MouseEvent& event) } } -void SprayTool::on_mouseup(Layer&, GUI::MouseEvent&) +void SprayTool::on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) { m_timer->stop(); } diff --git a/Applications/PaintBrush/SprayTool.h b/Applications/PaintBrush/SprayTool.h index d5e4564f9d01630118c9ddc302004480d451901d..5a4f2ba75b11af5e25dea823d6bb2f5a3946dcc7 100644 --- a/Applications/PaintBrush/SprayTool.h +++ b/Applications/PaintBrush/SprayTool.h @@ -38,9 +38,9 @@ public: SprayTool(); virtual ~SprayTool() override; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) override; - virtual void on_mouseup(Layer&, GUI::MouseEvent&) override; - virtual void on_mousemove(Layer&, GUI::MouseEvent&) override; + virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_contextmenu(GUI::ContextMenuEvent&) override; private: diff --git a/Applications/PaintBrush/Tool.h b/Applications/PaintBrush/Tool.h index 2ef8a0920c73bc7626d36b72210448917e8de68c..ddb4ce53153920fdff132f1f12b20d0ee70d0685 100644 --- a/Applications/PaintBrush/Tool.h +++ b/Applications/PaintBrush/Tool.h @@ -39,9 +39,9 @@ public: virtual const char* class_name() const = 0; - virtual void on_mousedown(Layer&, GUI::MouseEvent&) {} - virtual void on_mousemove(Layer&, GUI::MouseEvent&) {} - virtual void on_mouseup(Layer&, GUI::MouseEvent&) {} + virtual void on_mousedown(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) {} + virtual void on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) {} + virtual void on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) {} virtual void on_contextmenu(GUI::ContextMenuEvent&) {} virtual void on_second_paint(GUI::PaintEvent&) {} virtual void on_keydown(GUI::KeyEvent&) {} diff --git a/Applications/PaintBrush/ToolboxWidget.cpp b/Applications/PaintBrush/ToolboxWidget.cpp index 9dda50ea2f5cd4b8546256bd2c8d1d1fe65e3e47..b21b0d119079462cd1a9e8f4c94cf5142f954227 100644 --- a/Applications/PaintBrush/ToolboxWidget.cpp +++ b/Applications/PaintBrush/ToolboxWidget.cpp @@ -29,6 +29,7 @@ #include "EllipseTool.h" #include "EraseTool.h" #include "LineTool.h" +#include "MoveTool.h" #include "PaintableWidget.h" #include "PenTool.h" #include "PickerTool.h" @@ -92,6 +93,7 @@ ToolboxWidget::ToolboxWidget() }; }; + add_tool("Move", "move", make()); add_tool("Pen", "pen", make()); add_tool("Bucket Fill", "bucket", make()); add_tool("Spray", "spray", make());