mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 21:46:20 +00:00
Preserve linked cels between documents when Copy/Paste is used in the Timeline
Fix #734
This commit is contained in:
parent
55477ce0d5
commit
a73d0cf846
@ -314,28 +314,65 @@ void clipboard::paste()
|
|||||||
case DocumentRange::kCels: {
|
case DocumentRange::kCels: {
|
||||||
// Do nothing case: pasting in the same document.
|
// Do nothing case: pasting in the same document.
|
||||||
if (srcDoc == dstDoc)
|
if (srcDoc == dstDoc)
|
||||||
return;
|
return; // TODO paste clipboard content in new location
|
||||||
|
|
||||||
Transaction transaction(UIContext::instance(), "Paste Cels");
|
Transaction transaction(UIContext::instance(), "Paste Cels");
|
||||||
DocumentApi api = dstDoc->getApi(transaction);
|
DocumentApi api = dstDoc->getApi(transaction);
|
||||||
|
|
||||||
frame_t dstFrame = editor->frame();
|
frame_t dstFrameBegin = editor->frame();
|
||||||
for (frame_t frame = srcRange.frameBegin(); frame <= srcRange.frameEnd(); ++frame) {
|
|
||||||
if (dstFrame == dstSpr->totalFrames())
|
|
||||||
api.addFrame(dstSpr, dstFrame);
|
|
||||||
|
|
||||||
for (LayerIndex
|
// Add extra frames if needed
|
||||||
i = srcRange.layerEnd(),
|
while (dstFrameBegin+srcRange.frames() > dstSpr->totalFrames())
|
||||||
j = dstSpr->layerToIndex(editor->layer());
|
api.addFrame(dstSpr, dstSpr->totalFrames());
|
||||||
i >= srcRange.layerBegin() &&
|
|
||||||
i >= LayerIndex(0) &&
|
|
||||||
j >= LayerIndex(0); --i, --j) {
|
|
||||||
Cel* cel = srcLayers[i]->cel(frame);
|
|
||||||
|
|
||||||
if (cel && cel->image()) {
|
for (LayerIndex
|
||||||
api.copyCel(
|
i = srcRange.layerEnd(),
|
||||||
static_cast<LayerImage*>(srcLayers[i]), frame,
|
j = dstSpr->layerToIndex(editor->layer());
|
||||||
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
|
i >= srcRange.layerBegin() &&
|
||||||
|
i >= LayerIndex(0) &&
|
||||||
|
j >= LayerIndex(0); --i, --j) {
|
||||||
|
// Maps a linked Cel in the original sprite with its
|
||||||
|
// corresponding copy in the new sprite. In this way
|
||||||
|
// we can.
|
||||||
|
std::map<Cel*, Cel*> relatedCels;
|
||||||
|
|
||||||
|
for (frame_t frame = srcRange.frameBegin(),
|
||||||
|
dstFrame = dstFrameBegin;
|
||||||
|
frame <= srcRange.frameEnd();
|
||||||
|
++frame, ++dstFrame) {
|
||||||
|
Cel* srcCel = srcLayers[i]->cel(frame);
|
||||||
|
Cel* srcLink = nullptr;
|
||||||
|
|
||||||
|
if (srcCel && srcCel->image()) {
|
||||||
|
bool createCopy = true;
|
||||||
|
|
||||||
|
if (dstLayers[j]->isContinuous() &&
|
||||||
|
srcCel->links()) {
|
||||||
|
srcLink = srcCel->link();
|
||||||
|
if (!srcLink)
|
||||||
|
srcLink = srcCel;
|
||||||
|
|
||||||
|
if (srcLink) {
|
||||||
|
Cel* dstRelated = relatedCels[srcLink];
|
||||||
|
if (dstRelated) {
|
||||||
|
createCopy = false;
|
||||||
|
|
||||||
|
// Create a link from dstRelated
|
||||||
|
api.copyCel(
|
||||||
|
static_cast<LayerImage*>(dstLayers[j]), dstRelated->frame(),
|
||||||
|
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createCopy) {
|
||||||
|
api.copyCel(
|
||||||
|
static_cast<LayerImage*>(srcLayers[i]), frame,
|
||||||
|
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
|
||||||
|
|
||||||
|
if (srcLink)
|
||||||
|
relatedCels[srcLink] = dstLayers[j]->cel(dstFrame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cel* dstCel = dstLayers[j]->cel(dstFrame);
|
Cel* dstCel = dstLayers[j]->cel(dstFrame);
|
||||||
@ -344,7 +381,6 @@ void clipboard::paste()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++dstFrame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
Loading…
Reference in New Issue
Block a user