From 9f6b18ddb3fc46bca369fd76ef54e9299cc7ad6c Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 6 Nov 2019 15:01:22 -0300 Subject: [PATCH] A tilemap cannot be a background layer in the first release --- src/app/cmd/background_from_layer.cpp | 8 +++++--- src/app/cmd/copy_cel.cpp | 9 +++++++++ src/app/cmd/move_cel.cpp | 10 ++++++++++ src/app/commands/cmd_background_from_layer.cpp | 6 +++++- src/app/context_flags.cpp | 3 +++ src/app/context_flags.h | 3 ++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/app/cmd/background_from_layer.cpp b/src/app/cmd/background_from_layer.cpp index d64d971e0..a9c7b5f5b 100644 --- a/src/app/cmd/background_from_layer.cpp +++ b/src/app/cmd/background_from_layer.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 @@ -41,21 +42,22 @@ BackgroundFromLayer::BackgroundFromLayer(Layer* layer) void BackgroundFromLayer::onExecute() { Layer* layer = this->layer(); + ASSERT(!layer->isTilemap()); // TODO support background tilemaps + Sprite* sprite = layer->sprite(); auto doc = static_cast(sprite->document()); color_t bgcolor = doc->bgColor(); // Create a temporary image to draw each cel of the new Background // layer. - ImageRef bg_image(Image::create(sprite->pixelFormat(), - sprite->width(), - sprite->height())); + ImageRef bg_image(Image::create(sprite->spec())); CelList cels; layer->getCels(cels); for (Cel* cel : cels) { Image* cel_image = cel->image(); ASSERT(cel_image); + ASSERT(cel_image->pixelFormat() != IMAGE_TILEMAP); clear_image(bg_image.get(), bgcolor); render::composite_image( diff --git a/src/app/cmd/copy_cel.cpp b/src/app/cmd/copy_cel.cpp index 24cec3661..010dc9a8a 100644 --- a/src/app/cmd/copy_cel.cpp +++ b/src/app/cmd/copy_cel.cpp @@ -24,6 +24,7 @@ #include "doc/layer.h" #include "doc/primitives.h" #include "doc/sprite.h" +#include "render/rasterize.h" #include "render/render.h" namespace app { @@ -89,9 +90,17 @@ void CopyCel::onExecute() !srcCel || !srcImage) return; + ASSERT(!dstLayer->isTilemap()); // TODO support background tilemaps + if (createLink) { executeAndAdd(new cmd::SetCelData(dstCel, srcCel->dataRef())); } + // Rasterize tilemap into the regular image background layer + else if (srcLayer->isTilemap()) { + ImageRef tmp(Image::createCopy(dstImage.get())); + render::rasterize(tmp.get(), srcCel, 0, 0, false); + executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); + } else { BlendMode blend = (srcLayer->isBackground() ? BlendMode::SRC: diff --git a/src/app/cmd/move_cel.cpp b/src/app/cmd/move_cel.cpp index eb701f0d6..158bbf5cd 100644 --- a/src/app/cmd/move_cel.cpp +++ b/src/app/cmd/move_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 @@ -25,6 +26,7 @@ #include "doc/layer.h" #include "doc/primitives.h" #include "doc/sprite.h" +#include "render/rasterize.h" #include "render/render.h" namespace app { @@ -90,10 +92,18 @@ void MoveCel::onExecute() !srcCel || !srcImage) return; + ASSERT(!dstLayer->isTilemap()); // TODO support background tilemaps + if (createLink) { executeAndAdd(new cmd::SetCelData(dstCel, srcCel->dataRef())); executeAndAdd(new cmd::UnlinkCel(srcCel)); } + // Rasterize tilemap into the regular image background layer + else if (srcLayer->isTilemap()) { + ImageRef tmp(Image::createCopy(dstImage.get())); + render::rasterize(tmp.get(), srcCel, 0, 0, false); + executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); + } else { BlendMode blend = (srcLayer->isBackground() ? BlendMode::SRC: diff --git a/src/app/commands/cmd_background_from_layer.cpp b/src/app/commands/cmd_background_from_layer.cpp index 68e3867e9..8a82d8fc3 100644 --- a/src/app/commands/cmd_background_from_layer.cpp +++ b/src/app/commands/cmd_background_from_layer.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -43,7 +44,10 @@ bool BackgroundFromLayerCommand::onEnabled(Context* context) // Doesn't have a background layer !context->checkFlags(ContextFlags::HasBackgroundLayer) && // Isn't a reference layer - !context->checkFlags(ContextFlags::ActiveLayerIsReference); + !context->checkFlags(ContextFlags::ActiveLayerIsReference) && + // Isn't a tilemap layer + // TODO support background tilemaps + !context->checkFlags(ContextFlags::ActiveLayerIsTilemap); } void BackgroundFromLayerCommand::onExecute(Context* context) diff --git a/src/app/context_flags.cpp b/src/app/context_flags.cpp index ea81294e5..362b6d778 100644 --- a/src/app/context_flags.cpp +++ b/src/app/context_flags.cpp @@ -99,6 +99,9 @@ void ContextFlags::updateFlagsFromSite(const Site& site) if (layer->isReference()) m_flags |= ActiveLayerIsReference; + if (layer->isTilemap()) + m_flags |= ActiveLayerIsTilemap; + if (layer->isImage()) { m_flags |= ActiveLayerIsImage; diff --git a/src/app/context_flags.h b/src/app/context_flags.h index b4d59ad16..ba0d47799 100644 --- a/src/app/context_flags.h +++ b/src/app/context_flags.h @@ -33,7 +33,8 @@ namespace app { ActiveLayerIsVisible = 1 << 11, ActiveLayerIsEditable = 1 << 12, ActiveLayerIsReference = 1 << 13, - HasSelectedColors = 1 << 14, + ActiveLayerIsTilemap = 1 << 14, + HasSelectedColors = 1 << 15, }; ContextFlags();