mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-16 10:20:50 +00:00
Fix crash undoing Edit > Shift (regression from 1c05ea10bb7c6cde8bfc04711ebf104f5b7da658)
This commit is contained in:
parent
fd9ff17976
commit
7d8e493dca
@ -59,6 +59,8 @@ void CopyRegion::onRedo()
|
||||
void CopyRegion::swap()
|
||||
{
|
||||
Image* image = this->image();
|
||||
ASSERT(image);
|
||||
|
||||
swap_image_region_with_buffer(m_region, image, m_buffer);
|
||||
image->incrementVersion();
|
||||
}
|
||||
|
@ -45,7 +45,24 @@ void ShiftMaskedCel::shift(int dx, int dy)
|
||||
ASSERT(mask->bitmap());
|
||||
if (!mask->bitmap())
|
||||
return;
|
||||
doc::algorithm::shift_image_with_mask(cel, mask, dx, dy);
|
||||
|
||||
gfx::Rect newBounds;
|
||||
ImageRef newImage =
|
||||
doc::algorithm::shift_image_with_mask(cel, mask, dx, dy, newBounds);
|
||||
|
||||
ImageRef oldImage = cel->imageRef();
|
||||
if (!is_same_image(oldImage.get(), newImage.get())) {
|
||||
ObjectId id = oldImage->id();
|
||||
ObjectVersion ver = oldImage->version();
|
||||
oldImage->setId(NullId);
|
||||
|
||||
newImage->setId(id);
|
||||
newImage->setVersion(ver);
|
||||
newImage->incrementVersion();
|
||||
cel->data()->setImage(newImage);
|
||||
}
|
||||
cel->data()->setBounds(newBounds);
|
||||
cel->data()->incrementVersion();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -58,7 +58,11 @@ void shift_image(Image* image, int dx, int dy, double angle)
|
||||
}
|
||||
}
|
||||
|
||||
void shift_image_with_mask(Cel* cel, const Mask* mask, int dx, int dy)
|
||||
ImageRef shift_image_with_mask(const Cel* cel,
|
||||
const Mask* mask,
|
||||
const int dx,
|
||||
const int dy,
|
||||
gfx::Rect& newCelBounds)
|
||||
{
|
||||
ASSERT(!cel->bounds().isEmpty());
|
||||
ASSERT(!mask->bounds().isEmpty());
|
||||
@ -107,13 +111,15 @@ void shift_image_with_mask(Cel* cel, const Mask* mask, int dx, int dy)
|
||||
compCelBounds.setSize(newBounds.size());
|
||||
}
|
||||
ImageRef finalImage(Image::create(compImage->pixelFormat(), compCelBounds.w, compCelBounds.h));
|
||||
finalImage->copy(compImage.get(), gfx::Clip(0, 0, newBounds.x, newBounds.y,
|
||||
compCelBounds.w, compCelBounds.h));
|
||||
finalImage->copy(
|
||||
compImage.get(),
|
||||
gfx::Clip(0, 0, newBounds.x, newBounds.y,
|
||||
compCelBounds.w, compCelBounds.h));
|
||||
|
||||
// Final cel content assign
|
||||
finalImage->incrementVersion(); // TODO this should be in app::cmd module
|
||||
cel->data()->setBounds(compCelBounds);
|
||||
cel->data()->setImage(finalImage);
|
||||
newCelBounds = compCelBounds;
|
||||
return finalImage;
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
} // namespace doc
|
||||
|
@ -9,15 +9,21 @@
|
||||
#define DOC_ALGORITHM_SHIFT_IMAGE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/image_ref.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
class Image;
|
||||
class Mask;
|
||||
|
||||
namespace algorithm {
|
||||
|
||||
void shift_image(Image* image, int dx, int dy, double angle);
|
||||
void shift_image_with_mask(Cel* cel, const Mask* mask, int dx, int dy);
|
||||
ImageRef shift_image_with_mask(const Cel* cel,
|
||||
const Mask* mask,
|
||||
const int dx,
|
||||
const int dy,
|
||||
gfx::Rect& newCelBounds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user