From b22903b326a4ce63ff0d4e401dbb9c275932d11c Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Mar 2019 18:04:54 -0300 Subject: [PATCH] Refactor Cel::createCopy/Link() -> Cel::MakeCopy/Link() receiving the new frame position for the copy/link --- src/app/cmd/copy_cel.cpp | 7 +++---- src/app/doc.cpp | 4 ++-- src/app/file/fli_format.cpp | 3 +-- src/dio/aseprite_decoder.cpp | 8 +++----- src/doc/cel.cpp | 13 ++++++++----- src/doc/cel.h | 5 +++-- src/doc/sprite_tests.cpp | 14 +++++--------- 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/app/cmd/copy_cel.cpp b/src/app/cmd/copy_cel.cpp index fe35404c5..395a1eccb 100644 --- a/src/app/cmd/copy_cel.cpp +++ b/src/app/cmd/copy_cel.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -110,10 +111,8 @@ void CopyCel::onExecute() executeAndAdd(new cmd::RemoveCel(dstCel)); if (srcCel) { - if (createLink) { - dstCel = Cel::createLink(srcCel); - dstCel->setFrame(m_dstFrame); - } + if (createLink) + dstCel = Cel::MakeLink(m_dstFrame, srcCel); else dstCel = create_cel_copy(srcCel, dstSprite, dstLayer, m_dstFrame); diff --git a/src/app/doc.cpp b/src/app/doc.cpp index 0801efe22..3e5194c53 100644 --- a/src/app/doc.cpp +++ b/src/app/doc.cpp @@ -348,8 +348,8 @@ void Doc::copyLayerContent(const Layer* sourceLayer0, Doc* destDoc, Layer* destL auto it = linked.find(sourceCel->data()->id()); if (it != linked.end()) { - newCel.reset(Cel::createLink(it->second)); - newCel->setFrame(sourceCel->frame()); + newCel.reset(Cel::MakeLink(sourceCel->frame(), + it->second)); } else { newCel.reset(create_cel_copy(sourceCel, diff --git a/src/app/file/fli_format.cpp b/src/app/file/fli_format.cpp index 159db508b..eaf30fb73 100644 --- a/src/app/file/fli_format.cpp +++ b/src/app/file/fli_format.cpp @@ -138,8 +138,7 @@ bool FliFormat::onLoad(FileOp* fop) ++frame_out; } else if (palChange) { - Cel* cel = Cel::createLink(prevCel); - cel->setFrame(frame_out); + Cel* cel = Cel::MakeLink(frame_out, prevCel); layer->addCel(cel); ++frame_out; diff --git a/src/dio/aseprite_decoder.cpp b/src/dio/aseprite_decoder.cpp index ff9905d9f..8ef47ab9f 100644 --- a/src/dio/aseprite_decoder.cpp +++ b/src/dio/aseprite_decoder.cpp @@ -1,5 +1,5 @@ // Aseprite Document IO Library -// Copyright (c) 2018 Igara Studio S.A. +// Copyright (c) 2018-2019 Igara Studio S.A. // Copyright (c) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -651,12 +651,10 @@ doc::Cel* AsepriteDecoder::readCelChunk(doc::Sprite* sprite, // different X, Y, or opacity per link, in that case we must // create a copy. if (link->x() == x && link->y() == y && link->opacity() == opacity) { - cel.reset(doc::Cel::createLink(link)); - cel->setFrame(frame); + cel.reset(doc::Cel::MakeLink(frame, link)); } else { - cel.reset(doc::Cel::createCopy(link)); - cel->setFrame(frame); + cel.reset(doc::Cel::MakeCopy(frame, link)); cel->setPosition(x, y); cel->setOpacity(opacity); } diff --git a/src/doc/cel.cpp b/src/doc/cel.cpp index bffd5d723..6c67ff34b 100644 --- a/src/doc/cel.cpp +++ b/src/doc/cel.cpp @@ -1,4 +1,5 @@ // Aseprite Document Library +// Copyright (c) 2019 Igara Studio S.A. // Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -34,10 +35,11 @@ Cel::Cel(frame_t frame, const CelDataRef& celData) } // static -Cel* Cel::createCopy(const Cel* other) +Cel* Cel::MakeCopy(const frame_t newFrame, + const Cel* other) { - Cel* cel = new Cel(other->frame(), - ImageRef(Image::createCopy(other->image()))); + Cel* cel = new Cel(newFrame, + ImageRef(Image::createCopy(other->image()))); cel->setPosition(other->position()); cel->setOpacity(other->opacity()); @@ -45,9 +47,10 @@ Cel* Cel::createCopy(const Cel* other) } // static -Cel* Cel::createLink(const Cel* other) +Cel* Cel::MakeLink(const frame_t newFrame, + const Cel* other) { - return new Cel(other->frame(), other->dataRef()); + return new Cel(newFrame, other->dataRef()); } void Cel::setFrame(frame_t frame) diff --git a/src/doc/cel.h b/src/doc/cel.h index 4688fdcf4..7fddbcc0d 100644 --- a/src/doc/cel.h +++ b/src/doc/cel.h @@ -1,4 +1,5 @@ // Aseprite Document Library +// Copyright (c) 2019 Igara Studio S.A. // Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -27,8 +28,8 @@ namespace doc { Cel(frame_t frame, const ImageRef& image); Cel(frame_t frame, const CelDataRef& celData); - static Cel* createCopy(const Cel* other); - static Cel* createLink(const Cel* other); + static Cel* MakeCopy(const frame_t newFrame, const Cel* other); + static Cel* MakeLink(const frame_t newFrame, const Cel* other); frame_t frame() const { return m_frame; } int x() const { return m_data->position().x; } diff --git a/src/doc/sprite_tests.cpp b/src/doc/sprite_tests.cpp index 83413908e..d51f23df8 100644 --- a/src/doc/sprite_tests.cpp +++ b/src/doc/sprite_tests.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2018 Igara Studio S.A. +// Copyright (c) 2018-2019 Igara Studio S.A. // Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -104,17 +104,14 @@ TEST(Sprite, CelsRange) ImageRef imgA(Image::create(IMAGE_RGB, 32, 32)); Cel* celA = new Cel(frame_t(0), imgA); - Cel* celB = Cel::createLink(celA); - celB->setFrame(frame_t(2)); + Cel* celB = Cel::MakeLink(frame_t(2), celA); lay1->addCel(celA); lay1->addCel(celB); ImageRef imgC(Image::create(IMAGE_RGB, 32, 32)); Cel* celC = new Cel(frame_t(0), imgC); - Cel* celD = Cel::createCopy(celC); - Cel* celE = Cel::createLink(celD); - celD->setFrame(frame_t(1)); - celE->setFrame(frame_t(2)); + Cel* celD = Cel::MakeCopy(frame_t(1), celC); + Cel* celE = Cel::MakeLink(frame_t(2), celD); lay2->addCel(celC); lay2->addCel(celD); lay2->addCel(celE); @@ -123,8 +120,7 @@ TEST(Sprite, CelsRange) ImageRef imgG(Image::create(IMAGE_RGB, 32, 32)); Cel* celF = new Cel(frame_t(0), imgF); Cel* celG = new Cel(frame_t(1), imgG); - Cel* celH = Cel::createLink(celG); - celH->setFrame(frame_t(2)); + Cel* celH = Cel::MakeLink(frame_t(2), celG); lay3->addCel(celF); lay3->addCel(celG); lay3->addCel(celH);