Add support to use rectangular marquee/lasso tools w/right click

This commit is contained in:
David Capello 2016-11-30 21:07:30 -03:00
parent 3b7f48224c
commit 15bf0948ba
8 changed files with 56 additions and 12 deletions

View File

@ -10,6 +10,8 @@
<value id="PICK_FGCOLOR" value="1" />
<value id="ERASE" value="2" />
<value id="SCROLL" value="3" />
<value id="RECTANGULAR_MARQUEE" value="4" />
<value id="LASSO" value="5" />
</enum>
<enum id="OnionskinType">
<value id="MERGE" value="0" />

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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() &&