mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 13:09:27 +00:00
Add "maintain aspect ratio" in selection transformation (issue #48).
This commit is contained in:
parent
a22b86df65
commit
1dd4120951
@ -173,6 +173,10 @@
|
||||
<!-- When you rotate the selection, pressing this
|
||||
keyboard shortcut you activate angle snap -->
|
||||
<key action="AngleSnap" shortcut="Shift" />
|
||||
|
||||
<!-- When you scale the selection, pressing this
|
||||
keyboard shortcut you maintain aspect ratio -->
|
||||
<key action="MaintainAspectRatio" shortcut="Shift" />
|
||||
</spriteeditor>
|
||||
|
||||
</keyboard>
|
||||
|
@ -144,6 +144,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isMaintainAspectRatioKeyPressed() OVERRIDE {
|
||||
JAccel accel = get_accel_to_maintain_aspect_ratio();
|
||||
if (accel)
|
||||
return jaccel_check_from_key(accel);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class MiniEditor : public Editor
|
||||
|
@ -64,9 +64,10 @@
|
||||
|
||||
#define MONITOR_TIMER_MSECS 100
|
||||
|
||||
#define SPRITEDITOR_ACTION_COPYSELECTION "CopySelection"
|
||||
#define SPRITEDITOR_ACTION_SNAPTOGRID "SnapToGrid"
|
||||
#define SPRITEDITOR_ACTION_ANGLESNAP "AngleSnap"
|
||||
#define SPRITEDITOR_ACTION_COPYSELECTION "CopySelection"
|
||||
#define SPRITEDITOR_ACTION_SNAPTOGRID "SnapToGrid"
|
||||
#define SPRITEDITOR_ACTION_ANGLESNAP "AngleSnap"
|
||||
#define SPRITEDITOR_ACTION_MAINTAINASPECTRATIO "MaintainAspectRatio"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -959,6 +960,15 @@ JAccel get_accel_to_angle_snap()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JAccel get_accel_to_maintain_aspect_ratio()
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_MAINTAINASPECTRATIO);
|
||||
if (shortcut)
|
||||
return shortcut->accel;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tools::Tool* get_selected_quicktool(tools::Tool* currentTool)
|
||||
{
|
||||
if (currentTool && currentTool->getInk(0)->isSelection()) {
|
||||
|
@ -118,6 +118,7 @@ JAccel get_accel_to_change_tool(tools::Tool* tool);
|
||||
JAccel get_accel_to_copy_selection();
|
||||
JAccel get_accel_to_snap_to_grid();
|
||||
JAccel get_accel_to_angle_snap();
|
||||
JAccel get_accel_to_maintain_aspect_ratio();
|
||||
|
||||
tools::Tool* get_selected_quicktool(tools::Tool* currentTool);
|
||||
|
||||
|
@ -47,6 +47,10 @@ public:
|
||||
// Returns true if the user wants to activate angle snap, so he can
|
||||
// easily specify common angles (45, 90, 135, 180, etc.).
|
||||
virtual bool isAngleSnapKeyPressed() = 0;
|
||||
|
||||
// Returns true if the user wants to maintain the aspect ratio when
|
||||
// he is scaling the selection.
|
||||
virtual bool isMaintainAspectRatioKeyPressed() = 0;
|
||||
};
|
||||
|
||||
#endif // WIDGETS_EDITOR_CUSTOMIZATION_DELEGATE_H_INCLUDED
|
||||
|
@ -187,6 +187,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, Message* msg)
|
||||
int x, y;
|
||||
editor->screenToEditor(msg->mouse.x, msg->mouse.y, &x, &y);
|
||||
|
||||
// Get the customization for the pixels movement (snap to grid, angle snap, etc.).
|
||||
PixelsMovement::MoveModifier moveModifier = PixelsMovement::NormalMovement;
|
||||
|
||||
if (editor->getCustomizationDelegate()->isSnapToGridKeyPressed())
|
||||
@ -195,6 +196,9 @@ bool MovingPixelsState::onMouseMove(Editor* editor, Message* msg)
|
||||
if (editor->getCustomizationDelegate()->isAngleSnapKeyPressed())
|
||||
moveModifier |= PixelsMovement::AngleSnapMovement;
|
||||
|
||||
if (editor->getCustomizationDelegate()->isMaintainAspectRatioKeyPressed())
|
||||
moveModifier |= PixelsMovement::MaintainAspectRatioMovement;
|
||||
|
||||
// Drag the image to that position
|
||||
gfx::Rect bounds = m_pixelsMovement->moveImage(x, y, moveModifier);
|
||||
|
||||
|
@ -197,6 +197,17 @@ gfx::Rect PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier)
|
||||
case ScaleNWHandle:
|
||||
x1 = MIN(x1+dx, x2-1);
|
||||
y1 = MIN(y1+dy, y2-1);
|
||||
|
||||
if ((moveModifier & MaintainAspectRatioMovement) == MaintainAspectRatioMovement) {
|
||||
if (1000 * (x2-x1) / getInitialImageSize().w >
|
||||
1000 * (y2-y1) / getInitialImageSize().h) {
|
||||
y1 = y2 - getInitialImageSize().h * (x2-x1) / getInitialImageSize().w;
|
||||
}
|
||||
else {
|
||||
x1 = x2 - getInitialImageSize().w * (y2-y1) / getInitialImageSize().h;
|
||||
}
|
||||
}
|
||||
|
||||
updateBounds = true;
|
||||
break;
|
||||
|
||||
@ -208,6 +219,17 @@ gfx::Rect PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier)
|
||||
case ScaleNEHandle:
|
||||
x2 = MAX(x2+dx, x1+1);
|
||||
y1 = MIN(y1+dy, y2-1);
|
||||
|
||||
if ((moveModifier & MaintainAspectRatioMovement) == MaintainAspectRatioMovement) {
|
||||
if (1000 * (x2-x1) / getInitialImageSize().w >
|
||||
1000 * (y2-y1) / getInitialImageSize().h) {
|
||||
y1 = y2 - getInitialImageSize().h * (x2-x1) / getInitialImageSize().w;
|
||||
}
|
||||
else {
|
||||
x2 = x1 + getInitialImageSize().w * (y2-y1) / getInitialImageSize().h;
|
||||
}
|
||||
}
|
||||
|
||||
updateBounds = true;
|
||||
break;
|
||||
|
||||
@ -224,6 +246,17 @@ gfx::Rect PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier)
|
||||
case ScaleSWHandle:
|
||||
x1 = MIN(x1+dx, x2-1);
|
||||
y2 = MAX(y2+dy, y1+1);
|
||||
|
||||
if ((moveModifier & MaintainAspectRatioMovement) == MaintainAspectRatioMovement) {
|
||||
if (1000 * (x2-x1) / getInitialImageSize().w >
|
||||
1000 * (y2-y1) / getInitialImageSize().h) {
|
||||
y2 = y1 + getInitialImageSize().h * (x2-x1) / getInitialImageSize().w;
|
||||
}
|
||||
else {
|
||||
x1 = x2 - getInitialImageSize().w * (y2-y1) / getInitialImageSize().h;
|
||||
}
|
||||
}
|
||||
|
||||
updateBounds = true;
|
||||
break;
|
||||
|
||||
@ -235,6 +268,17 @@ gfx::Rect PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier)
|
||||
case ScaleSEHandle:
|
||||
x2 = MAX(x2+dx, x1+1);
|
||||
y2 = MAX(y2+dy, y1+1);
|
||||
|
||||
if ((moveModifier & MaintainAspectRatioMovement) == MaintainAspectRatioMovement) {
|
||||
if (1000 * (x2-x1) / getInitialImageSize().w >
|
||||
1000 * (y2-y1) / getInitialImageSize().h) {
|
||||
y2 = y1 + getInitialImageSize().h * (x2-x1) / getInitialImageSize().w;
|
||||
}
|
||||
else {
|
||||
x2 = x1 + getInitialImageSize().w * (y2-y1) / getInitialImageSize().h;
|
||||
}
|
||||
}
|
||||
|
||||
updateBounds = true;
|
||||
break;
|
||||
|
||||
|
@ -39,7 +39,8 @@ public:
|
||||
enum MoveModifier {
|
||||
NormalMovement = 1,
|
||||
SnapToGridMovement = 2,
|
||||
AngleSnapMovement = 4
|
||||
AngleSnapMovement = 4,
|
||||
MaintainAspectRatioMovement = 8
|
||||
};
|
||||
|
||||
// The "moveThis" image specifies the chunk of pixels to be moved.
|
||||
|
Loading…
Reference in New Issue
Block a user