mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-28 16:20:50 +00:00
Fix crash copying floating tilemaps
This commit is contained in:
parent
d6acb9e20f
commit
9c5b856aef
@ -630,11 +630,22 @@ void MovingPixelsState::onBeforeCommandExecution(CommandExecutionEvent& ev)
|
|||||||
std::unique_ptr<Mask> floatingMask;
|
std::unique_ptr<Mask> floatingMask;
|
||||||
m_pixelsMovement->getDraggedImageCopy(floatingImage, floatingMask);
|
m_pixelsMovement->getDraggedImageCopy(floatingImage, floatingMask);
|
||||||
|
|
||||||
|
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()->
|
Clipboard::instance()->
|
||||||
copyImage(floatingImage.get(),
|
copyImage(floatingImage.get(),
|
||||||
floatingMask.get(),
|
floatingMask.get(),
|
||||||
document->sprite()->palette(m_editor->frame()));
|
document->sprite()->palette(m_editor->frame()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clear floating pixels on Cut/Clear.
|
// Clear floating pixels on Cut/Clear.
|
||||||
if (command->id() != CommandId::Copy()) {
|
if (command->id() != CommandId::Copy()) {
|
||||||
|
@ -716,9 +716,22 @@ void PixelsMovement::getDraggedImageCopy(std::unique_ptr<Image>& outputImage,
|
|||||||
if (bounds.isEmpty())
|
if (bounds.isEmpty())
|
||||||
return;
|
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(
|
std::unique_ptr<Image> image(
|
||||||
Image::create(
|
Image::create(
|
||||||
m_site.sprite()->pixelFormat(), bounds.w, bounds.h));
|
pixelFormat,
|
||||||
|
imgSize.w,
|
||||||
|
imgSize.h));
|
||||||
|
|
||||||
drawImage(m_currentData, image.get(),
|
drawImage(m_currentData, image.get(),
|
||||||
gfx::PointF(bounds.origin()), false);
|
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);
|
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);
|
ImageIterator<TilemapTraits> dst_it(dst, area.dstBounds(), area.dst.x, area.dst.y);
|
||||||
|
|
||||||
int end_x = area.dst.x+area.size.w;
|
for (int y=0; y<area.size.h; ++y) {
|
||||||
|
for (int x=0; x<area.size.w; ++x) {
|
||||||
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) {
|
|
||||||
if (*src_it != doc::notile)
|
if (*src_it != doc::notile)
|
||||||
*dst_it = *src_it;
|
*dst_it = *src_it;
|
||||||
++src_it;
|
++src_it;
|
||||||
@ -1195,6 +1204,9 @@ void PixelsMovement::drawTransformedTilemap(
|
|||||||
const Transformation& transformation,
|
const Transformation& transformation,
|
||||||
doc::Image* dst, const doc::Image* src, const doc::Mask* mask)
|
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 boxw = std::max(1, src->width()-2);
|
||||||
const int boxh = std::max(1, src->height()-2);
|
const int boxh = std::max(1, src->height()-2);
|
||||||
|
|
||||||
|
@ -416,6 +416,7 @@ void Clipboard::copyImage(const Image* image,
|
|||||||
const Mask* mask,
|
const Mask* mask,
|
||||||
const Palette* pal)
|
const Palette* pal)
|
||||||
{
|
{
|
||||||
|
ASSERT(image->pixelFormat() != IMAGE_TILEMAP);
|
||||||
setData(
|
setData(
|
||||||
Image::createCopy(image),
|
Image::createCopy(image),
|
||||||
(mask ? new Mask(*mask): nullptr),
|
(mask ? new Mask(*mask): nullptr),
|
||||||
@ -424,6 +425,20 @@ void Clipboard::copyImage(const Image* image,
|
|||||||
true, false);
|
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,
|
void Clipboard::copyPalette(const Palette* palette,
|
||||||
const PalettePicks& picks)
|
const PalettePicks& picks)
|
||||||
{
|
{
|
||||||
|
@ -68,6 +68,10 @@ namespace app {
|
|||||||
void copyImage(const doc::Image* image,
|
void copyImage(const doc::Image* image,
|
||||||
const doc::Mask* mask,
|
const doc::Mask* mask,
|
||||||
const doc::Palette* palette);
|
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,
|
void copyPalette(const doc::Palette* palette,
|
||||||
const doc::PalettePicks& picks);
|
const doc::PalettePicks& picks);
|
||||||
void paste(Context* ctx, const bool interactive);
|
void paste(Context* ctx, const bool interactive);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user