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_oldBounds.offset(-m_newOrigin);
m_newBounds.offset(-m_oldOrigin); m_newBounds.offset(-m_oldOrigin);
ASSERT(m_newBounds != m_oldBounds);
} }
void CropCel::onExecute() void CropCel::onExecute()

View File

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

View File

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