aseprite/src/commands/cmd_duplicate_layer.cpp

101 lines
2.7 KiB
C++
Raw Normal View History

2007-11-16 18:25:45 +00:00
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2009 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 "jinete/jinete.h"
2007-09-23 20:13:58 +00:00
#include "commands/commands.h"
#include "console/console.h"
2007-09-23 20:13:58 +00:00
#include "core/app.h"
#include "modules/gui.h"
2007-09-23 20:13:58 +00:00
#include "modules/sprites.h"
#include "raster/layer.h"
2007-09-23 20:13:58 +00:00
#include "raster/sprite.h"
#include "raster/undo.h"
2007-09-23 20:13:58 +00:00
static Layer *duplicate_layer();
static bool cmd_duplicate_layer_enabled(const char *argument)
{
CurrentSprite sprite;
return sprite && sprite->layer;
}
static void cmd_duplicate_layer_execute(const char *argument)
2007-09-23 20:13:58 +00:00
{
CurrentSprite sprite;
if (duplicate_layer() != NULL)
update_screen_for_sprite(sprite);
}
static Layer *duplicate_layer()
{
CurrentSprite sprite;
Layer *layer_copy;
char buf[1024];
if (!sprite || !sprite->layer)
return NULL;
/* open undo */
2008-03-27 16:58:14 +00:00
if (undo_is_enabled(sprite->undo)) {
undo_set_label(sprite->undo, "Layer Duplication");
undo_open(sprite->undo);
2008-03-27 16:58:14 +00:00
}
layer_copy = layer_new_copy(sprite, sprite->layer);
if (!layer_copy) {
if (undo_is_enabled(sprite->undo))
undo_close(sprite->undo);
console_printf("Not enough memory");
return NULL;
}
layer_copy->flags &= ~(LAYER_IS_LOCKMOVE | LAYER_IS_BACKGROUND);
sprintf(buf, "%s %s", layer_copy->name, _("Copy"));
layer_set_name(layer_copy, buf);
/* add the new layer in the sprite */
if (undo_is_enabled(sprite->undo))
undo_add_layer(sprite->undo, sprite->layer->parent_layer, layer_copy);
layer_add_layer(sprite->layer->parent_layer, layer_copy);
if (undo_is_enabled(sprite->undo)) {
undo_move_layer(sprite->undo, layer_copy);
undo_set_layer(sprite->undo, sprite);
undo_close(sprite->undo);
}
layer_move_layer(sprite->layer->parent_layer, layer_copy, sprite->layer);
sprite_set_layer(sprite, layer_copy);
return layer_copy;
2007-09-23 20:13:58 +00:00
}
Command cmd_duplicate_layer = {
CMD_DUPLICATE_LAYER,
cmd_duplicate_layer_enabled,
NULL,
cmd_duplicate_layer_execute,
NULL
};