Skip to content
Permalink
Browse files

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

  • Loading branch information...
dacap committed Jun 22, 2017
1 parent 85b7996 commit 8d693d1a086ae99b7674c181ef96231e835c2c76
@@ -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" />
@@ -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) { }

@@ -99,9 +99,7 @@ class FreehandController : public Controller {
// 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 @@ class TwoPointsController : public MoveOriginCapability {

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 @@ class TwoPointsController : public MoveOriginCapability {

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 @@ class TwoPointsController : public MoveOriginCapability {
}

Point m_first;
bool m_enableModifiers;
};

// Controls clicks for tools like polygon
@@ -390,8 +385,6 @@ class FourPointsController : public MoveOriginCapability {
// 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 @@ class LineFreehandController : public Controller {
}

bool releaseButton(Stroke& stroke, const Point& point) override {
if (!stroke.empty())
m_last = stroke.lastPoint();
return false;
}

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

@@ -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.
@@ -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:
@@ -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) {

0 comments on commit 8d693d1

Please sign in to comment.
You can’t perform that action at this time.