mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-17 13:20:45 +00:00
Fix cmd::FlipMaskedCel to flip irregular regions
This commit is contained in:
parent
ec2ef30f20
commit
62c6647710
@ -11,7 +11,9 @@
|
||||
|
||||
#include "app/cmd/flip_masked_cel.h"
|
||||
|
||||
#include "app/cmd/copy_rect.h"
|
||||
#include "app/document.h"
|
||||
#include "app/util/autocrop.h"
|
||||
#include "doc/algorithm/flip_image.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/image.h"
|
||||
@ -22,39 +24,28 @@ namespace app {
|
||||
namespace cmd {
|
||||
|
||||
FlipMaskedCel::FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType)
|
||||
: WithCel(cel)
|
||||
, m_flipType(flipType)
|
||||
, m_bgcolor(static_cast<app::Document*>(cel->document())->bgColor(cel->layer()))
|
||||
{
|
||||
}
|
||||
|
||||
void FlipMaskedCel::onExecute()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipMaskedCel::onUndo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipMaskedCel::swap()
|
||||
{
|
||||
Cel* cel = this->cel();
|
||||
app::Document* doc = static_cast<app::Document*>(cel->document());
|
||||
color_t bgcolor = doc->bgColor(cel->layer());
|
||||
Image* image = cel->image();
|
||||
Mask* mask = static_cast<app::Document*>(cel->document())->mask();
|
||||
Mask* mask = doc->mask();
|
||||
ASSERT(mask->bitmap());
|
||||
if (!mask->bitmap())
|
||||
return;
|
||||
|
||||
ImageRef copy(Image::createCopy(image));
|
||||
int x = cel->x();
|
||||
int y = cel->y();
|
||||
|
||||
mask->offsetOrigin(-x, -y);
|
||||
doc::algorithm::flip_image_with_mask(image, mask, m_flipType, m_bgcolor);
|
||||
doc::algorithm::flip_image_with_mask(
|
||||
copy.get(), mask, flipType, bgcolor);
|
||||
mask->offsetOrigin(x, y);
|
||||
|
||||
image->incrementVersion();
|
||||
int x1, y1, x2, y2;
|
||||
if (get_shrink_rect2(&x1, &y1, &x2, &y2, image, copy.get())) {
|
||||
add(new cmd::CopyRect(image, copy.get(),
|
||||
gfx::Clip(x1, y1, x1, y1, x2-x1+1, y2-y1+1)));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -9,32 +9,21 @@
|
||||
#define APP_CMD_FLIP_MASKED_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "doc/algorithm/flip_type.h"
|
||||
#include "doc/color.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class FlipMaskedCel : public Cmd
|
||||
, public WithCel {
|
||||
class FlipMaskedCel : public CmdSequence {
|
||||
public:
|
||||
FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
void swap();
|
||||
|
||||
doc::algorithm::FlipType m_flipType;
|
||||
color_t m_bgcolor;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
|
Loading…
x
Reference in New Issue
Block a user