mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Flatten layers command no longer converts result to background when it shouldn't. (fix #806)
This commit is contained in:
parent
5e3ba8237a
commit
3eb01db8e1
@ -12,6 +12,7 @@
|
|||||||
#include "app/cmd/flatten_layers.h"
|
#include "app/cmd/flatten_layers.h"
|
||||||
|
|
||||||
#include "app/cmd/add_layer.h"
|
#include "app/cmd/add_layer.h"
|
||||||
|
#include "app/cmd/set_layer_name.h"
|
||||||
#include "app/cmd/configure_background.h"
|
#include "app/cmd/configure_background.h"
|
||||||
#include "app/cmd/copy_rect.h"
|
#include "app/cmd/copy_rect.h"
|
||||||
#include "app/cmd/remove_layer.h"
|
#include "app/cmd/remove_layer.h"
|
||||||
@ -43,21 +44,24 @@ void FlattenLayers::onExecute()
|
|||||||
sprite->width(),
|
sprite->width(),
|
||||||
sprite->height()));
|
sprite->height()));
|
||||||
|
|
||||||
// If there aren't a background layer we must to create the background.
|
LayerImage* flatLayer; // The layer onto which everything will be flattened.
|
||||||
LayerImage* background = sprite->backgroundLayer();
|
color_t bgcolor; // The background color to use for flatLayer.
|
||||||
bool created = false;
|
|
||||||
if (!background) {
|
flatLayer = sprite->backgroundLayer();
|
||||||
background = new LayerImage(sprite);
|
if (flatLayer && flatLayer->isVisible())
|
||||||
executeAndAdd(new cmd::AddLayer(sprite->folder(), background, nullptr));
|
{
|
||||||
executeAndAdd(new cmd::ConfigureBackground(background));
|
// There exists a visible background layer, so we will flatten onto that.
|
||||||
created = true;
|
bgcolor = doc->bgColor(flatLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
color_t bgcolor;
|
|
||||||
if (created || !background->isVisible())
|
|
||||||
bgcolor = doc->bgColor(background); // Use color bar background color
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Create a new transparent layer to flatten everything onto.
|
||||||
|
flatLayer = new LayerImage(sprite);
|
||||||
|
ASSERT(flatLayer->isVisible());
|
||||||
|
executeAndAdd(new cmd::AddLayer(sprite->folder(), flatLayer, nullptr));
|
||||||
|
executeAndAdd(new cmd::SetLayerName(flatLayer, "Flattened"));
|
||||||
bgcolor = sprite->transparentColor();
|
bgcolor = sprite->transparentColor();
|
||||||
|
}
|
||||||
|
|
||||||
render::Render render;
|
render::Render render;
|
||||||
render.setBgType(render::BgType::NONE);
|
render.setBgType(render::BgType::NONE);
|
||||||
@ -71,7 +75,7 @@ void FlattenLayers::onExecute()
|
|||||||
// TODO Keep cel links when possible
|
// TODO Keep cel links when possible
|
||||||
|
|
||||||
ImageRef cel_image;
|
ImageRef cel_image;
|
||||||
Cel* cel = background->cel(frame);
|
Cel* cel = flatLayer->cel(frame);
|
||||||
if (cel) {
|
if (cel) {
|
||||||
if (cel->links())
|
if (cel->links())
|
||||||
executeAndAdd(new cmd::UnlinkCel(cel));
|
executeAndAdd(new cmd::UnlinkCel(cel));
|
||||||
@ -85,22 +89,14 @@ void FlattenLayers::onExecute()
|
|||||||
else {
|
else {
|
||||||
cel_image.reset(Image::createCopy(image.get()));
|
cel_image.reset(Image::createCopy(image.get()));
|
||||||
cel = new Cel(frame, cel_image);
|
cel = new Cel(frame, cel_image);
|
||||||
background->addCel(cel);
|
flatLayer->addCel(cel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show background if it's hidden
|
|
||||||
if (!background->isVisible()) {
|
|
||||||
LayerFlags newFlags = LayerFlags(
|
|
||||||
int(background->flags()) | int(LayerFlags::Visible));
|
|
||||||
|
|
||||||
executeAndAdd(new cmd::SetLayerFlags(background, newFlags));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete old layers.
|
// Delete old layers.
|
||||||
LayerList layers = sprite->folder()->getLayersList();
|
LayerList layers = sprite->folder()->getLayersList();
|
||||||
for (Layer* layer : layers)
|
for (Layer* layer : layers)
|
||||||
if (layer != background)
|
if (layer != flatLayer)
|
||||||
executeAndAdd(new cmd::RemoveLayer(layer));
|
executeAndAdd(new cmd::RemoveLayer(layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user