mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-28 16:20:50 +00:00
Restore Reference Layer bounds correctly if we delete a cel & undo it (fix #3264)
This commit is contained in:
parent
fd430603a0
commit
f886e85af9
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -55,6 +55,10 @@ namespace doc {
|
||||
return *m_boundsF;
|
||||
}
|
||||
|
||||
bool hasBoundsF() const {
|
||||
return m_boundsF != nullptr;
|
||||
}
|
||||
|
||||
virtual int getMemSize() const override {
|
||||
ASSERT(m_image);
|
||||
return sizeof(CelData) + m_image->getMemSize();
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -14,12 +15,15 @@
|
||||
#include "doc/cel_data.h"
|
||||
#include "doc/subobjects_io.h"
|
||||
#include "doc/user_data_io.h"
|
||||
#include "fixmath/fixmath.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
namespace doc {
|
||||
|
||||
#define HAS_BOUNDS_F 1
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
@ -33,6 +37,17 @@ void write_celdata(std::ostream& os, const CelData* celdata)
|
||||
write8(os, celdata->opacity());
|
||||
write32(os, celdata->image()->id());
|
||||
write_user_data(os, celdata->userData());
|
||||
|
||||
if (celdata->hasBoundsF()) { // Reference layer
|
||||
write32(os, HAS_BOUNDS_F);
|
||||
write32(os, fixmath::ftofix(celdata->boundsF().x));
|
||||
write32(os, fixmath::ftofix(celdata->boundsF().y));
|
||||
write32(os, fixmath::ftofix(celdata->boundsF().w));
|
||||
write32(os, fixmath::ftofix(celdata->boundsF().h));
|
||||
}
|
||||
else {
|
||||
write32(os, 0);
|
||||
}
|
||||
}
|
||||
|
||||
CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects, bool setId)
|
||||
@ -45,6 +60,22 @@ CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects, bool setId)
|
||||
int opacity = read8(is);
|
||||
ObjectId imageId = read32(is);
|
||||
UserData userData = read_user_data(is);
|
||||
gfx::RectF boundsF;
|
||||
|
||||
// Extra fields
|
||||
int flags = read32(is);
|
||||
if (flags & HAS_BOUNDS_F) {
|
||||
fixmath::fixed x = read32(is);
|
||||
fixmath::fixed y = read32(is);
|
||||
fixmath::fixed w = read32(is);
|
||||
fixmath::fixed h = read32(is);
|
||||
if (w && h) {
|
||||
boundsF = gfx::RectF(fixmath::fixtof(x),
|
||||
fixmath::fixtof(y),
|
||||
fixmath::fixtof(w),
|
||||
fixmath::fixtof(h));
|
||||
}
|
||||
}
|
||||
|
||||
ImageRef image(subObjects->getImageRef(imageId));
|
||||
if (!image)
|
||||
@ -56,6 +87,8 @@ CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects, bool setId)
|
||||
celdata->setUserData(userData);
|
||||
if (setId)
|
||||
celdata->setId(id);
|
||||
if (!boundsF.isEmpty())
|
||||
celdata->setBoundsF(boundsF);
|
||||
return celdata.release();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user