Add possibility to hold tool modifiers when we start drawing on kMouseDownMessage (fix #2537)

E.g. In this way we can press the Shift modifier, then press the mouse
button to start drawing successive straight lines with the angle
snapped (so there is no need to release/press the Shift modifier again
and again).
This commit is contained in:
David Capello 2020-12-14 14:49:16 -03:00
parent 81d9e8afec
commit 21e893162d
2 changed files with 22 additions and 4 deletions

View File

@ -1536,7 +1536,7 @@ void Editor::updateToolByTipProximity(ui::PointerType pointerType)
}
}
void Editor::updateToolLoopModifiersIndicators()
void Editor::updateToolLoopModifiersIndicators(const bool firstFromMouseDown)
{
int modifiers = int(tools::ToolLoopModifiers::kNone);
const bool autoSelectLayer = isAutoSelectLayer();
@ -1569,7 +1569,13 @@ void Editor::updateToolLoopModifiersIndicators()
modifiers |= int(tools::ToolLoopModifiers::kSquareAspect);
if (int(action & KeyAction::DrawFromCenter))
modifiers |= int(tools::ToolLoopModifiers::kFromCenter);
if (int(action & KeyAction::RotateShape))
// We prefer to activate the rotation only when the user press
// the Alt key again in the ToolLoop (and not before starting
// the loop). So Alt+Shift+selection tool will subtract the
// selection but will not start the rotation until we release
// and press the Alt key again.
if ((int(action & KeyAction::RotateShape)) && !firstFromMouseDown)
modifiers |= int(tools::ToolLoopModifiers::kRotateShape);
}
@ -1800,7 +1806,16 @@ bool Editor::onProcessMessage(Message* msg)
->pressButton(pointer_from_msg(this, mouseMsg));
EditorStatePtr holdState(m_state);
return m_state->onMouseDown(this, mouseMsg);
bool state = m_state->onMouseDown(this, mouseMsg);
// Re-update the tool modifiers if the state has changed
// (e.g. we are on DrawingState now). This is required for the
// Line tool to be able to Shift+press mouse buttons to start
// drawing lines with the angle snapped.
if (m_state != holdState)
updateToolLoopModifiersIndicators(true);
return state;
}
break;

View File

@ -334,7 +334,10 @@ namespace app {
void setStateInternal(const EditorStatePtr& newState);
void updateQuicktool();
void updateToolByTipProximity(ui::PointerType pointerType);
void updateToolLoopModifiersIndicators();
// firstFromMouseDown=true when we call this function from the
// first MouseDown message (instead of KeyDown).
void updateToolLoopModifiersIndicators(const bool firstFromMouseDown = false);
void drawBackground(ui::Graphics* g);
void drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc);