From 9eadd740b86db8aa1a57cb60b190322f1c75d18c Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 19 Nov 2024 14:05:13 -0300 Subject: [PATCH] Disable tool changes when we're previewing a filter In this way the user cannot use Ctrl key to try to move a cel and get an error that the sprite is locked so we cannot move the cel. Actually we shouldn't be able to move the cel when we're using the Editor for preview purposes (FilterWindow / WindowWithHand). This issue was reported in #4465, and created for the new Dialog:show{hand=true} API mainly. --- src/app/tools/active_tool.cpp | 20 ++++++++++++++------ src/app/tools/active_tool.h | 7 +++++++ src/app/ui/window_with_hand.cpp | 10 ++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/app/tools/active_tool.cpp b/src/app/tools/active_tool.cpp index 021df9aca..9fdf8c6fa 100644 --- a/src/app/tools/active_tool.cpp +++ b/src/app/tools/active_tool.cpp @@ -47,6 +47,7 @@ private: ActiveToolManager::ActiveToolManager(ToolBox* toolbox) : m_toolbox(toolbox) , m_quickTool(nullptr) + , m_allowQuickToolChanges(true) , m_rightClick(false) , m_rightClickTool(nullptr) , m_rightClickInk(nullptr) @@ -57,14 +58,16 @@ ActiveToolManager::ActiveToolManager(ToolBox* toolbox) Tool* ActiveToolManager::activeTool() const { - if (m_quickTool) - return m_quickTool; + if (m_allowQuickToolChanges) { + if (m_quickTool) + return m_quickTool; - if (m_rightClickTool) - return m_rightClickTool; + if (m_rightClickTool) + return m_rightClickTool; - if (m_proximityTool) - return m_proximityTool; + if (m_proximityTool) + return m_proximityTool; + } // Active tool should never returns null ASSERT(m_selectedTool); @@ -234,6 +237,11 @@ void ActiveToolManager::setSelectedTool(Tool* tool) notify_observers(&ActiveToolObserver::onSelectedToolChange, tool); } +void ActiveToolManager::setAllowQuickToolChanges(const bool state) +{ + m_allowQuickToolChanges = state; +} + // static bool ActiveToolManager::isToolAffectedByRightClickMode(Tool* tool) { diff --git a/src/app/tools/active_tool.h b/src/app/tools/active_tool.h index ed71958ff..4ff8435c8 100644 --- a/src/app/tools/active_tool.h +++ b/src/app/tools/active_tool.h @@ -54,6 +54,8 @@ public: const InkType inkType, const app::Color& color) const; + void setAllowQuickToolChanges(bool state); + private: static bool isToolAffectedByRightClickMode(Tool* tool); @@ -63,6 +65,11 @@ private: // shortuts). Tool* m_quickTool; + // This can be disable temporarily in case we want to use an Editor + // in "preview only mode" (e.g. when we're previewing a filter we + // want to disable the Ctrl key to change to the Move tool). + bool m_allowQuickToolChanges; + // Special tool by stylus proximity. bool m_rightClick; Tool* m_rightClickTool; diff --git a/src/app/ui/window_with_hand.cpp b/src/app/ui/window_with_hand.cpp index b890a03bd..f2adc14d9 100644 --- a/src/app/ui/window_with_hand.cpp +++ b/src/app/ui/window_with_hand.cpp @@ -11,6 +11,7 @@ #include "app/ui/window_with_hand.h" #include "app/app.h" +#include "app/tools/active_tool.h" #include "app/tools/tool_box.h" #include "app/ui/context_bar.h" #include "app/ui/editor/editor.h" @@ -30,11 +31,14 @@ WindowWithHand::~WindowWithHand() void WindowWithHand::enableHandTool(const bool state) { + auto* atm = App::instance()->activeToolManager(); + if (m_editor) { m_editor->remove_observer(this); m_editor = nullptr; } if (m_oldTool) { + atm->setAllowQuickToolChanges(true); ToolBar::instance()->selectTool(m_oldTool); m_oldTool = nullptr; } @@ -43,7 +47,13 @@ void WindowWithHand::enableHandTool(const bool state) if (state && editor) { m_editor = editor; m_editor->add_observer(this); + + // Disable quick tools like Ctrl to select the Move tool and move + // cels, or Alt for eyedropper. We just want the Hand tool + // (selected tool) for preview purposes. + atm->setAllowQuickToolChanges(false); m_oldTool = m_editor->getCurrentEditorTool(); + tools::Tool* hand = App::instance()->toolBox()->getToolById(tools::WellKnownTools::Hand); ToolBar::instance()->selectTool(hand); }