2007-11-16 18:25:45 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2010-02-01 21:25:40 +00:00
|
|
|
* Copyright (C) 2001-2010 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"
|
|
|
|
|
2010-09-26 18:59:32 +00:00
|
|
|
#include "gui/jinete.h"
|
2007-09-23 20:13:58 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "commands/command.h"
|
2009-08-17 19:32:09 +00:00
|
|
|
#include "console.h"
|
2009-12-11 14:53:05 +00:00
|
|
|
#include "app.h"
|
2007-11-09 04:10:19 +00:00
|
|
|
#include "modules/gui.h"
|
|
|
|
#include "raster/layer.h"
|
2007-09-23 20:13:58 +00:00
|
|
|
#include "raster/sprite.h"
|
2007-11-09 04:10:19 +00:00
|
|
|
#include "raster/undo.h"
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "sprite_wrappers.h"
|
2007-09-23 20:13:58 +00:00
|
|
|
|
2009-06-11 15:11:11 +00:00
|
|
|
static Layer *duplicate_layer(Sprite* sprite);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// duplicate_layer
|
|
|
|
|
|
|
|
class DuplicateLayerCommand : public Command
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DuplicateLayerCommand();
|
|
|
|
Command* clone() const { return new DuplicateLayerCommand(*this); }
|
|
|
|
|
|
|
|
protected:
|
2010-07-31 15:23:45 +00:00
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
2009-10-09 01:34:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DuplicateLayerCommand::DuplicateLayerCommand()
|
|
|
|
: Command("duplicate_layer",
|
|
|
|
"Duplicate Layer",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-31 15:23:45 +00:00
|
|
|
bool DuplicateLayerCommand::onEnabled(Context* context)
|
2007-11-09 04:10:19 +00:00
|
|
|
{
|
2009-10-09 01:34:06 +00:00
|
|
|
const CurrentSpriteReader sprite(context);
|
2010-03-31 00:43:18 +00:00
|
|
|
return sprite && sprite->getCurrentLayer();
|
2007-11-09 04:10:19 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 15:23:45 +00:00
|
|
|
void DuplicateLayerCommand::onExecute(Context* context)
|
2007-09-23 20:13:58 +00:00
|
|
|
{
|
2009-10-09 01:34:06 +00:00
|
|
|
CurrentSpriteWriter sprite(context);
|
2009-06-11 15:11:11 +00:00
|
|
|
if (duplicate_layer(sprite) != NULL)
|
2009-06-01 02:59:15 +00:00
|
|
|
update_screen_for_sprite(sprite);
|
2007-11-09 04:10:19 +00:00
|
|
|
}
|
|
|
|
|
2009-11-17 13:12:26 +00:00
|
|
|
static Layer* duplicate_layer(Sprite* sprite)
|
2007-11-09 04:10:19 +00:00
|
|
|
{
|
2008-02-29 19:29:49 +00:00
|
|
|
/* open undo */
|
2010-09-19 18:23:15 +00:00
|
|
|
if (sprite->getUndo()->isEnabled()) {
|
2010-09-19 20:44:06 +00:00
|
|
|
sprite->getUndo()->setLabel("Layer Duplication");
|
2010-10-01 02:55:35 +00:00
|
|
|
sprite->getUndo()->undo_open();
|
2008-03-27 16:58:14 +00:00
|
|
|
}
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2010-03-31 00:43:18 +00:00
|
|
|
Layer* layer_copy = sprite->getCurrentLayer()->duplicate_for(sprite);
|
2007-11-09 04:10:19 +00:00
|
|
|
if (!layer_copy) {
|
2010-09-19 18:23:15 +00:00
|
|
|
if (sprite->getUndo()->isEnabled())
|
2010-10-01 02:55:35 +00:00
|
|
|
sprite->getUndo()->undo_close();
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2009-06-11 15:11:11 +00:00
|
|
|
Console console;
|
|
|
|
console.printf("Not enough memory");
|
2007-11-09 04:10:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-17 13:12:26 +00:00
|
|
|
layer_copy->set_background(false);
|
|
|
|
layer_copy->set_moveable(true);
|
2010-09-19 03:03:32 +00:00
|
|
|
layer_copy->setName(layer_copy->getName() + " Copy");
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
/* add the new layer in the sprite */
|
2010-09-19 18:23:15 +00:00
|
|
|
if (sprite->getUndo()->isEnabled())
|
2010-10-01 02:55:35 +00:00
|
|
|
sprite->getUndo()->undo_add_layer(sprite->getCurrentLayer()->get_parent(), layer_copy);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2010-03-31 00:43:18 +00:00
|
|
|
sprite->getCurrentLayer()->get_parent()->add_layer(layer_copy);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2010-09-19 18:23:15 +00:00
|
|
|
if (sprite->getUndo()->isEnabled()) {
|
2010-10-01 02:55:35 +00:00
|
|
|
sprite->getUndo()->undo_move_layer(layer_copy);
|
|
|
|
sprite->getUndo()->undo_set_layer(sprite);
|
|
|
|
sprite->getUndo()->undo_close();
|
2007-11-09 04:10:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 00:43:18 +00:00
|
|
|
sprite->getCurrentLayer()->get_parent()->move_layer(layer_copy, sprite->getCurrentLayer());
|
|
|
|
sprite->setCurrentLayer(layer_copy);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
|
|
|
return layer_copy;
|
2007-09-23 20:13:58 +00:00
|
|
|
}
|
2007-12-05 01:30:50 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// CommandFactory
|
|
|
|
|
|
|
|
Command* CommandFactory::create_duplicate_layer_command()
|
|
|
|
{
|
|
|
|
return new DuplicateLayerCommand;
|
|
|
|
}
|