From 17dee030f52397a22c818d8cf7183b0fddd3a57c Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 11 Oct 2008 15:59:13 +0000 Subject: [PATCH] Added undo support when changing frame duration. Replaced ClearMask with Undoable::clear_mask. --- ChangeLog | 14 ++++++ makefile.vc | 3 +- src/commands/cmd_frame_properties.cpp | 25 +++++----- src/dialogs/filesel.cpp | 11 +++-- src/raster/sprite.cpp | 2 +- src/raster/undoable.cpp | 24 +++++++--- src/raster/undoable.h | 3 +- src/util/clipbrd.cpp | 13 ++++-- src/util/misc.cpp | 67 --------------------------- src/util/misc.h | 1 - 10 files changed, 64 insertions(+), 99 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4c3d0f96..126295fdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-10-11 David A. Capello + + * 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 + + * src/util/misc.cpp (ClearMask): Removed. + + * src/util/clipbrd.cpp (cut_to_clipboard): Use Undoable::clear_mask now. + 2008-10-09 David A. Capello * src/raster/mask.cpp (shrink_mask): Fixed a bug where image_crop diff --git a/makefile.vc b/makefile.vc index c51624142..5481862b5 100644 --- a/makefile.vc +++ b/makefile.vc @@ -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 diff --git a/src/commands/cmd_frame_properties.cpp b/src/commands/cmd_frame_properties.cpp index 19c3e3cd8..a972fb671 100644 --- a/src/commands/cmd_frame_properties.cpp +++ b/src/commands/cmd_frame_properties.cpp @@ -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" - "<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; frframes; ++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; cfrlens[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); diff --git a/src/raster/undoable.h b/src/raster/undoable.h index 36345b8a5..2f0581d6d 100644 --- a/src/raster/undoable.h +++ b/src/raster/undoable.h @@ -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); diff --git a/src/util/clipbrd.cpp b/src/util/clipbrd.cpp index 00bade60f..6eff3a352 100644 --- a/src/util/clipbrd.cpp +++ b/src/util/clipbrd.cpp @@ -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); } } diff --git a/src/util/misc.cpp b/src/util/misc.cpp index cc7842a87..7ba06326a 100644 --- a/src/util/misc.cpp +++ b/src/util/misc.cpp @@ -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; vmask->h; v++) { - d = div(0, 8); - address = ((ase_uint8 **)sprite->mask->bitmap->line)[v]+d.quot; - - for (u=0; umask->w; u++) { - if ((*address & (1<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) diff --git a/src/util/misc.h b/src/util/misc.h index 89be36e85..d049c429d 100644 --- a/src/util/misc.h +++ b/src/util/misc.h @@ -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);