mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-22 01:21:19 +00:00
Fix crash copying floating tilemaps
This commit is contained in:
parent
d6acb9e20f
commit
9c5b856aef
@ -630,10 +630,21 @@ void MovingPixelsState::onBeforeCommandExecution(CommandExecutionEvent& ev)
|
||||
std::unique_ptr<Mask> floatingMask;
|
||||
m_pixelsMovement->getDraggedImageCopy(floatingImage, floatingMask);
|
||||
|
||||
Clipboard::instance()->
|
||||
copyImage(floatingImage.get(),
|
||||
floatingMask.get(),
|
||||
document->sprite()->palette(m_editor->frame()));
|
||||
if (floatingImage->isTilemap()) {
|
||||
Site site = m_editor->getSite();
|
||||
ASSERT(site.tileset());
|
||||
Clipboard::instance()->
|
||||
copyTilemap(floatingImage.get(),
|
||||
floatingMask.get(),
|
||||
document->sprite()->palette(m_editor->frame()),
|
||||
site.tileset());
|
||||
}
|
||||
else {
|
||||
Clipboard::instance()->
|
||||
copyImage(floatingImage.get(),
|
||||
floatingMask.get(),
|
||||
document->sprite()->palette(m_editor->frame()));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear floating pixels on Cut/Clear.
|
||||
|
@ -716,9 +716,22 @@ void PixelsMovement::getDraggedImageCopy(std::unique_ptr<Image>& outputImage,
|
||||
if (bounds.isEmpty())
|
||||
return;
|
||||
|
||||
doc::PixelFormat pixelFormat;
|
||||
gfx::Size imgSize;
|
||||
if (m_site.tilemapMode() == TilemapMode::Tiles) {
|
||||
imgSize = m_site.grid().canvasToTile(bounds).size();
|
||||
pixelFormat = IMAGE_TILEMAP;
|
||||
}
|
||||
else {
|
||||
imgSize = bounds.size();
|
||||
pixelFormat = m_site.sprite()->pixelFormat();
|
||||
}
|
||||
|
||||
std::unique_ptr<Image> image(
|
||||
Image::create(
|
||||
m_site.sprite()->pixelFormat(), bounds.w, bounds.h));
|
||||
pixelFormat,
|
||||
imgSize.w,
|
||||
imgSize.h));
|
||||
|
||||
drawImage(m_currentData, image.get(),
|
||||
gfx::PointF(bounds.origin()), false);
|
||||
@ -1177,12 +1190,8 @@ static void merge_tilemaps(Image* dst, const Image* src, gfx::Clip area)
|
||||
ImageConstIterator<TilemapTraits> src_it(src, area.srcBounds(), area.src.x, area.src.y);
|
||||
ImageIterator<TilemapTraits> dst_it(dst, area.dstBounds(), area.dst.x, area.dst.y);
|
||||
|
||||
int end_x = area.dst.x+area.size.w;
|
||||
|
||||
for (int end_y=area.dst.y+area.size.h;
|
||||
area.dst.y<end_y;
|
||||
++area.dst.y, ++area.src.y) {
|
||||
for (int x=area.dst.x; x<end_x; ++x) {
|
||||
for (int y=0; y<area.size.h; ++y) {
|
||||
for (int x=0; x<area.size.w; ++x) {
|
||||
if (*src_it != doc::notile)
|
||||
*dst_it = *src_it;
|
||||
++src_it;
|
||||
@ -1195,6 +1204,9 @@ void PixelsMovement::drawTransformedTilemap(
|
||||
const Transformation& transformation,
|
||||
doc::Image* dst, const doc::Image* src, const doc::Mask* mask)
|
||||
{
|
||||
ASSERT(dst->pixelFormat() == IMAGE_TILEMAP);
|
||||
ASSERT(src->pixelFormat() == IMAGE_TILEMAP);
|
||||
|
||||
const int boxw = std::max(1, src->width()-2);
|
||||
const int boxh = std::max(1, src->height()-2);
|
||||
|
||||
|
@ -416,6 +416,7 @@ void Clipboard::copyImage(const Image* image,
|
||||
const Mask* mask,
|
||||
const Palette* pal)
|
||||
{
|
||||
ASSERT(image->pixelFormat() != IMAGE_TILEMAP);
|
||||
setData(
|
||||
Image::createCopy(image),
|
||||
(mask ? new Mask(*mask): nullptr),
|
||||
@ -424,6 +425,20 @@ void Clipboard::copyImage(const Image* image,
|
||||
true, false);
|
||||
}
|
||||
|
||||
void Clipboard::copyTilemap(const Image* image,
|
||||
const Mask* mask,
|
||||
const Palette* pal,
|
||||
const Tileset* tileset)
|
||||
{
|
||||
ASSERT(image->pixelFormat() == IMAGE_TILEMAP);
|
||||
setData(
|
||||
Image::createCopy(image),
|
||||
(mask ? new Mask(*mask): nullptr),
|
||||
(pal ? new Palette(*pal): nullptr),
|
||||
Tileset::MakeCopyCopyingImages(tileset),
|
||||
true, false);
|
||||
}
|
||||
|
||||
void Clipboard::copyPalette(const Palette* palette,
|
||||
const PalettePicks& picks)
|
||||
{
|
||||
|
@ -68,6 +68,10 @@ namespace app {
|
||||
void copyImage(const doc::Image* image,
|
||||
const doc::Mask* mask,
|
||||
const doc::Palette* palette);
|
||||
void copyTilemap(const doc::Image* image,
|
||||
const doc::Mask* mask,
|
||||
const doc::Palette* pal,
|
||||
const doc::Tileset* tileset);
|
||||
void copyPalette(const doc::Palette* palette,
|
||||
const doc::PalettePicks& picks);
|
||||
void paste(Context* ctx, const bool interactive);
|
||||
|
Loading…
x
Reference in New Issue
Block a user