Don't generate cmd::CropCel() if it isn't necessary

This commit is contained in:
David Capello 2019-04-24 17:31:06 -03:00
parent 6f72666330
commit e8a057a334
3 changed files with 11 additions and 7 deletions

View File

@ -27,6 +27,8 @@ CropCel::CropCel(Cel* cel, const gfx::Rect& newBounds)
{
m_oldBounds.offset(-m_newOrigin);
m_newBounds.offset(-m_oldOrigin);
ASSERT(m_newBounds != m_oldBounds);
}
void CropCel::onExecute()

View File

@ -35,10 +35,11 @@ void PatchCel::onExecute()
{
Cel* cel = this->cel();
executeAndAdd(
new CropCel(cel,
cel->bounds() |
gfx::Rect(m_region.bounds()).offset(m_pos)));
const gfx::Rect newBounds =
cel->bounds() | gfx::Rect(m_region.bounds()).offset(m_pos);
if (cel->bounds() != newBounds) {
executeAndAdd(new CropCel(cel, newBounds));
}
executeAndAdd(
new CopyRegion(cel->image(),
@ -46,8 +47,7 @@ void PatchCel::onExecute()
m_region,
m_pos - cel->position()));
executeAndAdd(
new TrimCel(cel));
executeAndAdd(new TrimCel(cel));
m_patch = nullptr;
}

View File

@ -28,7 +28,9 @@ TrimCel::TrimCel(Cel* cel)
if (algorithm::shrink_bounds(cel->image(), newBounds,
cel->image()->maskColor())) {
newBounds.offset(cel->position());
add(new cmd::CropCel(cel, newBounds));
if (cel->bounds() != newBounds) {
add(new cmd::CropCel(cel, newBounds));
}
}
else {
// Delete the given "cel" and all its links.