A tilemap cannot be a background layer in the first release

This commit is contained in:
David Capello 2019-11-06 15:01:22 -03:00
parent 962ad545ad
commit 9f6b18ddb3
6 changed files with 34 additions and 5 deletions

View File

@ -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<Doc*>(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(

View File

@ -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:

View File

@ -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:

View File

@ -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)

View File

@ -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;

View File

@ -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();