Added undo support when changing frame duration.

Replaced ClearMask with Undoable::clear_mask.
This commit is contained in:
David Capello 2008-10-11 15:59:13 +00:00
parent a1d9d2cada
commit 17dee030f5
10 changed files with 64 additions and 99 deletions

View File

@ -1,3 +1,17 @@
2008-10-11 David A. Capello <davidcapello@gmail.com>
* src/raster/undoable.cpp (Undoable::set_constant_frame_rate): Added.
(Undoable::set_frame_length): Renamed to set_frame_duration.
* src/commands/cmd_frame_properties.cpp (dialogs_frame_length):
Added undo.
2008-10-10 David A. Capello <davidcapello@gmail.com>
* src/util/misc.cpp (ClearMask): Removed.
* src/util/clipbrd.cpp (cut_to_clipboard): Use Undoable::clear_mask now.
2008-10-09 David A. Capello <davidcapello@gmail.com>
* src/raster/mask.cpp (shrink_mask): Fixed a bug where image_crop

View File

@ -31,7 +31,7 @@ CFLAGS = -nologo \
-I$(ZLIB_DIR) \
-DPNG_NO_MMX_CODE
LFLAGS = -NOLOGO -SUBSYSTEM:WINDOWS -MACHINE:X86 -RELEASE
LFLAGS = -NOLOGO -SUBSYSTEM:WINDOWS -MACHINE:X86
LIBS = User32.lib Shell32.lib ComCtl32.lib ComDlg32.lib Gdi32.lib \
Msimg32.lib WinMM.lib AdvAPI32.lib Ole32.lib ShLwApi.lib Vfw32.Lib
@ -42,6 +42,7 @@ ifdef DEBUGMODE
LIBS += Alld.lib
else
CFLAGS += -MD
LFLAGS += -RELEASE
LIBS += Alleg.lib
endif

View File

@ -21,13 +21,10 @@
#include "jinete/jinete.h"
#include "commands/commands.h"
/* #include "core/app.h" */
#include "modules/gui.h"
#include "modules/sprites.h"
/* #include "raster/cel.h" */
/* #include "raster/layer.h" */
#include "raster/sprite.h"
/* #include "raster/undo.h" */
#include "raster/undoable.h"
void dialogs_frame_length(int sprite_frame);
@ -45,6 +42,7 @@ static void cmd_frame_properties_execute(const char *argument)
void dialogs_frame_length(int sprite_frame)
{
JWidget window, frame, frlen, ok;
Sprite* sprite = current_sprite;
char buf[64];
window = load_widget("frlen.jid", "frame_duration");
@ -65,7 +63,7 @@ void dialogs_frame_length(int sprite_frame)
sprintf(buf, "%d", sprite_frame+1);
jwidget_set_text(frame, buf);
sprintf(buf, "%d", sprite_get_frlen(current_sprite, current_sprite->frame));
sprintf(buf, "%d", sprite_get_frlen(sprite, sprite->frame));
jwidget_set_text(frlen, buf);
jwindow_open_fg(window);
@ -74,13 +72,18 @@ void dialogs_frame_length(int sprite_frame)
if (sprite_frame < 0) {
if (jalert("Warning"
"<<Do you want change the frame-rate of all frames?"
"<<(this operation can\'t be undoed)"
"||&Yes||&No") == 1)
sprite_set_speed(current_sprite, num);
"<<Do you want to change the duration of all frames?"
"||&Yes||&No") == 1) {
Undoable undoable(sprite, "Constant Frame-Rate");
undoable.set_constant_frame_rate(num);
undoable.commit();
}
}
else {
Undoable undoable(sprite, "Frame Duration");
undoable.set_frame_duration(sprite_frame, num);
undoable.commit();
}
else
sprite_set_frlen(current_sprite, sprite_frame, num);
}
jwidget_free(window);
}

View File

@ -62,11 +62,12 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg);
static bool location_msg_proc(JWidget widget, JMessage msg);
static bool filetype_msg_proc(JWidget widget, JMessage msg);
/* Shows the dialog to select a file in ASE.
Mainly it uses:
* the 'core/file_system' routines.
* the 'widgets/fileview' widget.
/**
* Shows the dialog to select a file in ASE.
*
* Mainly it uses:
* - the 'core/file_system' routines.
* - the 'widgets/fileview' widget.
*/
char *ase_file_selector(const char *message,
const char *init_path,

View File

@ -483,7 +483,7 @@ int sprite_get_frlen(Sprite* sprite, int frame)
}
/**
* Sets a constant frame-rate
* Sets a constant frame-rate.
*/
void sprite_set_speed(Sprite* sprite, int msecs)
{

View File

@ -399,7 +399,7 @@ void Undoable::set_cel_frame_position(Cel* cel, int frame)
cel->frame = frame;
}
void Undoable::set_frame_length(int frame, int msecs)
void Undoable::set_frame_duration(int frame, int msecs)
{
if (is_enabled())
undo_set_frlen(sprite->undo, sprite, frame);
@ -407,6 +407,16 @@ void Undoable::set_frame_length(int frame, int msecs)
sprite_set_frlen(sprite, frame, msecs);
}
void Undoable::set_constant_frame_rate(int msecs)
{
if (is_enabled()) {
for (int fr=0; fr<sprite->frames; ++fr)
undo_set_frlen(sprite->undo, sprite, fr);
}
sprite_set_speed(sprite, msecs);
}
void Undoable::move_frame_before(int frame, int before_frame)
{
if (frame != before_frame &&
@ -423,18 +433,18 @@ void Undoable::move_frame_before(int frame, int before_frame)
frlen_aux = sprite->frlens[frame];
for (int c=frame; c<before_frame-1; c++)
set_frame_length(c, sprite->frlens[c+1]);
set_frame_duration(c, sprite->frlens[c+1]);
set_frame_length(before_frame-1, frlen_aux);
set_frame_duration(before_frame-1, frlen_aux);
}
// moving the frame to the past
else if (before_frame < frame) {
frlen_aux = sprite->frlens[frame];
for (int c=frame; c>before_frame; c--)
set_frame_length(c, sprite->frlens[c-1]);
set_frame_duration(c, sprite->frlens[c-1]);
set_frame_length(before_frame, frlen_aux);
set_frame_duration(before_frame, frlen_aux);
}
// change the cels of position...
@ -507,7 +517,7 @@ Image* Undoable::get_cel_image(Cel* cel)
return NULL;
}
// clears the mask region in the current sprite with the BG color
// clears the mask region in the current sprite with the specified background color
void Undoable::clear_mask(int bgcolor)
{
Cel* cel = get_current_cel();
@ -529,7 +539,7 @@ void Undoable::clear_mask(int bgcolor)
// clear all
image_clear(image, bgcolor);
}
// if the layer is transparent we can remove the cel (and it's
// if the layer is transparent we can remove the cel (and its
// associated image)
else {
remove_cel(sprite->layer, cel);

View File

@ -63,7 +63,8 @@ public:
void remove_frame(int frame);
void remove_frame_of_layer(Layer* layer, int frame);
void copy_previous_frame(Layer* layer, int frame);
void set_frame_length(int frame, int msecs);
void set_frame_duration(int frame, int msecs);
void set_constant_frame_rate(int msecs);
void move_frame_before(int frame, int before_frame);
void move_frame_before_layer(Layer* layer, int frame, int before_frame);

View File

@ -38,6 +38,7 @@
#include "raster/rotate.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "raster/undoable.h"
#include "raster/undo.h"
#include "util/clipbrd.h"
#include "util/misc.h"
@ -138,11 +139,13 @@ void cut_to_clipboard()
if (!low_copy())
console_printf("Can't copying an image portion from the current layer\n");
else {
if (undo_is_enabled(current_sprite->undo))
undo_set_label(current_sprite->undo, "Cut");
ClearMask();
update_screen_for_sprite(current_sprite);
Sprite* sprite = current_sprite;
{
Undoable undoable(sprite, "Cut");
undoable.clear_mask(app_get_color_to_clear_layer(sprite->layer));
undoable.commit();
}
update_screen_for_sprite(sprite);
}
}

View File

@ -115,73 +115,6 @@ void LoadPalette(const char *filename)
}
}
/* clears the mask region in the current sprite with the BG color */
void ClearMask()
{
Sprite *sprite = current_sprite;
int x, y, u, v, putx, puty;
ase_uint8 *address;
Image *image;
div_t d;
if (sprite != NULL) {
image = GetImage2(sprite, &x, &y, NULL);
if (image) {
int bgcolor = app_get_color_to_clear_layer(sprite->layer);
/* if the mask is empty then we have to clear the entire image
in the cel */
if (mask_is_empty(sprite->mask)) {
/* if the layer is the background then we clear the image */
if (layer_is_background(sprite->layer)) {
if (undo_is_enabled(sprite->undo))
undo_image(sprite->undo, image, 0, 0, image->w, image->h);
/* clear all */
image_clear(image, bgcolor);
}
/* if the layer is transparent we can remove the cel (and it's
associated image) */
else {
assert(layer_get_cel(sprite->layer, sprite->frame) != NULL);
RemoveCel(sprite->layer, layer_get_cel(sprite->layer,
sprite->frame));
}
}
else {
int x1 = MAX(0, sprite->mask->x);
int y1 = MAX(0, sprite->mask->y);
int x2 = MIN(image->w-1, sprite->mask->x+sprite->mask->w-1);
int y2 = MIN(image->h-1, sprite->mask->y+sprite->mask->h-1);
/* do nothing */
if (x1 > x2 || y1 > y2)
return;
if (undo_is_enabled(sprite->undo))
undo_image(sprite->undo, image, x1, y1, x2-x1+1, y2-y1+1);
/* clear the masked zones */
for (v=0; v<sprite->mask->h; v++) {
d = div(0, 8);
address = ((ase_uint8 **)sprite->mask->bitmap->line)[v]+d.quot;
for (u=0; u<sprite->mask->w; u++) {
if ((*address & (1<<d.rem))) {
putx = u+sprite->mask->x-x;
puty = v+sprite->mask->y-y;
image_putpixel(image, putx, puty, bgcolor);
}
_image_bitmap_next_bit(d, address);
}
}
}
}
}
}
/* returns a new layer created from the current mask in the current
sprite, the layer isn't added to the sprite */
Layer *NewLayerFromMask(Sprite *src_sprite, Sprite *dst_sprite)

View File

@ -33,7 +33,6 @@ Image* GetImage2(Sprite* sprite, int *x, int *y, int *opacity);
void LoadPalette(const char* filename);
void ClearMask();
Layer* NewLayerFromMask(Sprite* src, Sprite* dst);
Image* GetLayerImage(Layer* layer, int *x, int *y, int frame);