diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 3a6e9af49..b39cb3c36 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -369,6 +369,7 @@ add_library(app-lib ui_context.cpp util/autocrop.cpp util/clipboard.cpp + util/create_cel_copy.cpp util/expand_cel_canvas.cpp util/filetoks.cpp util/msk_file.cpp diff --git a/src/app/cmd/copy_cel.cpp b/src/app/cmd/copy_cel.cpp index 0576870e7..5ba9e6f33 100644 --- a/src/app/cmd/copy_cel.cpp +++ b/src/app/cmd/copy_cel.cpp @@ -19,6 +19,7 @@ #include "app/cmd/set_cel_data.h" #include "app/cmd/unlink_cel.h" #include "app/document.h" +#include "app/util/create_cel_copy.h" #include "doc/cel.h" #include "doc/layer.h" #include "doc/primitives.h" @@ -109,11 +110,12 @@ void CopyCel::onExecute() executeAndAdd(new cmd::RemoveCel(dstCel)); if (srcCel) { - if (createLink) + if (createLink) { dstCel = Cel::createLink(srcCel); + dstCel->setFrame(m_dstFrame); + } else - dstCel = Cel::createCopy(srcCel); - dstCel->setFrame(m_dstFrame); + dstCel = create_cel_copy(srcCel, dstSprite, m_dstFrame); executeAndAdd(new cmd::AddCel(dstLayer, dstCel)); } diff --git a/src/app/cmd/move_cel.cpp b/src/app/cmd/move_cel.cpp index 59aac8d69..95248afdf 100644 --- a/src/app/cmd/move_cel.cpp +++ b/src/app/cmd/move_cel.cpp @@ -21,6 +21,7 @@ #include "app/cmd/set_cel_frame.h" #include "app/cmd/unlink_cel.h" #include "app/document.h" +#include "app/util/create_cel_copy.h" #include "doc/cel.h" #include "doc/layer.h" #include "doc/primitives.h" @@ -118,8 +119,7 @@ void MoveCel::onExecute() executeAndAdd(new cmd::SetCelFrame(srcCel, m_dstFrame)); } else { - dstCel = Cel::createCopy(srcCel); - dstCel->setFrame(m_dstFrame); + dstCel = create_cel_copy(srcCel, dstSprite, m_dstFrame); executeAndAdd(new cmd::AddCel(dstLayer, dstCel)); executeAndAdd(new cmd::ClearCel(srcCel)); diff --git a/src/app/document.cpp b/src/app/document.cpp index eea86b51a..ec0df837a 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -20,6 +20,7 @@ #include "app/file/format_options.h" #include "app/flatten.h" #include "app/pref/preferences.h" +#include "app/util/create_cel_copy.h" #include "base/memory.h" #include "base/mutex.h" #include "base/scoped_lock.h" @@ -364,7 +365,9 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La newCel->setFrame(sourceCel->frame()); } else { - newCel.reset(Cel::createCopy(sourceCel)); + newCel.reset(create_cel_copy(sourceCel, + destLayer->sprite(), + sourceCel->frame())); linked.insert(std::make_pair(sourceCel->data()->id(), newCel.get())); } diff --git a/src/app/util/create_cel_copy.cpp b/src/app/util/create_cel_copy.cpp new file mode 100644 index 000000000..1d0fb2283 --- /dev/null +++ b/src/app/util/create_cel_copy.cpp @@ -0,0 +1,43 @@ +// Aseprite +// Copyright (C) 2001-2015 David Capello +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "base/unique_ptr.h" +#include "doc/cel.h" +#include "doc/image.h" +#include "doc/sprite.h" +#include "render/render.h" + +namespace app { + +using namespace doc; + +Cel* create_cel_copy(const Cel* srcCel, + const Sprite* dstSprite, + const frame_t dstFrame) +{ + base::UniquePtr dstCel( + new Cel(dstFrame, + ImageRef(Image::create(dstSprite->pixelFormat(), + srcCel->image()->width(), + srcCel->image()->height())))); + + render::composite_image( + dstCel->image(), srcCel->image(), + srcCel->sprite()->palette(srcCel->frame()), // TODO add dst palette + 0, 0, 255, BlendMode::SRC); + + dstCel->setPosition(srcCel->position()); + dstCel->setOpacity(srcCel->opacity()); + + return dstCel.release(); +} + +} // namespace app diff --git a/src/app/util/create_cel_copy.h b/src/app/util/create_cel_copy.h new file mode 100644 index 000000000..e7c787f04 --- /dev/null +++ b/src/app/util/create_cel_copy.h @@ -0,0 +1,27 @@ +// Aseprite +// Copyright (C) 2001-2015 David Capello +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. + +#ifndef APP_UTIL_CREATE_CEL_COPY_H_INCLUDED +#define APP_UTIL_CREATE_CEL_COPY_H_INCLUDED +#pragma once + +#include "doc/frame.h" + +namespace doc { + class Cel; + class Sprite; +} + +namespace app { + + Cel* create_cel_copy(const Cel* srcCel, + const Sprite* dstSprite, + const frame_t dstFrame); + +} // namespace app + +#endif