Add extra KeyContexts for each selection transformation

This commit is contained in:
David Capello 2015-09-11 20:04:02 -03:00
parent adce0b9569
commit 74e642d997
8 changed files with 71 additions and 26 deletions

View File

@ -327,14 +327,20 @@ private:
for (Key* key : *app::KeyboardShortcuts::instance()) { for (Key* key : *app::KeyboardShortcuts::instance()) {
std::string text = key->triggerString(); std::string text = key->triggerString();
switch (key->keycontext()) { switch (key->keycontext()) {
case KeyContext::Selection: case KeyContext::SelectionTool:
text = "Selection context: " + text; text = "Selection Tool: " + text;
break; break;
case KeyContext::MovingPixels: case KeyContext::TranslatingSelection:
text = "Moving pixels context: " + text; text = "Translating Selection: " + text;
break;
case KeyContext::ScalingSelection:
text = "Scaling Selection: " + text;
break;
case KeyContext::RotatingSelection:
text = "Rotating Selection: " + text;
break; break;
case KeyContext::MoveTool: case KeyContext::MoveTool:
text = "Move tool: " + text; text = "Move Tool: " + text;
break; break;
} }
KeyItem* keyItem = new KeyItem(text, key, NULL, 0); KeyItem* keyItem = new KeyItem(text, key, NULL, 0);

View File

@ -1072,7 +1072,7 @@ void Editor::updateQuicktool()
// Don't change quicktools if we are in a selection tool and using // Don't change quicktools if we are in a selection tool and using
// the selection modifiers. // the selection modifiers.
if (current_tool->getInk(0)->isSelection() && if (current_tool->getInk(0)->isSelection() &&
int(m_customizationDelegate->getPressedKeyAction(KeyContext::Selection)) != 0) int(m_customizationDelegate->getPressedKeyAction(KeyContext::SelectionTool)) != 0)
return; return;
tools::Tool* old_quicktool = m_quicktool; tools::Tool* old_quicktool = m_quicktool;
@ -1126,7 +1126,7 @@ void Editor::updateContextBarFromModifiers()
KeyAction action = KeyAction::None; KeyAction action = KeyAction::None;
if (m_customizationDelegate) if (m_customizationDelegate)
action = m_customizationDelegate->getPressedKeyAction(KeyContext::Selection); action = m_customizationDelegate->getPressedKeyAction(KeyContext::SelectionTool);
if (int(action & KeyAction::AddSelection)) if (int(action & KeyAction::AddSelection))
mode = tools::SelectionMode::ADD; mode = tools::SelectionMode::ADD;

View File

@ -129,7 +129,8 @@ bool MovingCelState::onMouseMove(Editor* editor, MouseMessage* msg)
gfx::Point newCursorPos = editor->screenToEditor(msg->position()); gfx::Point newCursorPos = editor->screenToEditor(msg->position());
gfx::Point delta = newCursorPos - m_mouseStart; gfx::Point delta = newCursorPos - m_mouseStart;
if (int(editor->getCustomizationDelegate()->getPressedKeyAction(KeyContext::MovingPixels) & KeyAction::LockAxis)) { if (int(editor->getCustomizationDelegate()
->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::LockAxis)) {
if (ABS(delta.x) < ABS(delta.y)) { if (ABS(delta.x) < ABS(delta.y)) {
delta.x = 0; delta.x = 0;
} }

View File

@ -264,7 +264,7 @@ bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg)
// In case that the user is pressing the copy-selection keyboard shortcut. // In case that the user is pressing the copy-selection keyboard shortcut.
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
if ((customization) && if ((customization) &&
int(customization->getPressedKeyAction(KeyContext::MovingPixels) & KeyAction::CopySelection)) { int(customization->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::CopySelection)) {
// Stamp the pixels to create the copy. // Stamp the pixels to create the copy.
m_pixelsMovement->stampImage(); m_pixelsMovement->stampImage();
} }
@ -315,8 +315,36 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg)
gfx::Point spritePos = editor->screenToEditor(mousePos); gfx::Point spritePos = editor->screenToEditor(mousePos);
// Get the customization for the pixels movement (snap to grid, angle snap, etc.). // Get the customization for the pixels movement (snap to grid, angle snap, etc.).
KeyContext keyContext = KeyContext::Normal;
switch (m_pixelsMovement->handle()) {
case MoveHandle:
keyContext = KeyContext::TranslatingSelection;
break;
case ScaleNWHandle:
case ScaleNHandle:
case ScaleNEHandle:
case ScaleWHandle:
case ScaleEHandle:
case ScaleSWHandle:
case ScaleSHandle:
case ScaleSEHandle:
keyContext = KeyContext::ScalingSelection;
break;
case RotateNWHandle:
case RotateNHandle:
case RotateNEHandle:
case RotateWHandle:
case RotateEHandle:
case RotateSWHandle:
case RotateSHandle:
case RotateSEHandle:
keyContext = KeyContext::RotatingSelection;
break;
}
PixelsMovement::MoveModifier moveModifier = PixelsMovement::NormalMovement; PixelsMovement::MoveModifier moveModifier = PixelsMovement::NormalMovement;
KeyAction action = editor->getCustomizationDelegate()->getPressedKeyAction(KeyContext::MovingPixels); KeyAction action = editor->getCustomizationDelegate()
->getPressedKeyAction(keyContext);
if (int(action & KeyAction::SnapToGrid)) if (int(action & KeyAction::SnapToGrid))
moveModifier |= PixelsMovement::SnapToGridMovement; moveModifier |= PixelsMovement::SnapToGridMovement;

View File

@ -54,6 +54,8 @@ namespace app {
const char* operationName); const char* operationName);
~PixelsMovement(); ~PixelsMovement();
HandleType handle() const { return m_handle; }
void cutMask(); void cutMask();
void copyMask(); void copyMask();
void catchImage(const gfx::Point& pos, HandleType handle); void catchImage(const gfx::Point& pos, HandleType handle);

View File

@ -316,7 +316,7 @@ bool StandbyState::onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos)
if (editor->isInsideSelection()) { if (editor->isInsideSelection()) {
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
if ((customization) && if ((customization) &&
int(customization->getPressedKeyAction(KeyContext::MovingPixels) & KeyAction::CopySelection)) int(customization->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::CopySelection))
editor->showMouseCursor(kArrowPlusCursor); editor->showMouseCursor(kArrowPlusCursor);
else else
editor->showMouseCursor(kMoveCursor); editor->showMouseCursor(kMoveCursor);
@ -453,7 +453,7 @@ void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleT
// If the Ctrl key is pressed start dragging a copy of the selection // If the Ctrl key is pressed start dragging a copy of the selection
if ((customization) && if ((customization) &&
int(customization->getPressedKeyAction(KeyContext::MovingPixels) & KeyAction::CopySelection)) int(customization->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::CopySelection))
pixelsMovement->copyMask(); pixelsMovement->copyMask();
else else
pixelsMovement->cutMask(); pixelsMovement->cutMask();

View File

@ -135,25 +135,25 @@ Key::Key(KeyAction action)
m_keycontext = KeyContext::Any; m_keycontext = KeyContext::Any;
break; break;
case KeyAction::CopySelection: case KeyAction::CopySelection:
m_keycontext = KeyContext::MovingPixels; m_keycontext = KeyContext::TranslatingSelection;
break; break;
case KeyAction::SnapToGrid: case KeyAction::SnapToGrid:
m_keycontext = KeyContext::MovingPixels; m_keycontext = KeyContext::TranslatingSelection;
break; break;
case KeyAction::AngleSnap: case KeyAction::AngleSnap:
m_keycontext = KeyContext::MovingPixels; m_keycontext = KeyContext::RotatingSelection;
break; break;
case KeyAction::MaintainAspectRatio: case KeyAction::MaintainAspectRatio:
m_keycontext = KeyContext::MovingPixels; m_keycontext = KeyContext::ScalingSelection;
break; break;
case KeyAction::LockAxis: case KeyAction::LockAxis:
m_keycontext = KeyContext::MovingPixels; m_keycontext = KeyContext::TranslatingSelection;
break; break;
case KeyAction::AddSelection: case KeyAction::AddSelection:
m_keycontext = KeyContext::Selection; m_keycontext = KeyContext::SelectionTool;
break; break;
case KeyAction::SubtractSelection: case KeyAction::SubtractSelection:
m_keycontext = KeyContext::Selection; m_keycontext = KeyContext::SelectionTool;
break; break;
case KeyAction::AutoSelectLayer: case KeyAction::AutoSelectLayer:
m_keycontext = KeyContext::MoveTool; m_keycontext = KeyContext::MoveTool;
@ -316,7 +316,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
const char* keycontextstr = xmlKey->Attribute("context"); const char* keycontextstr = xmlKey->Attribute("context");
if (keycontextstr) { if (keycontextstr) {
if (strcmp(keycontextstr, "Selection") == 0) if (strcmp(keycontextstr, "Selection") == 0)
keycontext = KeyContext::Selection; keycontext = KeyContext::SelectionTool;
else if (strcmp(keycontextstr, "Normal") == 0) else if (strcmp(keycontextstr, "Normal") == 0)
keycontext = KeyContext::Normal; keycontext = KeyContext::Normal;
} }
@ -518,11 +518,17 @@ void KeyboardShortcuts::exportAccel(TiXmlElement& parent, Key* key, const ui::Ac
case KeyContext::Normal: case KeyContext::Normal:
keycontextStr = "Normal"; keycontextStr = "Normal";
break; break;
case KeyContext::Selection: case KeyContext::SelectionTool:
keycontextStr = "Selection"; keycontextStr = "Selection";
break; break;
case KeyContext::MovingPixels: case KeyContext::TranslatingSelection:
keycontextStr = "MovingPixels"; keycontextStr = "TranslatingSelection";
break;
case KeyContext::ScalingSelection:
keycontextStr = "ScalingSelection";
break;
case KeyContext::RotatingSelection:
keycontextStr = "RotatingSelection";
break; break;
case KeyContext::MoveTool: case KeyContext::MoveTool:
keycontextStr = "MoveTool"; keycontextStr = "MoveTool";
@ -646,7 +652,7 @@ KeyContext KeyboardShortcuts::getCurrentKeyContext()
if (doc && if (doc &&
doc->isMaskVisible() && doc->isMaskVisible() &&
App::instance()->activeTool()->getInk(0)->isSelection()) App::instance()->activeTool()->getInk(0)->isSelection())
return KeyContext::Selection; return KeyContext::SelectionTool;
else else
return KeyContext::Normal; return KeyContext::Normal;
} }

View File

@ -33,8 +33,10 @@ namespace app {
enum class KeyContext { enum class KeyContext {
Any, Any,
Normal, Normal,
Selection, SelectionTool,
MovingPixels, TranslatingSelection,
ScalingSelection,
RotatingSelection,
MoveTool, MoveTool,
}; };