mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 03:44:16 +00:00
Simplify logic in FlipCommand::onExecute().
This commit is contained in:
parent
95a9524ec2
commit
73fc81ec58
@ -21,6 +21,7 @@
|
|||||||
#include "commands/command.h"
|
#include "commands/command.h"
|
||||||
#include "commands/params.h"
|
#include "commands/params.h"
|
||||||
#include "document_wrappers.h"
|
#include "document_wrappers.h"
|
||||||
|
#include "gfx/size.h"
|
||||||
#include "gui/list.h"
|
#include "gui/list.h"
|
||||||
#include "modules/editors.h"
|
#include "modules/editors.h"
|
||||||
#include "modules/gui.h"
|
#include "modules/gui.h"
|
||||||
@ -94,40 +95,33 @@ void FlipCommand::onExecute(Context* context)
|
|||||||
|
|
||||||
if (m_flipMask) {
|
if (m_flipMask) {
|
||||||
Image* image;
|
Image* image;
|
||||||
int x1, y1, x2, y2;
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
image = sprite->getCurrentImage(&x, &y);
|
image = sprite->getCurrentImage(&x, &y);
|
||||||
if (!image)
|
if (!image)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Mask is empty?
|
// This variable will be the area to be flipped inside the image.
|
||||||
if (!document->isMaskVisible()) {
|
gfx::Rect bounds(gfx::Point(0, 0),
|
||||||
// so we flip the entire image
|
gfx::Size(image->w, image->h));
|
||||||
x1 = 0;
|
|
||||||
y1 = 0;
|
|
||||||
x2 = image->w-1;
|
|
||||||
y2 = image->h-1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const gfx::Rect& bounds = document->getMask()->getBounds();
|
|
||||||
|
|
||||||
// apply the cel offset
|
// If there is some portion of sprite selected, we flip the
|
||||||
x1 = bounds.x - x;
|
// selected region only. If the mask isn't visible, we flip the
|
||||||
y1 = bounds.y - y;
|
// whole image.
|
||||||
x2 = bounds.x + bounds.w - 1 - x;
|
if (document->isMaskVisible()) {
|
||||||
y2 = bounds.y + bounds.h - 1 - y;
|
Mask* mask = document->getMask();
|
||||||
|
gfx::Rect maskBounds = mask->getBounds();
|
||||||
|
|
||||||
// clip
|
// Adjust the mask depending on the cel position.
|
||||||
x1 = MID(0, x1, image->w-1);
|
maskBounds.offset(-x, -y);
|
||||||
y1 = MID(0, y1, image->h-1);
|
|
||||||
x2 = MID(0, x2, image->w-1);
|
// Intersect the full area of the image with the mask's
|
||||||
y2 = MID(0, y2, image->h-1);
|
// bounds, so we don't request to flip an area outside the
|
||||||
|
// image's bounds.
|
||||||
|
bounds = bounds.createIntersect(maskBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
undoTransaction.flipImage(image,
|
// Flip the portion of image specified by "bounds" variable.
|
||||||
gfx::Rect(x1, y1,
|
undoTransaction.flipImage(image, bounds, m_flipType);
|
||||||
x2-x1+1, y2-y1+1), m_flipType);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// get all sprite cels
|
// get all sprite cels
|
||||||
|
Loading…
x
Reference in New Issue
Block a user