2007-11-16 18:25:45 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2008-02-10 12:55:22 +00:00
|
|
|
* Copyright (C) 2001-2008 David A. 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
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
#include "commands/commands.h"
|
2007-11-09 04:10:19 +00:00
|
|
|
#include "console/console.h"
|
2007-09-23 20:13:58 +00:00
|
|
|
#include "core/app.h"
|
2007-11-09 04:10:19 +00:00
|
|
|
#include "modules/gui.h"
|
2007-09-23 20:13:58 +00:00
|
|
|
#include "modules/sprites.h"
|
2007-11-09 04:10:19 +00:00
|
|
|
#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"
|
2007-09-23 20:13:58 +00:00
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
static Layer *duplicate_layer(void);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
static bool cmd_duplicate_layer_enabled(const char *argument)
|
2007-11-09 04:10:19 +00:00
|
|
|
{
|
|
|
|
return
|
|
|
|
current_sprite != NULL &&
|
|
|
|
current_sprite->layer != NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
static void cmd_duplicate_layer_execute(const char *argument)
|
2007-09-23 20:13:58 +00:00
|
|
|
{
|
2007-12-05 01:30:50 +00:00
|
|
|
if (duplicate_layer() != NULL)
|
2007-11-19 14:23:15 +00:00
|
|
|
update_screen_for_sprite(current_sprite);
|
2007-11-09 04:10:19 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
static Layer *duplicate_layer(void)
|
2007-11-09 04:10:19 +00:00
|
|
|
{
|
|
|
|
Sprite *sprite = current_sprite;
|
|
|
|
Layer *layer_copy;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if (!sprite || !sprite->layer)
|
|
|
|
return NULL;
|
|
|
|
|
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
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
layer_copy = layer_new_copy(sprite, sprite->layer);
|
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);
|
|
|
|
|
2007-11-09 04:10:19 +00:00
|
|
|
console_printf("Not enough memory");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%s %s", layer_copy->name, _("Copy"));
|
|
|
|
layer_set_name(layer_copy, buf);
|
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
/* add the new layer in the sprite */
|
|
|
|
if (undo_is_enabled(sprite->undo))
|
2008-03-22 18:43:56 +00:00
|
|
|
undo_add_layer(sprite->undo, sprite->layer->parent_layer, layer_copy);
|
2007-11-09 04:10:19 +00:00
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
layer_add_layer(sprite->layer->parent_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);
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
layer_move_layer(sprite->layer->parent_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
|
|
|
|
|
|
|
Command cmd_duplicate_layer = {
|
|
|
|
CMD_DUPLICATE_LAYER,
|
|
|
|
cmd_duplicate_layer_enabled,
|
|
|
|
NULL,
|
|
|
|
cmd_duplicate_layer_execute,
|
|
|
|
NULL
|
|
|
|
};
|