Add "LockAxis" key (Shift) to move the selection in X or Y axis only.

Now "Alt" modifier is the key used to snap to grid the selection.
This commit is contained in:
David Capello 2012-07-06 19:51:40 -03:00
parent 11d20a6e33
commit 9b9daca59f
8 changed files with 43 additions and 2 deletions

View File

@ -196,7 +196,11 @@
<!-- When you move the selection, pressing this
keyboard shortcut you can snap to grid -->
<key action="SnapToGrid" shortcut="Shift" />
<key action="SnapToGrid" shortcut="Alt" />
<!-- When you move the selection, pressing this keyboard
shortcut so you lock the movement to one axis -->
<key action="LockAxis" shortcut="Shift" />
<!-- When you rotate the selection, pressing this
keyboard shortcut you activate angle snap -->

View File

@ -152,6 +152,14 @@ public:
return false;
}
bool isLockAxisKeyPressed() OVERRIDE {
JAccel accel = get_accel_to_lock_axis();
if (accel)
return jaccel_check_from_key(accel);
else
return false;
}
};
class MiniEditor : public Editor

View File

@ -65,6 +65,7 @@
#define SPRITEDITOR_ACTION_SNAPTOGRID "SnapToGrid"
#define SPRITEDITOR_ACTION_ANGLESNAP "AngleSnap"
#define SPRITEDITOR_ACTION_MAINTAINASPECTRATIO "MaintainAspectRatio"
#define SPRITEDITOR_ACTION_LOCKAXIS "LockAxis"
//////////////////////////////////////////////////////////////////////
@ -789,6 +790,15 @@ JAccel get_accel_to_maintain_aspect_ratio()
return NULL;
}
JAccel get_accel_to_lock_axis()
{
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_LOCKAXIS);
if (shortcut)
return shortcut->accel;
else
return NULL;
}
tools::Tool* get_selected_quicktool(tools::Tool* currentTool)
{
if (currentTool && currentTool->getInk(0)->isSelection()) {

View File

@ -82,6 +82,7 @@ ui::JAccel get_accel_to_copy_selection();
ui::JAccel get_accel_to_snap_to_grid();
ui::JAccel get_accel_to_angle_snap();
ui::JAccel get_accel_to_maintain_aspect_ratio();
ui::JAccel get_accel_to_lock_axis();
tools::Tool* get_selected_quicktool(tools::Tool* currentTool);

View File

@ -51,6 +51,10 @@ public:
// Returns true if the user wants to maintain the aspect ratio when
// he is scaling the selection.
virtual bool isMaintainAspectRatioKeyPressed() = 0;
// Returns true if the user wants to lock the X or Y axis when he is
// dragging the selection.
virtual bool isLockAxisKeyPressed() = 0;
};
#endif // WIDGETS_EDITOR_CUSTOMIZATION_DELEGATE_H_INCLUDED

View File

@ -249,6 +249,9 @@ bool MovingPixelsState::onMouseMove(Editor* editor, Message* msg)
if (editor->getCustomizationDelegate()->isMaintainAspectRatioKeyPressed())
moveModifier |= PixelsMovement::MaintainAspectRatioMovement;
if (editor->getCustomizationDelegate()->isLockAxisKeyPressed())
moveModifier |= PixelsMovement::LockAxisMovement;
// Invalidate handles area.
Decorator* decorator = static_cast<Decorator*>(editor->getDecorator());
TransformHandles* transfHandles = decorator->getTransformHandles(editor);

View File

@ -216,6 +216,16 @@ gfx::Rect PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier)
x2 += gridOffset.x;
y2 += gridOffset.y;
}
else if ((moveModifier & LockAxisMovement) == LockAxisMovement) {
if (ABS(dx) < ABS(dy)) {
x1 -= dx;
x2 -= dx;
}
else {
y1 -= dy;
y2 -= dy;
}
}
break;
case ScaleNWHandle:

View File

@ -41,7 +41,8 @@ public:
NormalMovement = 1,
SnapToGridMovement = 2,
AngleSnapMovement = 4,
MaintainAspectRatioMovement = 8
MaintainAspectRatioMovement = 8,
LockAxisMovement = 16
};
// The "moveThis" image specifies the chunk of pixels to be moved.