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"
|
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
#include "jinete/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:
|
|
|
|
bool enabled(Context* context);
|
|
|
|
void execute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
DuplicateLayerCommand::DuplicateLayerCommand()
|
|
|
|
: Command("duplicate_layer",
|
|
|
|
"Duplicate Layer",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DuplicateLayerCommand::enabled(Context* context)
|
2007-11-09 04:10:19 +00:00
|
|
|
{
|
2009-10-09 01:34:06 +00:00
|
|
|
const CurrentSpriteReader sprite(context);
|
2009-06-01 02:59:15 +00:00
|
|
|
return sprite && sprite->layer;
|
2007-11-09 04:10:19 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
void DuplicateLayerCommand::execute(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 */
|
2008-03-27 16:58:14 +00:00
|
|
|
if (undo_is_enabled(sprite->undo)) {
|
|
|
|
undo_set_label(sprite->undo, "Layer Duplication");
|
2008-02-29 19:29:49 +00:00
|
|
|
undo_open(sprite->undo);
|
2008-03-27 16:58:14 +00:00
|
|
|
}
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2009-11-17 13:12:26 +00:00
|
|
|
Layer* layer_copy = sprite->layer->duplicate_for(sprite);
|
2007-11-09 04:10:19 +00:00
|
|
|
if (!layer_copy) {
|
2008-02-29 19:29:49 +00:00
|
|
|
if (undo_is_enabled(sprite->undo))
|
|
|
|
undo_close(sprite->undo);
|
|
|
|
|
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);
|
|
|
|
layer_copy->set_name(layer_copy->get_name() + " " + _("Copy"));
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
/* add the new layer in the sprite */
|
|
|
|
if (undo_is_enabled(sprite->undo))
|
2009-11-17 13:12:26 +00:00
|
|
|
undo_add_layer(sprite->undo, sprite->layer->get_parent(), layer_copy);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2009-11-17 13:12:26 +00:00
|
|
|
sprite->layer->get_parent()->add_layer(layer_copy);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
|
|
|
if (undo_is_enabled(sprite->undo)) {
|
|
|
|
undo_move_layer(sprite->undo, layer_copy);
|
|
|
|
undo_set_layer(sprite->undo, sprite);
|
|
|
|
undo_close(sprite->undo);
|
|
|
|
}
|
|
|
|
|
2009-11-17 13:12:26 +00:00
|
|
|
sprite->layer->get_parent()->move_layer(layer_copy, sprite->layer);
|
2007-11-09 04:10:19 +00:00
|
|
|
sprite_set_layer(sprite, layer_copy);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|