Add support to create layers inside groups

This commit is contained in:
David Capello 2016-06-08 15:55:44 -03:00
parent f6fa39ba52
commit 64c1ecf555
4 changed files with 27 additions and 18 deletions

View File

@ -378,7 +378,7 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
DocumentApi api = document->getApi(transaction);
// Add the layer in the sprite.
LayerImage* resultLayer = api.newLayer(sprite, "Sprite Sheet");
LayerImage* resultLayer = api.newLayer(sprite->root(), "Sprite Sheet");
// Add all frames+cels to the new layer
for (size_t i=0; i<animation.size(); ++i) {

View File

@ -105,7 +105,20 @@ void NewLayerCommand::onExecute(Context* context)
name = window.name()->text();
}
LayerGroup* parent = sprite->root();
Layer* activeLayer = writer.layer();
if (activeLayer) {
if (activeLayer->isGroup() &&
activeLayer->isExpanded() &&
!m_group) {
parent = static_cast<LayerGroup*>(activeLayer);
activeLayer = nullptr;
}
else {
parent = activeLayer->parent();
}
}
Layer* layer;
{
Transaction transaction(
@ -114,9 +127,9 @@ void NewLayerCommand::onExecute(Context* context)
DocumentApi api = document->getApi(transaction);
if (m_group)
layer = api.newGroup(sprite, name);
layer = api.newGroup(parent, name);
else
layer = api.newLayer(sprite, name);
layer = api.newLayer(parent, name);
// If "top" parameter is false, create the layer above the active
// one.

View File

@ -396,31 +396,27 @@ void DocumentApi::swapCel(
if (cel2) setCelFramePosition(cel2, frame1);
}
LayerImage* DocumentApi::newLayer(Sprite* sprite, const std::string& name)
LayerImage* DocumentApi::newLayer(LayerGroup* parent, const std::string& name)
{
LayerImage* layer = new LayerImage(sprite);
LayerImage* layer = new LayerImage(parent->sprite());
layer->setName(name);
addLayer(sprite->root(), layer,
sprite->root()->lastLayer());
addLayer(parent, layer, parent->lastLayer());
return layer;
}
LayerGroup* DocumentApi::newGroup(Sprite* sprite, const std::string& name)
LayerGroup* DocumentApi::newGroup(LayerGroup* parent, const std::string& name)
{
LayerGroup* layer = new LayerGroup(sprite);
LayerGroup* layer = new LayerGroup(parent->sprite());
layer->setName(name);
addLayer(sprite->root(), layer,
sprite->root()->lastLayer());
addLayer(parent, layer, parent->lastLayer());
return layer;
}
void DocumentApi::addLayer(LayerGroup* folder, Layer* newLayer, Layer* afterThis)
void DocumentApi::addLayer(LayerGroup* parent, Layer* newLayer, Layer* afterThis)
{
m_transaction.execute(new cmd::AddLayer(folder, newLayer, afterThis));
m_transaction.execute(new cmd::AddLayer(parent, newLayer, afterThis));
}
void DocumentApi::removeLayer(Layer* layer)

View File

@ -80,9 +80,9 @@ namespace app {
LayerImage* layer, frame_t frame1, frame_t frame2);
// Layers API
LayerImage* newLayer(Sprite* sprite, const std::string& name);
LayerGroup* newGroup(Sprite* sprite, const std::string& name);
void addLayer(LayerGroup* folder, Layer* newLayer, Layer* afterThis);
LayerImage* newLayer(LayerGroup* parent, const std::string& name);
LayerGroup* newGroup(LayerGroup* parent, const std::string& name);
void addLayer(LayerGroup* parent, Layer* newLayer, Layer* afterThis);
void removeLayer(Layer* layer);
void restackLayerAfter(Layer* layer, Layer* afterThis);
void restackLayerBefore(Layer* layer, Layer* beforeThis);