mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 21:46:20 +00:00
Fix keyboard shortcuts with Shift+ key when pencil tool is active
This commit is contained in:
parent
40136e5074
commit
7323f1d071
@ -39,14 +39,19 @@ namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
DrawingState::DrawingState(tools::ToolLoop* toolLoop,
|
||||
DrawingState::DrawingState(Editor* editor,
|
||||
tools::ToolLoop* toolLoop,
|
||||
const DrawingType type)
|
||||
: m_type(type)
|
||||
: m_editor(editor)
|
||||
, m_type(type)
|
||||
, m_toolLoop(toolLoop)
|
||||
, m_toolLoopManager(new tools::ToolLoopManager(toolLoop))
|
||||
, m_mouseMoveReceived(false)
|
||||
, m_mousePressedReceived(false)
|
||||
{
|
||||
m_beforeCmdConn =
|
||||
UIContext::instance()->BeforeCommandExecution.connect(
|
||||
&DrawingState::onBeforeCommandExecution, this);
|
||||
}
|
||||
|
||||
DrawingState::~DrawingState()
|
||||
@ -92,6 +97,9 @@ bool DrawingState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||
// Drawing loop
|
||||
ASSERT(m_toolLoopManager != NULL);
|
||||
|
||||
if (!editor->hasCapture())
|
||||
editor->captureMouse();
|
||||
|
||||
m_mousePressedReceived = true;
|
||||
|
||||
// Notify the mouse button down to the tool loop manager.
|
||||
@ -180,12 +188,15 @@ bool DrawingState::onKeyDown(Editor* editor, KeyMessage* msg)
|
||||
if (KeyboardShortcuts::instance()
|
||||
->getCommandFromKeyMessage(msg, &command, ¶ms)) {
|
||||
// We accept zoom commands.
|
||||
if (command->id() == CommandId::Zoom)
|
||||
if (command->id() == CommandId::Zoom) {
|
||||
UIContext::instance()->executeCommand(command, params);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// When we are drawing, we "eat" all pressed keys.
|
||||
return true;
|
||||
// Return true when we cannot execute commands (true = the onKeyDown
|
||||
// event was used, so the key is not used to run a command).
|
||||
return !canExecuteCommands();
|
||||
}
|
||||
|
||||
bool DrawingState::onKeyUp(Editor* editor, KeyMessage* msg)
|
||||
@ -218,6 +229,25 @@ void DrawingState::onExposeSpritePixels(const gfx::Region& rgn)
|
||||
m_toolLoop->validateDstImage(rgn);
|
||||
}
|
||||
|
||||
bool DrawingState::canExecuteCommands()
|
||||
{
|
||||
// Returning true here means that the user can trigger commands with
|
||||
// keyboard shortcuts. In our case we want to be able to use
|
||||
// keyboard shortcuts only when the Shift key was pressed to run a
|
||||
// command (e.g. Shift+N), not to draw a straight line from the
|
||||
// pencil (freehand) tool.
|
||||
return (m_type == DrawingType::LineFreehand &&
|
||||
!m_mousePressedReceived);
|
||||
}
|
||||
|
||||
void DrawingState::onBeforeCommandExecution(CommandExecutionEvent& cmd)
|
||||
{
|
||||
if (canExecuteCommands() && m_toolLoop) {
|
||||
m_toolLoop->cancel();
|
||||
destroyLoopIfCanceled(m_editor);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawingState::destroyLoopIfCanceled(Editor* editor)
|
||||
{
|
||||
// Cancel drawing loop
|
||||
|
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/ui/editor/standby_state.h"
|
||||
#include "obs/connection.h"
|
||||
|
||||
namespace app {
|
||||
namespace tools {
|
||||
@ -17,9 +18,12 @@ namespace app {
|
||||
class ToolLoopManager;
|
||||
}
|
||||
|
||||
class CommandExecutionEvent;
|
||||
|
||||
class DrawingState : public StandbyState {
|
||||
public:
|
||||
DrawingState(tools::ToolLoop* loop,
|
||||
DrawingState(Editor* editor,
|
||||
tools::ToolLoop* loop,
|
||||
const DrawingType type);
|
||||
virtual ~DrawingState();
|
||||
virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
|
||||
@ -45,9 +49,12 @@ namespace app {
|
||||
void notifyToolLoopModifiersChange(Editor* editor);
|
||||
|
||||
private:
|
||||
bool canExecuteCommands();
|
||||
void onBeforeCommandExecution(CommandExecutionEvent& cmd);
|
||||
void destroyLoopIfCanceled(Editor* editor);
|
||||
void destroyLoop(Editor* editor);
|
||||
|
||||
Editor* m_editor;
|
||||
DrawingType m_type;
|
||||
|
||||
// The tool-loop.
|
||||
@ -71,6 +78,8 @@ namespace app {
|
||||
// Shift press is used to draw a line, but then released without a
|
||||
// mouse click.
|
||||
bool m_mousePressedReceived;
|
||||
|
||||
obs::scoped_connection m_beforeCmdConn;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -596,7 +596,8 @@ DrawingState* StandbyState::startDrawingState(Editor* editor,
|
||||
return nullptr;
|
||||
|
||||
EditorStatePtr newState(
|
||||
new DrawingState(toolLoop,
|
||||
new DrawingState(editor,
|
||||
toolLoop,
|
||||
drawingType));
|
||||
editor->setState(newState);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user