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.
This commit is contained in:
David Capello 2024-11-19 14:05:13 -03:00
parent 21565a9349
commit 9eadd740b8
3 changed files with 31 additions and 6 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -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);
}