aseprite/src/commands/cmd_duplicate_layer.cpp

104 lines
3.1 KiB
C++
Raw Normal View History

2007-11-16 18:25:45 +00:00
/* ASE - Allegro Sprite Editor
2011-01-18 23:49:53 +00:00
* Copyright (C) 2001-2011 David Capello
2007-09-23 20:13:58 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "gui/gui.h"
2007-09-23 20:13:58 +00:00
#include "commands/command.h"
#include "console.h"
2009-12-11 14:53:05 +00:00
#include "app.h"
#include "modules/gui.h"
#include "raster/layer.h"
2007-09-23 20:13:58 +00:00
#include "raster/sprite.h"
2011-03-13 20:33:42 +00:00
#include "raster/undo_history.h"
#include "document_wrappers.h"
//////////////////////////////////////////////////////////////////////
// Duplicate Layer command
class DuplicateLayerCommand : public Command
{
public:
DuplicateLayerCommand();
Command* clone() const { return new DuplicateLayerCommand(*this); }
protected:
bool onEnabled(Context* context);
void onExecute(Context* context);
};
DuplicateLayerCommand::DuplicateLayerCommand()
2011-01-20 23:46:58 +00:00
: Command("DuplicateLayer",
"Duplicate Layer",
CmdRecordableFlag)
{
}
bool DuplicateLayerCommand::onEnabled(Context* context)
{
const ActiveDocumentReader document(context);
const Sprite* sprite(document ? document->getSprite(): 0);
return sprite && sprite->getCurrentLayer();
}
void DuplicateLayerCommand::onExecute(Context* context)
2007-09-23 20:13:58 +00:00
{
#if 0 // TODO IMPLEMENT THIS
ActiveDocumentWriter document(context);
Sprite* sprite = document->getSprite();
UndoHistory* undo = document->getUndoHistory();
2011-03-23 00:22:13 +00:00
UndoTransaction undoTransaction(document, "Layer Duplication");
// Clone the layer
UniquePtr<Layer> newLayerPtr(sprite->getCurrentLayer()->clone());
newLayerPtr->set_background(false);
newLayerPtr->set_moveable(true);
newLayerPtr->setName(layer_copy->getName() + " Copy");
// Add the new layer in the sprite.
if (undo->isEnabled())
undo->undo_add_layer(sprite->getCurrentLayer()->get_parent(), newLayerPtr);
sprite->getCurrentLayer()->get_parent()->add_layer(newLayerPtr);
// Release the pointer as it is owned by the sprite now
Layer* newLayer = newLayerPtr.release();
if (undo->isEnabled()) {
undo->undo_move_layer(newLayer);
undo->undo_set_layer(sprite);
2008-03-27 16:58:14 +00:00
}
2011-03-23 00:22:13 +00:00
undoTransaction.commit();
sprite->getCurrentLayer()->get_parent()->move_layer(newLayer, sprite->getCurrentLayer());
sprite->setCurrentLayer(newLayer);
update_screen_for_document(document);
#endif
2007-09-23 20:13:58 +00:00
}
//////////////////////////////////////////////////////////////////////
// CommandFactory
2011-01-20 23:46:58 +00:00
Command* CommandFactory::createDuplicateLayerCommand()
{
return new DuplicateLayerCommand;
}