From 068ca3a394d85025aa3e63feec6bd265a866cc6a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 14 Jun 2021 18:06:50 +0200 Subject: [PATCH] PixelPaint: Always animate marching ants during interactive selection The Selection object now tracks whether there is an ongoing interactive selection (originating from one of the selection tools). If so it makes sure to pump the marching ants animation. --- Userland/Applications/PixelPaint/RectangleSelectTool.cpp | 4 ++++ Userland/Applications/PixelPaint/Selection.cpp | 2 +- Userland/Applications/PixelPaint/Selection.h | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp index 832765dc2d8..a7a52e0bb24 100644 --- a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp +++ b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp @@ -25,6 +25,8 @@ void RectangleSelectTool::on_mousedown(Layer&, GUI::MouseEvent&, GUI::MouseEvent return; m_selecting = true; + m_editor->selection().begin_interactive_selection(); + m_selection_start = image_event.position(); m_selection_end = image_event.position(); m_editor->update(); @@ -45,6 +47,8 @@ void RectangleSelectTool::on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent& return; m_selecting = false; + m_editor->selection().end_interactive_selection(); + m_editor->update(); auto rect_in_image = Gfx::IntRect::from_two_points(m_selection_start, m_selection_end); diff --git a/Userland/Applications/PixelPaint/Selection.cpp b/Userland/Applications/PixelPaint/Selection.cpp index 6e645e9ddb2..7bdef9d97db 100644 --- a/Userland/Applications/PixelPaint/Selection.cpp +++ b/Userland/Applications/PixelPaint/Selection.cpp @@ -23,7 +23,7 @@ Selection::Selection(ImageEditor& editor) m_marching_ants_timer = Core::Timer::create_repeating(80, [this] { ++m_marching_ants_offset; m_marching_ants_offset %= marching_ant_length; - if (!is_empty()) + if (!is_empty() || m_in_interactive_selection) m_editor.update(); }); m_marching_ants_timer->start(); diff --git a/Userland/Applications/PixelPaint/Selection.h b/Userland/Applications/PixelPaint/Selection.h index 9c73f4f29ae..443e85d515d 100644 --- a/Userland/Applications/PixelPaint/Selection.h +++ b/Userland/Applications/PixelPaint/Selection.h @@ -27,11 +27,15 @@ public: void draw_marching_ants(Gfx::Painter&, Gfx::IntRect const&) const; + void begin_interactive_selection() { m_in_interactive_selection = true; } + void end_interactive_selection() { m_in_interactive_selection = false; } + private: ImageEditor& m_editor; Gfx::IntRect m_rect; RefPtr m_marching_ants_timer; int m_marching_ants_offset { 0 }; + bool m_in_interactive_selection { false }; }; }