From dd0cc58d6c2a0a2855341060556c2df6b47cf27f Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 11 Sep 2021 23:26:09 -0400 Subject: [PATCH] PixelPaint: Allow panning when right-clicking with MoveTool The MoveTool now lets you pan if you're dragging with a right click. Previously, right-clicking did not perform any actions at all, so this isn't removing any old functionality. --- Userland/Applications/PixelPaint/MoveTool.cpp | 23 +++++++++++++++++++ Userland/Applications/PixelPaint/MoveTool.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/Userland/Applications/PixelPaint/MoveTool.cpp b/Userland/Applications/PixelPaint/MoveTool.cpp index 54af91a280..59bcbb578a 100644 --- a/Userland/Applications/PixelPaint/MoveTool.cpp +++ b/Userland/Applications/PixelPaint/MoveTool.cpp @@ -25,6 +25,14 @@ MoveTool::~MoveTool() void MoveTool::on_mousedown(Layer* layer, MouseEvent& event) { + if (event.image_event().button() == GUI::MouseButton::Right && !m_is_panning) { + m_is_panning = true; + m_event_origin = event.raw_event().position(); + m_saved_pan_origin = m_editor->pan_origin(); + m_editor->set_override_cursor(Gfx::StandardCursor::Drag); + return; + } + if (!layer) return; @@ -41,6 +49,15 @@ void MoveTool::on_mousedown(Layer* layer, MouseEvent& event) void MoveTool::on_mousemove(Layer* layer, MouseEvent& event) { + if (m_is_panning) { + auto& raw_event = event.raw_event(); + auto delta = raw_event.position() - m_event_origin; + m_editor->set_pan_origin(m_saved_pan_origin.translated( + -delta.x(), + -delta.y())); + return; + } + if (!layer) return; @@ -54,6 +71,12 @@ void MoveTool::on_mousemove(Layer* layer, MouseEvent& event) void MoveTool::on_mouseup(Layer* layer, MouseEvent& event) { + if (event.image_event().button() == GUI::MouseButton::Right && m_is_panning) { + m_is_panning = false; + m_editor->set_override_cursor(cursor()); + return; + } + if (!layer) return; diff --git a/Userland/Applications/PixelPaint/MoveTool.h b/Userland/Applications/PixelPaint/MoveTool.h index 50a48163cd..93631ff077 100644 --- a/Userland/Applications/PixelPaint/MoveTool.h +++ b/Userland/Applications/PixelPaint/MoveTool.h @@ -25,6 +25,9 @@ private: RefPtr m_layer_being_moved; Gfx::IntPoint m_event_origin; Gfx::IntPoint m_layer_origin; + + bool m_is_panning { false }; + Gfx::FloatPoint m_saved_pan_origin; }; }