Add Ctrl modifier to Shift+pencil to enable angle snap (#1387)

This commit is contained in:
David Capello 2017-06-22 17:47:56 -03:00
parent 85b7996e9a
commit 8d693d1a08
8 changed files with 38 additions and 21 deletions

View File

@ -523,6 +523,7 @@
<!-- Modifiers for freehand tool controller -->
<key action="StraightLineFromLastPoint" shortcut="Shift" />
<key action="AngleSnapFromLastPoint" shortcut="Ctrl" />
<!-- Modifiers for two-points tool controller -->
<key action="SquareAspect" shortcut="Shift" />

View File

@ -28,6 +28,7 @@ namespace app {
virtual bool canSnapToGrid() { return true; }
virtual bool isFreehand() { return false; }
virtual bool isOnePoint() { return false; }
virtual bool isTwoPoints() { return false; }
virtual void prepareController(ToolLoop* loop) { }

View File

@ -99,9 +99,7 @@ private:
// Controls clicks for tools like line
class TwoPointsController : public MoveOriginCapability {
public:
TwoPointsController(const bool enableModifiers)
: m_enableModifiers(enableModifiers) {
}
bool isTwoPoints() override { return true; }
void pressButton(Stroke& stroke, const Point& point) override {
MoveOriginCapability::pressButton(stroke, point);
@ -126,8 +124,7 @@ public:
stroke[1] = point;
if (m_enableModifiers &&
(int(loop->getModifiers()) & int(ToolLoopModifiers::kSquareAspect))) {
if ((int(loop->getModifiers()) & int(ToolLoopModifiers::kSquareAspect))) {
int dx = stroke[1].x - m_first.x;
int dy = stroke[1].y - m_first.y;
int minsize = MIN(ABS(dx), ABS(dy));
@ -172,8 +169,7 @@ public:
stroke[0] = m_first;
if (m_enableModifiers &&
(int(loop->getModifiers()) & int(ToolLoopModifiers::kFromCenter))) {
if ((int(loop->getModifiers()) & int(ToolLoopModifiers::kFromCenter))) {
int rx = stroke[1].x - m_first.x;
int ry = stroke[1].y - m_first.y;
stroke[0].x = m_first.x - rx;
@ -232,7 +228,6 @@ private:
}
Point m_first;
bool m_enableModifiers;
};
// Controls clicks for tools like polygon
@ -390,8 +385,6 @@ private:
// freehand until the mouse is released.
class LineFreehandController : public Controller {
public:
LineFreehandController() : m_twoPoints(false) { }
bool isFreehand() override { return true; }
gfx::Point getLastPoint() const override { return m_last; }
@ -414,6 +407,8 @@ public:
}
bool releaseButton(Stroke& stroke, const Point& point) override {
if (!stroke.empty())
m_last = stroke.lastPoint();
return false;
}

View File

@ -234,6 +234,10 @@ class IntertwineAsPixelPerfect : public Intertwine {
Stroke m_pts;
public:
// Useful for Shift+Ctrl+pencil to draw straight lines and snap
// angle when "pixel perfect" is selected.
bool snapByAngle() override { return true; }
void prepareIntertwine() override {
m_pts.reset();
}

View File

@ -115,7 +115,7 @@ ToolBox::ToolBox()
m_controllers[WellKnownControllers::Freehand] = new FreehandController();
m_controllers[WellKnownControllers::PointByPoint] = new PointByPointController();
m_controllers[WellKnownControllers::OnePoints] = new OnePointController();
m_controllers[WellKnownControllers::TwoPoints] = new TwoPointsController(true);
m_controllers[WellKnownControllers::TwoPoints] = new TwoPointsController();
m_controllers[WellKnownControllers::FourPoints] = new FourPointsController();
m_controllers[WellKnownControllers::LineFreehand] = new LineFreehandController();

View File

@ -1442,14 +1442,27 @@ void Editor::updateToolLoopModifiersIndicators()
int(tools::ToolLoopModifiers::kAddSelection) |
int(tools::ToolLoopModifiers::kSubtractSelection)));
// Shape tools (line, curves, rectangles, etc.)
action = m_customizationDelegate->getPressedKeyAction(KeyContext::ShapeTool);
if (int(action & KeyAction::MoveOrigin))
modifiers |= int(tools::ToolLoopModifiers::kMoveOrigin);
if (int(action & KeyAction::SquareAspect))
modifiers |= int(tools::ToolLoopModifiers::kSquareAspect);
if (int(action & KeyAction::DrawFromCenter))
modifiers |= int(tools::ToolLoopModifiers::kFromCenter);
tools::Controller* controller =
(App::instance()->activeToolManager()->selectedTool() ?
App::instance()->activeToolManager()->selectedTool()->getController(0): nullptr);
// Shape tools modifiers (line, curves, rectangles, etc.)
if (controller && controller->isTwoPoints()) {
action = m_customizationDelegate->getPressedKeyAction(KeyContext::ShapeTool);
if (int(action & KeyAction::MoveOrigin))
modifiers |= int(tools::ToolLoopModifiers::kMoveOrigin);
if (int(action & KeyAction::SquareAspect))
modifiers |= int(tools::ToolLoopModifiers::kSquareAspect);
if (int(action & KeyAction::DrawFromCenter))
modifiers |= int(tools::ToolLoopModifiers::kFromCenter);
}
// Freehand modifiers
if (controller && controller->isFreehand()) {
action = m_customizationDelegate->getPressedKeyAction(KeyContext::FreehandTool);
if (int(action & KeyAction::AngleSnapFromLastPoint))
modifiers |= int(tools::ToolLoopModifiers::kSquareAspect);
}
}
else {
// We update the selection mode only if we're not selecting.

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -44,6 +44,7 @@ namespace {
{ "SubtractSelection" , "Subtract Selection" , app::KeyAction::SubtractSelection },
{ "AutoSelectLayer" , "Auto Select Layer" , app::KeyAction::AutoSelectLayer },
{ "StraightLineFromLastPoint", "Straight Line from Last Point", app::KeyAction::StraightLineFromLastPoint },
{ "AngleSnapFromLastPoint", "Angle Snap from Last Point", app::KeyAction::AngleSnapFromLastPoint },
{ "MoveOrigin" , "Move Origin" , app::KeyAction::MoveOrigin },
{ "SquareAspect" , "Square Aspect" , app::KeyAction::SquareAspect },
{ "DrawFromCenter" , "Draw From Center" , app::KeyAction::DrawFromCenter },
@ -158,6 +159,7 @@ Key::Key(KeyAction action)
m_keycontext = KeyContext::MoveTool;
break;
case KeyAction::StraightLineFromLastPoint:
case KeyAction::AngleSnapFromLastPoint:
m_keycontext = KeyContext::FreehandTool;
break;
case KeyAction::MoveOrigin:

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -71,6 +71,7 @@ namespace app {
SquareAspect = 0x00001000,
DrawFromCenter = 0x00002000,
ScaleFromCenter = 0x00004000,
AngleSnapFromLastPoint = 0x00008000,
};
inline KeyAction operator&(KeyAction a, KeyAction b) {