From 15bf0948baee27ab23716a5d75130a7b076a1d88 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 30 Nov 2016 21:07:30 -0300 Subject: [PATCH] Add support to use rectangular marquee/lasso tools w/right click --- data/pref.xml | 2 ++ src/app/commands/cmd_options.cpp | 10 ++++++++++ src/app/tools/active_tool.cpp | 11 ++++++++++- src/app/tools/tool_box.cpp | 1 + src/app/tools/tool_box.h | 3 ++- src/app/ui/context_bar.cpp | 1 + src/app/ui/editor/editor.cpp | 28 +++++++++++++++++++--------- src/app/ui/editor/standby_state.cpp | 12 +++++++++++- 8 files changed, 56 insertions(+), 12 deletions(-) diff --git a/data/pref.xml b/data/pref.xml index 5fac43bdc..f484d658c 100644 --- a/data/pref.xml +++ b/data/pref.xml @@ -10,6 +10,8 @@ + + diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index a3ee62212..37a45e772 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -185,10 +185,20 @@ public: } // Right-click + + static_assert(int(app::gen::RightClickMode::PAINT_BGCOLOR) == 0, ""); + static_assert(int(app::gen::RightClickMode::PICK_FGCOLOR) == 1, ""); + static_assert(int(app::gen::RightClickMode::ERASE) == 2, ""); + static_assert(int(app::gen::RightClickMode::SCROLL) == 3, ""); + static_assert(int(app::gen::RightClickMode::RECTANGULAR_MARQUEE) == 4, ""); + static_assert(int(app::gen::RightClickMode::LASSO) == 5, ""); + rightClickBehavior()->addItem("Paint with background color"); rightClickBehavior()->addItem("Pick foreground color"); rightClickBehavior()->addItem("Erase"); rightClickBehavior()->addItem("Scroll"); + rightClickBehavior()->addItem("Rectangular Marquee"); + rightClickBehavior()->addItem("Lasso"); rightClickBehavior()->setSelectedItemIndex((int)m_pref.editor.rightClickMode()); // Zoom with Scroll Wheel diff --git a/src/app/tools/active_tool.cpp b/src/app/tools/active_tool.cpp index 74e52ae3e..6be05dc07 100644 --- a/src/app/tools/active_tool.cpp +++ b/src/app/tools/active_tool.cpp @@ -177,6 +177,14 @@ void ActiveToolManager::pressButton(const Pointer& pointer) tool = m_toolbox->getToolById(WellKnownTools::Hand); ink = m_toolbox->getInkById(tools::WellKnownInks::Scroll); break; + case app::gen::RightClickMode::RECTANGULAR_MARQUEE: + tool = m_toolbox->getToolById(WellKnownTools::RectangularMarquee); + ink = m_toolbox->getInkById(tools::WellKnownInks::Selection); + break; + case app::gen::RightClickMode::LASSO: + tool = m_toolbox->getToolById(WellKnownTools::Lasso); + ink = m_toolbox->getInkById(tools::WellKnownInks::Selection); + break; } } } @@ -212,7 +220,8 @@ bool ActiveToolManager::isToolAffectedByRightClickMode(Tool* tool) return ((tool->getInk(0)->isPaint() && !shadingMode) || (tool->getInk(0)->isEffect())) && - (!tool->getInk(0)->isEraser()); + (!tool->getInk(0)->isEraser()) && + (!tool->getInk(0)->isSelection()); } } // namespace tools diff --git a/src/app/tools/tool_box.cpp b/src/app/tools/tool_box.cpp index 0bec93fc2..52ba1d328 100644 --- a/src/app/tools/tool_box.cpp +++ b/src/app/tools/tool_box.cpp @@ -42,6 +42,7 @@ namespace tools { using namespace gfx; const char* WellKnownTools::RectangularMarquee = "rectangular_marquee"; +const char* WellKnownTools::Lasso = "lasso"; const char* WellKnownTools::Pencil = "pencil"; const char* WellKnownTools::Eraser = "eraser"; const char* WellKnownTools::Eyedropper = "eyedropper"; diff --git a/src/app/tools/tool_box.h b/src/app/tools/tool_box.h index 025b85d9e..b0bc9b51a 100644 --- a/src/app/tools/tool_box.h +++ b/src/app/tools/tool_box.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -22,6 +22,7 @@ namespace app { namespace WellKnownTools { extern const char* RectangularMarquee; + extern const char* Lasso; extern const char* Pencil; extern const char* Eraser; extern const char* Eyedropper; diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index fdbdbb2ad..8319d2af6 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -1195,6 +1195,7 @@ public: } void setupTooltips(TooltipManager* tooltipManager) { + // TODO use real shortcuts in tooltips tooltipManager->addTooltipFor(at(0), "Replace selection", BOTTOM); tooltipManager->addTooltipFor(at(1), "Add to selection\n(Shift)", BOTTOM); tooltipManager->addTooltipFor(at(2), "Subtract from selection\n(Shift+Alt)", BOTTOM); diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 7fa8139a1..807a8d3fa 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1165,10 +1165,17 @@ void Editor::updateToolLoopModifiersIndicators() action = m_customizationDelegate->getPressedKeyAction(KeyContext::SelectionTool); gen::SelectionMode mode = Preferences::instance().selection.mode(); - if (int(action & KeyAction::AddSelection)) - mode = gen::SelectionMode::ADD; - if (int(action & KeyAction::SubtractSelection) || m_secondaryButton) + if (int(action & KeyAction::SubtractSelection) || + // Don't use "subtract" mode if the selection was activated + // with the "right click mode = a selection-like tool" + (m_secondaryButton && + App::instance()->activeToolManager()->selectedTool() && + App::instance()->activeToolManager()->selectedTool()->getInk(0)->isSelection())) { mode = gen::SelectionMode::SUBTRACT; + } + else if (int(action & KeyAction::AddSelection)) { + mode = gen::SelectionMode::ADD; + } switch (mode) { case gen::SelectionMode::DEFAULT: modifiers |= int(tools::ToolLoopModifiers::kReplaceSelection); break; case gen::SelectionMode::ADD: modifiers |= int(tools::ToolLoopModifiers::kAddSelection); break; @@ -1260,14 +1267,17 @@ bool Editor::onProcessMessage(Message* msg) m_oldPos = mouseMsg->position(); updateToolByTipProximity(mouseMsg->pointerType()); - if (!m_secondaryButton && mouseMsg->right()) { - m_secondaryButton = mouseMsg->right(); - - updateToolLoopModifiersIndicators(); - updateQuicktool(); - setCursor(mouseMsg->position()); + // Only when we right-click with the regular "paint bg-color + // right-click mode" we will mark indicate that the secondary + // button was used (m_secondaryButton == true). + if (mouseMsg->right() && !m_secondaryButton) { + m_secondaryButton = true; } + updateToolLoopModifiersIndicators(); + updateQuicktool(); + setCursor(mouseMsg->position()); + App::instance()->activeToolManager() ->pressButton(pointer_from_msg(this, mouseMsg)); diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index decfea121..4ca6252c5 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -18,6 +18,7 @@ #include "app/document_range.h" #include "app/ini_file.h" #include "app/pref/preferences.h" +#include "app/tools/active_tool.h" #include "app/tools/ink.h" #include "app/tools/pick_ink.h" #include "app/tools/tool.h" @@ -244,7 +245,16 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg) return true; } - if (clickedInk->isSelection()) { + // Only if the selected tool or quick tool is selection, we give the + // possibility to transform/move the selection. In other case, + // e.g. when selection is used with right-click mode, the + // transformation is disabled. + auto activeToolManager = App::instance()->activeToolManager(); + if (clickedInk->isSelection() && + ((activeToolManager->selectedTool() && + activeToolManager->selectedTool()->getInk(0)->isSelection()) || + (activeToolManager->quickTool() && + activeToolManager->quickTool()->getInk(0)->isSelection()))) { // Transform selected pixels if (editor->isActive() && document->isMaskVisible() &&