2015-04-28 00:03:02 +08:00
|
|
|
// Aseprite
|
2018-06-05 22:33:28 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-04-28 00:03:02 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2015-04-28 00:03:02 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2024-12-16 21:10:34 +08:00
|
|
|
#include "config.h"
|
2015-04-28 00:03:02 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "app/cmd/clear_rect.h"
|
|
|
|
|
2018-07-07 22:54:44 +08:00
|
|
|
#include "app/doc.h"
|
2015-04-28 00:03:02 +08:00
|
|
|
#include "doc/cel.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/primitives.h"
|
|
|
|
|
2024-12-16 21:10:34 +08:00
|
|
|
namespace app { namespace cmd {
|
2015-04-28 00:03:02 +08:00
|
|
|
|
|
|
|
using namespace doc;
|
|
|
|
|
|
|
|
ClearRect::ClearRect(Cel* cel, const gfx::Rect& bounds)
|
|
|
|
{
|
2018-06-05 22:33:28 +08:00
|
|
|
ASSERT(cel);
|
2015-04-28 00:03:02 +08:00
|
|
|
|
2018-06-05 22:33:28 +08:00
|
|
|
Image* image = cel->image();
|
2015-04-28 00:03:02 +08:00
|
|
|
if (!image)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_offsetX = bounds.x - cel->x();
|
|
|
|
m_offsetY = bounds.y - cel->y();
|
|
|
|
|
2024-12-16 21:10:34 +08:00
|
|
|
gfx::Rect bounds2 = image->bounds().createIntersection(
|
|
|
|
gfx::Rect(m_offsetX, m_offsetY, bounds.w, bounds.h));
|
2015-04-28 00:03:02 +08:00
|
|
|
if (bounds.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_dstImage.reset(new WithImage(image));
|
2018-06-05 22:33:28 +08:00
|
|
|
|
2018-07-07 22:54:44 +08:00
|
|
|
Doc* doc = static_cast<Doc*>(cel->document());
|
2015-04-28 00:03:02 +08:00
|
|
|
m_bgcolor = doc->bgColor(cel->layer());
|
|
|
|
|
2024-12-16 21:10:34 +08:00
|
|
|
m_copy.reset(crop_image(image, bounds2.x, bounds2.y, bounds2.w, bounds2.h, m_bgcolor));
|
2015-04-28 00:03:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearRect::onExecute()
|
|
|
|
{
|
|
|
|
m_seq.execute(context());
|
|
|
|
if (m_dstImage)
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearRect::onUndo()
|
|
|
|
{
|
|
|
|
if (m_dstImage)
|
|
|
|
restore();
|
|
|
|
m_seq.undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearRect::onRedo()
|
|
|
|
{
|
|
|
|
m_seq.redo();
|
|
|
|
if (m_dstImage)
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearRect::clear()
|
|
|
|
{
|
|
|
|
fill_rect(m_dstImage->image(),
|
2024-12-16 21:10:34 +08:00
|
|
|
m_offsetX,
|
|
|
|
m_offsetY,
|
2015-04-28 00:03:02 +08:00
|
|
|
m_offsetX + m_copy->width() - 1,
|
|
|
|
m_offsetY + m_copy->height() - 1,
|
|
|
|
m_bgcolor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearRect::restore()
|
|
|
|
{
|
|
|
|
copy_image(m_dstImage->image(), m_copy.get(), m_offsetX, m_offsetY);
|
|
|
|
}
|
|
|
|
|
2024-12-16 21:10:34 +08:00
|
|
|
}} // namespace app::cmd
|