From ffd0f178798083d57922507f7530c3aafec95176 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 30 Sep 2010 23:55:35 -0300 Subject: [PATCH] Move all undo_*() functions as members of Undo class. --- src/commands/cmd_cel_properties.cpp | 2 +- src/commands/cmd_duplicate_layer.cpp | 12 +- src/commands/cmd_invert_mask.cpp | 2 +- src/commands/cmd_load_mask.cpp | 2 +- src/commands/cmd_mask_all.cpp | 2 +- src/commands/cmd_merge_down_layer.cpp | 18 +- src/commands/cmd_palette_editor.cpp | 10 +- src/commands/cmd_reselect_mask.cpp | 2 +- src/dialogs/maskcol.cpp | 2 +- src/dialogs/vectmap.cpp | 2 +- src/effect/effect.cpp | 8 +- src/raster/layer.cpp | 2 +- src/raster/sprite.cpp | 5 +- src/raster/undo.cpp | 263 +++++++++++++------------- src/raster/undo.h | 94 +++++---- src/tools/inks.h | 2 +- src/undoable.cpp | 84 ++++---- src/util/celmove.cpp | 42 ++-- src/util/clipboard.cpp | 4 +- src/util/misc.cpp | 8 +- src/widgets/editor/editor.cpp | 20 +- 21 files changed, 302 insertions(+), 284 deletions(-) diff --git a/src/commands/cmd_cel_properties.cpp b/src/commands/cmd_cel_properties.cpp index 28a7c10cd..784c55dc0 100644 --- a/src/commands/cmd_cel_properties.cpp +++ b/src/commands/cmd_cel_properties.cpp @@ -141,7 +141,7 @@ void CelPropertiesCommand::onExecute(Context* context) cel_writer->opacity != new_opacity) { if (sprite_writer->getUndo()->isEnabled()) { sprite_writer->getUndo()->setLabel("Cel Opacity Change"); - undo_int(sprite_writer->getUndo(), (GfxObj *)cel_writer, &cel_writer->opacity); + sprite_writer->getUndo()->undo_int(cel_writer, &cel_writer->opacity); } /* change cel opacity */ diff --git a/src/commands/cmd_duplicate_layer.cpp b/src/commands/cmd_duplicate_layer.cpp index 6b655db9f..bcac99ce6 100644 --- a/src/commands/cmd_duplicate_layer.cpp +++ b/src/commands/cmd_duplicate_layer.cpp @@ -70,13 +70,13 @@ static Layer* duplicate_layer(Sprite* sprite) /* open undo */ if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Layer Duplication"); - undo_open(sprite->getUndo()); + sprite->getUndo()->undo_open(); } Layer* layer_copy = sprite->getCurrentLayer()->duplicate_for(sprite); if (!layer_copy) { if (sprite->getUndo()->isEnabled()) - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_close(); Console console; console.printf("Not enough memory"); @@ -89,14 +89,14 @@ static Layer* duplicate_layer(Sprite* sprite) /* add the new layer in the sprite */ if (sprite->getUndo()->isEnabled()) - undo_add_layer(sprite->getUndo(), sprite->getCurrentLayer()->get_parent(), layer_copy); + sprite->getUndo()->undo_add_layer(sprite->getCurrentLayer()->get_parent(), layer_copy); sprite->getCurrentLayer()->get_parent()->add_layer(layer_copy); if (sprite->getUndo()->isEnabled()) { - undo_move_layer(sprite->getUndo(), layer_copy); - undo_set_layer(sprite->getUndo(), sprite); - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_move_layer(layer_copy); + sprite->getUndo()->undo_set_layer(sprite); + sprite->getUndo()->undo_close(); } sprite->getCurrentLayer()->get_parent()->move_layer(layer_copy, sprite->getCurrentLayer()); diff --git a/src/commands/cmd_invert_mask.cpp b/src/commands/cmd_invert_mask.cpp index d0b319154..d200bb7f6 100644 --- a/src/commands/cmd_invert_mask.cpp +++ b/src/commands/cmd_invert_mask.cpp @@ -77,7 +77,7 @@ void InvertMaskCommand::onExecute(Context* context) /* undo */ if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Mask Invert"); - undo_set_mask(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_mask(sprite); } /* create a new mask */ diff --git a/src/commands/cmd_load_mask.cpp b/src/commands/cmd_load_mask.cpp index d656a44ce..b12ae7693 100644 --- a/src/commands/cmd_load_mask.cpp +++ b/src/commands/cmd_load_mask.cpp @@ -86,7 +86,7 @@ void LoadMaskCommand::onExecute(Context* context) // undo if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Mask Load"); - undo_set_mask(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_mask(sprite); } sprite->setMask(mask); diff --git a/src/commands/cmd_mask_all.cpp b/src/commands/cmd_mask_all.cpp index 7428a4cd8..9b89376ac 100644 --- a/src/commands/cmd_mask_all.cpp +++ b/src/commands/cmd_mask_all.cpp @@ -59,7 +59,7 @@ void MaskAllCommand::onExecute(Context* context) /* undo */ if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Mask All"); - undo_set_mask(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_mask(sprite); } /* change the selection */ diff --git a/src/commands/cmd_merge_down_layer.cpp b/src/commands/cmd_merge_down_layer.cpp index af80e980a..877f294c4 100644 --- a/src/commands/cmd_merge_down_layer.cpp +++ b/src/commands/cmd_merge_down_layer.cpp @@ -82,7 +82,7 @@ void MergeDownLayerCommand::onExecute(Context* context) if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Merge Down Layer"); - undo_open(sprite->getUndo()); + sprite->getUndo()->undo_open(); } for (frpos=0; frposgetTotalFrames(); ++frpos) { @@ -113,7 +113,7 @@ void MergeDownLayerCommand::onExecute(Context* context) /* adding it in the stock of images */ index = sprite->getStock()->addImage(dst_image); if (sprite->getUndo()->isEnabled()) - undo_add_image(sprite->getUndo(), sprite->getStock(), index); + sprite->getUndo()->undo_add_image(sprite->getStock(), index); /* creating a copy of the cell */ dst_cel = cel_new(frpos, index); @@ -121,7 +121,7 @@ void MergeDownLayerCommand::onExecute(Context* context) cel_set_opacity(dst_cel, src_cel->opacity); if (sprite->getUndo()->isEnabled()) - undo_add_cel(sprite->getUndo(), dst_layer, dst_cel); + sprite->getUndo()->undo_add_cel(dst_layer, dst_cel); static_cast(dst_layer)->addCel(dst_cel); } @@ -160,14 +160,14 @@ void MergeDownLayerCommand::onExecute(Context* context) static_cast(src_layer)->get_blend_mode()); if (sprite->getUndo()->isEnabled()) { - undo_int(sprite->getUndo(), (GfxObj *)dst_cel, &dst_cel->x); - undo_int(sprite->getUndo(), (GfxObj *)dst_cel, &dst_cel->y); + sprite->getUndo()->undo_int(dst_cel, &dst_cel->x); + sprite->getUndo()->undo_int(dst_cel, &dst_cel->y); } cel_set_position(dst_cel, x1, y1); if (sprite->getUndo()->isEnabled()) - undo_replace_image(sprite->getUndo(), sprite->getStock(), dst_cel->image); + sprite->getUndo()->undo_replace_image(sprite->getStock(), dst_cel->image); sprite->getStock()->replaceImage(dst_cel->image, new_image); image_free(dst_image); @@ -176,9 +176,9 @@ void MergeDownLayerCommand::onExecute(Context* context) } if (sprite->getUndo()->isEnabled()) { - undo_set_layer(sprite->getUndo(), sprite); - undo_remove_layer(sprite->getUndo(), src_layer); - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_set_layer(sprite); + sprite->getUndo()->undo_remove_layer(src_layer); + sprite->getUndo()->undo_close(); } sprite->setCurrentLayer(dst_layer); diff --git a/src/commands/cmd_palette_editor.cpp b/src/commands/cmd_palette_editor.cpp index 05b3a416f..7e04b5725 100644 --- a/src/commands/cmd_palette_editor.cpp +++ b/src/commands/cmd_palette_editor.cpp @@ -511,10 +511,10 @@ static void sort_command(JWidget widget) if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Sort Palette"); - undo_open(sprite->getUndo()); + sprite->getUndo()->undo_open(); // Remove the current palette in the current frame - undo_remove_palette(sprite->getUndo(), sprite, frame_palette); + sprite->getUndo()->undo_remove_palette(sprite, frame_palette); } // Delete the current palette @@ -526,11 +526,11 @@ static void sort_command(JWidget widget) if (sprite->getUndo()->isEnabled()) { // Add undo information about the new added palette - undo_add_palette(sprite->getUndo(), sprite, sprite->getPalette(frame_begin)); + sprite->getUndo()->undo_add_palette(sprite, sprite->getPalette(frame_begin)); // Add undo information about image remapping - undo_remap_palette(sprite->getUndo(), sprite, frame_begin, frame_end-1, mapping); - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_remap_palette(sprite, frame_begin, frame_end-1, mapping); + sprite->getUndo()->undo_close(); } // Remap images (to the new palette indexes) diff --git a/src/commands/cmd_reselect_mask.cpp b/src/commands/cmd_reselect_mask.cpp index 9a3edfd69..15bf35e19 100644 --- a/src/commands/cmd_reselect_mask.cpp +++ b/src/commands/cmd_reselect_mask.cpp @@ -65,7 +65,7 @@ void ReselectMaskCommand::onExecute(Context* context) /* undo */ if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Mask Reselection"); - undo_set_mask(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_mask(sprite); } /* set the mask */ diff --git a/src/dialogs/maskcol.cpp b/src/dialogs/maskcol.cpp index 85d1d7ec2..c2248563b 100644 --- a/src/dialogs/maskcol.cpp +++ b/src/dialogs/maskcol.cpp @@ -135,7 +135,7 @@ void dialogs_mask_color(Sprite* sprite) /* undo */ if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Mask by Color"); - undo_set_mask(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_mask(sprite); } /* change the mask */ diff --git a/src/dialogs/vectmap.cpp b/src/dialogs/vectmap.cpp index a9ae52334..8b8b2220e 100644 --- a/src/dialogs/vectmap.cpp +++ b/src/dialogs/vectmap.cpp @@ -143,7 +143,7 @@ void dialogs_vector_map(Sprite* sprite) /* undo stuff */ if (sprite->getUndo()->isEnabled()) - undo_image(sprite->getUndo(), image, 0, 0, image->w, image->h); + sprite->getUndo()->undo_image(image, 0, 0, image->w, image->h); dmax = std::sqrt(static_cast(image->w/2*image->w/2 + image->h/2*image->h/2)); for (y=0; yh; y++) { diff --git a/src/effect/effect.cpp b/src/effect/effect.cpp index 8aee83110..cedfa80a0 100644 --- a/src/effect/effect.cpp +++ b/src/effect/effect.cpp @@ -251,8 +251,8 @@ void effect_apply(Effect* effect) // Undo stuff if (effect->sprite->getUndo()->isEnabled()) { effect->sprite->getUndo()->setLabel(effect->effect_data->label); - undo_image(effect->sprite->getUndo(), effect->src, - effect->x, effect->y, effect->w, effect->h); + effect->sprite->getUndo() + ->undo_image(effect->src, effect->x, effect->y, effect->w, effect->h); } // Copy "dst" to "src" @@ -309,7 +309,7 @@ void effect_apply_to_target(Effect *effect) /* open undo group of operations */ if (nimages > 1) { if (effect->sprite->getUndo()->isEnabled()) - undo_open(effect->sprite->getUndo()); + effect->sprite->getUndo()->undo_open(); } effect->progress_base = 0.0f; @@ -330,7 +330,7 @@ void effect_apply_to_target(Effect *effect) /* close undo group of operations */ if (nimages > 1) { if (effect->sprite->getUndo()->isEnabled()) - undo_close(effect->sprite->getUndo()); + effect->sprite->getUndo()->undo_close(); } /* free all ImageRefs */ diff --git a/src/raster/layer.cpp b/src/raster/layer.cpp index 32c81af9c..c2e99246e 100644 --- a/src/raster/layer.cpp +++ b/src/raster/layer.cpp @@ -134,7 +134,7 @@ LayerImage::LayerImage(const LayerImage* src_layer, Sprite* dst_sprite) cel_copy->image = dst_sprite->getStock()->addImage(image_copy); if (dst_sprite->getUndo()->isEnabled()) - undo_add_image(dst_sprite->getUndo(), dst_sprite->getStock(), cel_copy->image); + dst_sprite->getUndo()->undo_add_image(dst_sprite->getStock(), cel_copy->image); addCel(cel_copy); } diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index 1352331fc..8eefc55cf 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -85,8 +85,7 @@ public: } bool isModified() const { - return (m_undo->diff_count == - m_undo->diff_saved) ? false: true; + return !m_undo->isSavedState(); } bool isAssociatedToFile() const { @@ -94,7 +93,7 @@ public: } void markAsSaved() { - m_undo->diff_saved = m_undo->diff_count; + m_undo->markSavedState(); m_associated_to_file = true; } diff --git a/src/raster/undo.cpp b/src/raster/undo.cpp index c5bddb86c..14fc2f60e 100644 --- a/src/raster/undo.cpp +++ b/src/raster/undo.cpp @@ -149,11 +149,8 @@ struct UndoAction void (*invert)(UndoStream* stream, UndoChunk* chunk, int state); }; -static void run_undo(Undo* undo, int state); -static void discard_undo_tail(Undo* undo); static int count_undo_groups(UndoStream* undo_stream); static bool out_of_group(UndoStream* undo_stream); -static void update_undo(Undo* undo); /* Undo actions */ @@ -300,71 +297,76 @@ static void undo_stream_push_chunk(UndoStream* stream, UndoChunk* chunk); Undo::Undo(Sprite* sprite) : GfxObj(GFXOBJ_UNDO) { - this->sprite = sprite; - this->undo_stream = new UndoStream(this); // TODO try/catch - this->redo_stream = new UndoStream(this); - this->diff_count = 0; - this->diff_saved = 0; - this->enabled = true; - this->label = NULL; + m_sprite = sprite; + m_undoStream = new UndoStream(this); // TODO try/catch + m_redoStream = new UndoStream(this); + m_diffCount = 0; + m_diffSaved = 0; + m_enabled = true; + m_label = NULL; } Undo::~Undo() { - delete this->undo_stream; - delete this->redo_stream; + delete m_undoStream; + delete m_redoStream; } bool Undo::isEnabled() const { - return this->enabled ? true: false; + return m_enabled ? true: false; } void Undo::setEnabled(bool state) { - this->enabled = state; + m_enabled = state; } bool Undo::canUndo() const { - return !this->undo_stream->chunks.empty(); + return !m_undoStream->chunks.empty(); } bool Undo::canRedo() const { - return !this->redo_stream->chunks.empty(); + return !m_redoStream->chunks.empty(); } void Undo::doUndo() { - run_undo(this, DO_UNDO); + runUndo(DO_UNDO); } void Undo::doRedo() { - run_undo(this, DO_REDO); + runUndo(DO_REDO); } void Undo::clearRedo() { - if (!this->redo_stream->chunks.empty()) { - delete this->redo_stream; - this->redo_stream = new UndoStream(this); + if (!m_redoStream->chunks.empty()) { + delete m_redoStream; + m_redoStream = new UndoStream(this); } } +const char* Undo::getLabel() +{ + return m_label; +} + void Undo::setLabel(const char* label) { - this->label = label; + m_label = label; } const char* Undo::getNextUndoLabel() const { UndoChunk* chunk; - ASSERT(this->canUndo()); + ASSERT(canUndo()); - chunk = *this->undo_stream->chunks.begin(); + chunk = *m_undoStream->chunks.begin(); return chunk->label; } @@ -372,21 +374,28 @@ const char* Undo::getNextRedoLabel() const { UndoChunk* chunk; - ASSERT(this->canRedo()); + ASSERT(canRedo()); - chunk = *this->redo_stream->chunks.begin(); + chunk = *m_redoStream->chunks.begin(); return chunk->label; } -////////////////////////////////////////////////////////////////////// -// General undo routines - -static void run_undo(Undo* undo, int state) +bool Undo::isSavedState() const { - UndoStream* undo_stream = ((state == DO_UNDO)? undo->undo_stream: - undo->redo_stream); - UndoStream* redo_stream = ((state == DO_REDO)? undo->undo_stream: - undo->redo_stream); + return (m_diffCount == m_diffSaved); +} + +void Undo::markSavedState() +{ + m_diffSaved = m_diffCount; +} + +void Undo::runUndo(int state) +{ + UndoStream* undo_stream = ((state == DO_UNDO)? m_undoStream: + m_redoStream); + UndoStream* redo_stream = ((state == DO_REDO)? m_undoStream: + m_redoStream); UndoChunk* chunk; int level = 0; @@ -395,7 +404,7 @@ static void run_undo(Undo* undo, int state) if (!chunk) break; - undo->setLabel(chunk->label); + setLabel(chunk->label); (undo_actions[chunk->type].invert)(redo_stream, chunk, state); if (chunk->type == UNDO_TYPE_OPEN) @@ -406,15 +415,15 @@ static void run_undo(Undo* undo, int state) undo_chunk_free(chunk); if (state == DO_UNDO) - undo->diff_count--; + m_diffCount--; else if (state == DO_REDO) - undo->diff_count++; + m_diffCount++; } while (level); } -static void discard_undo_tail(Undo* undo) +void Undo::discardTail() { - UndoStream* undo_stream = undo->undo_stream; + UndoStream* undo_stream = m_undoStream; UndoChunk* chunk; int level = 0; @@ -482,23 +491,23 @@ static bool out_of_group(UndoStream* undo_stream) return level == 0; } -/* called every time a new undo is added */ -static void update_undo(Undo* undo) +// Called every time a new undo is added. +void Undo::updateUndo() { int undo_size_limit = get_config_int("Options", "UndoSizeLimit", 8)*1024*1024; - /* more diff */ - undo->diff_count++; + // More differences. + m_diffCount++; - /* reset the "redo" stream */ - undo->clearRedo(); + // Reset the "redo" stream. + clearRedo(); - if (out_of_group(undo->undo_stream)) { - int groups = count_undo_groups(undo->undo_stream); + if (out_of_group(m_undoStream)) { + int groups = count_undo_groups(m_undoStream); - /* "undo" is too big? */ - while (groups > 1 && undo->undo_stream->size > undo_size_limit) { - discard_undo_tail(undo); + // "undo" is too big? + while (groups > 1 && m_undoStream->size > undo_size_limit) { + discardTail(); groups--; } } @@ -512,10 +521,10 @@ static void update_undo(Undo* undo) ***********************************************************************/ -void undo_open(Undo* undo) +void Undo::undo_open() { - chunk_open_new(undo->undo_stream); - update_undo(undo); + chunk_open_new(m_undoStream); + updateUndo(); } static void chunk_open_new(UndoStream* stream) @@ -538,10 +547,10 @@ static void chunk_open_invert(UndoStream* stream, UndoChunk* chunk, int state) ***********************************************************************/ -void undo_close(Undo* undo) +void Undo::undo_close() { - chunk_close_new(undo->undo_stream); - update_undo(undo); + chunk_close_new(m_undoStream); + updateUndo(); } static void chunk_close_new(UndoStream* stream) @@ -576,10 +585,10 @@ struct UndoChunkData ase_uint8 data[0]; }; -void undo_data(Undo* undo, GfxObj *gfxobj, void *data, int size) +void Undo::undo_data(GfxObj *gfxobj, void *data, int size) { - chunk_data_new(undo->undo_stream, gfxobj, data, size); - update_undo(undo); + chunk_data_new(m_undoStream, gfxobj, data, size); + updateUndo(); } static void chunk_data_new(UndoStream* stream, GfxObj *gfxobj, void *data, int size) @@ -644,10 +653,10 @@ struct UndoChunkImage ase_uint8 data[0]; }; -void undo_image(Undo* undo, Image* image, int x, int y, int w, int h) +void Undo::undo_image(Image* image, int x, int y, int w, int h) { - chunk_image_new(undo->undo_stream, image, x, y, w, h); - update_undo(undo); + chunk_image_new(m_undoStream, image, x, y, w, h); + updateUndo(); } static void chunk_image_new(UndoStream* stream, Image* image, int x, int y, int w, int h) @@ -731,10 +740,10 @@ struct UndoChunkFlip ase_uint8 horz; }; -void undo_flip(Undo* undo, Image* image, int x1, int y1, int x2, int y2, bool horz) +void Undo::undo_flip(Image* image, int x1, int y1, int x2, int y2, bool horz) { - chunk_flip_new(undo->undo_stream, image, x1, y1, x2, y2, horz); - update_undo(undo); + chunk_flip_new(m_undoStream, image, x1, y1, x2, y2, horz); + updateUndo(); } static void chunk_flip_new(UndoStream* stream, Image* image, int x1, int y1, int x2, int y2, bool horz) @@ -796,10 +805,10 @@ struct UndoChunkDirty ase_uint8 data[0]; }; -void undo_dirty(Undo* undo, Dirty *dirty) +void Undo::undo_dirty(Dirty *dirty) { - chunk_dirty_new(undo->undo_stream, dirty); - update_undo(undo); + chunk_dirty_new(m_undoStream, dirty); + updateUndo(); } static void chunk_dirty_new(UndoStream* stream, Dirty *dirty) @@ -839,10 +848,10 @@ struct UndoChunkAddImage ase_uint32 image_index; }; -void undo_add_image(Undo* undo, Stock *stock, int image_index) +void Undo::undo_add_image(Stock *stock, int image_index) { - chunk_add_image_new(undo->undo_stream, stock, image_index); - update_undo(undo); + chunk_add_image_new(m_undoStream, stock, image_index); + updateUndo(); } static void chunk_add_image_new(UndoStream* stream, Stock *stock, int image_index) @@ -890,10 +899,10 @@ struct UndoChunkRemoveImage ase_uint8 data[0]; }; -void undo_remove_image(Undo* undo, Stock *stock, int image_index) +void Undo::undo_remove_image(Stock *stock, int image_index) { - chunk_remove_image_new(undo->undo_stream, stock, image_index); - update_undo(undo); + chunk_remove_image_new(m_undoStream, stock, image_index); + updateUndo(); } static void chunk_remove_image_new(UndoStream* stream, Stock *stock, int image_index) @@ -944,10 +953,10 @@ struct UndoChunkReplaceImage ase_uint8 data[0]; }; -void undo_replace_image(Undo* undo, Stock *stock, int image_index) +void Undo::undo_replace_image(Stock *stock, int image_index) { - chunk_replace_image_new(undo->undo_stream, stock, image_index); - update_undo(undo); + chunk_replace_image_new(m_undoStream, stock, image_index); + updateUndo(); } static void chunk_replace_image_new(UndoStream* stream, Stock *stock, int image_index) @@ -1002,10 +1011,10 @@ struct UndoChunkAddCel ase_uint32 cel_id; }; -void undo_add_cel(Undo* undo, Layer* layer, Cel* cel) +void Undo::undo_add_cel(Layer* layer, Cel* cel) { - chunk_add_cel_new(undo->undo_stream, layer, cel); - update_undo(undo); + chunk_add_cel_new(m_undoStream, layer, cel); + updateUndo(); } static void chunk_add_cel_new(UndoStream* stream, Layer* layer, Cel* cel) @@ -1048,10 +1057,10 @@ struct UndoChunkRemoveCel ase_uint8 data[0]; }; -void undo_remove_cel(Undo* undo, Layer* layer, Cel* cel) +void Undo::undo_remove_cel(Layer* layer, Cel* cel) { - chunk_remove_cel_new(undo->undo_stream, layer, cel); - update_undo(undo); + chunk_remove_cel_new(m_undoStream, layer, cel); + updateUndo(); } static void chunk_remove_cel_new(UndoStream* stream, Layer* layer, Cel* cel) @@ -1098,10 +1107,10 @@ struct UndoChunkSetLayerName ase_uint8 name_text[0]; }; -void undo_set_layer_name(Undo* undo, Layer* layer) +void Undo::undo_set_layer_name(Layer* layer) { - chunk_set_layer_name_new(undo->undo_stream, layer); - update_undo(undo); + chunk_set_layer_name_new(m_undoStream, layer); + updateUndo(); } static void chunk_set_layer_name_new(UndoStream* stream, Layer *layer) @@ -1153,10 +1162,10 @@ struct UndoChunkAddLayer ase_uint32 layer_id; }; -void undo_add_layer(Undo* undo, Layer* folder, Layer* layer) +void Undo::undo_add_layer(Layer* folder, Layer* layer) { - chunk_add_layer_new(undo->undo_stream, folder, layer); - update_undo(undo); + chunk_add_layer_new(m_undoStream, folder, layer); + updateUndo(); } static void chunk_add_layer_new(UndoStream* stream, Layer* folder, Layer* layer) @@ -1201,10 +1210,10 @@ struct UndoChunkRemoveLayer ase_uint8 data[0]; }; -void undo_remove_layer(Undo* undo, Layer* layer) +void Undo::undo_remove_layer(Layer* layer) { - chunk_remove_layer_new(undo->undo_stream, layer); - update_undo(undo); + chunk_remove_layer_new(m_undoStream, layer); + updateUndo(); } static void chunk_remove_layer_new(UndoStream* stream, Layer* layer) @@ -1256,10 +1265,10 @@ struct UndoChunkMoveLayer ase_uint32 after_id; }; -void undo_move_layer(Undo* undo, Layer* layer) +void Undo::undo_move_layer(Layer* layer) { - chunk_move_layer_new(undo->undo_stream, layer); - update_undo(undo); + chunk_move_layer_new(m_undoStream, layer); + updateUndo(); } static void chunk_move_layer_new(UndoStream* stream, Layer* layer) @@ -1305,10 +1314,10 @@ struct UndoChunkSetLayer ase_uint32 layer_id; }; -void undo_set_layer(Undo* undo, Sprite *sprite) +void Undo::undo_set_layer(Sprite *sprite) { - chunk_set_layer_new(undo->undo_stream, sprite); - update_undo(undo); + chunk_set_layer_new(m_undoStream, sprite); + updateUndo(); } static void chunk_set_layer_new(UndoStream* stream, Sprite *sprite) @@ -1351,10 +1360,10 @@ struct UndoChunkAddPalette ase_uint32 palette_id; }; -void undo_add_palette(Undo* undo, Sprite *sprite, Palette* palette) +void Undo::undo_add_palette(Sprite *sprite, Palette* palette) { - chunk_add_palette_new(undo->undo_stream, sprite, palette); - update_undo(undo); + chunk_add_palette_new(m_undoStream, sprite, palette); + updateUndo(); } static void chunk_add_palette_new(UndoStream* stream, Sprite *sprite, Palette* palette) @@ -1396,10 +1405,10 @@ struct UndoChunkRemovePalette ase_uint8 data[0]; }; -void undo_remove_palette(Undo* undo, Sprite *sprite, Palette* palette) +void Undo::undo_remove_palette(Sprite *sprite, Palette* palette) { - chunk_remove_palette_new(undo->undo_stream, sprite, palette); - update_undo(undo); + chunk_remove_palette_new(m_undoStream, sprite, palette); + updateUndo(); } static void chunk_remove_palette_new(UndoStream* stream, Sprite *sprite, Palette* palette) @@ -1447,10 +1456,10 @@ struct UndoChunkRemapPalette ase_uint8 mapping[256]; }; -void undo_remap_palette(Undo* undo, Sprite* sprite, int frame_from, int frame_to, const std::vector& mapping) +void Undo::undo_remap_palette(Sprite* sprite, int frame_from, int frame_to, const std::vector& mapping) { - chunk_remap_palette_new(undo->undo_stream, sprite, frame_from, frame_to, mapping); - update_undo(undo); + chunk_remap_palette_new(m_undoStream, sprite, frame_from, frame_to, mapping); + updateUndo(); } static void chunk_remap_palette_new(UndoStream* stream, Sprite *sprite, int frame_from, int frame_to, const std::vector& mapping) @@ -1503,10 +1512,10 @@ struct UndoChunkSetMask ase_uint8 data[0]; }; -void undo_set_mask(Undo* undo, Sprite *sprite) +void Undo::undo_set_mask(Sprite *sprite) { - chunk_set_mask_new(undo->undo_stream, sprite); - update_undo(undo); + chunk_set_mask_new(m_undoStream, sprite); + updateUndo(); } static void chunk_set_mask_new(UndoStream* stream, Sprite *sprite) @@ -1550,10 +1559,10 @@ struct UndoChunkSetImgType ase_uint32 imgtype; }; -void undo_set_imgtype(Undo* undo, Sprite* sprite) +void Undo::undo_set_imgtype(Sprite* sprite) { - chunk_set_imgtype_new(undo->undo_stream, sprite); - update_undo(undo); + chunk_set_imgtype_new(m_undoStream, sprite); + updateUndo(); } static void chunk_set_imgtype_new(UndoStream* stream, Sprite* sprite) @@ -1599,10 +1608,10 @@ struct UndoChunkSetSize ase_uint32 height; }; -void undo_set_size(Undo* undo, Sprite* sprite) +void Undo::undo_set_size(Sprite* sprite) { - chunk_set_size_new(undo->undo_stream, sprite); - update_undo(undo); + chunk_set_size_new(m_undoStream, sprite); + updateUndo(); } static void chunk_set_size_new(UndoStream* stream, Sprite* sprite) @@ -1643,10 +1652,10 @@ struct UndoChunkSetFrame ase_uint32 frame; }; -void undo_set_frame(Undo* undo, Sprite* sprite) +void Undo::undo_set_frame(Sprite* sprite) { - chunk_set_frame_new(undo->undo_stream, sprite); - update_undo(undo); + chunk_set_frame_new(m_undoStream, sprite); + updateUndo(); } static void chunk_set_frame_new(UndoStream* stream, Sprite* sprite) @@ -1686,10 +1695,10 @@ struct UndoChunkSetFrames ase_uint32 frames; }; -void undo_set_frames(Undo* undo, Sprite *sprite) +void Undo::undo_set_frames(Sprite *sprite) { - chunk_set_frames_new(undo->undo_stream, sprite); - update_undo(undo); + chunk_set_frames_new(m_undoStream, sprite); + updateUndo(); } static void chunk_set_frames_new(UndoStream* stream, Sprite *sprite) @@ -1731,10 +1740,10 @@ struct UndoChunkSetFrlen ase_uint32 duration; }; -void undo_set_frlen(Undo* undo, Sprite *sprite, int frame) +void Undo::undo_set_frlen(Sprite *sprite, int frame) { - chunk_set_frlen_new(undo->undo_stream, sprite, frame); - update_undo(undo); + chunk_set_frlen_new(m_undoStream, sprite, frame); + updateUndo(); } static void chunk_set_frlen_new(UndoStream* stream, Sprite *sprite, int frame) @@ -1779,8 +1788,8 @@ static UndoChunk* undo_chunk_new(UndoStream* stream, int type, int size) chunk->type = type; chunk->size = size; - chunk->label = stream->undo->label ? - stream->undo->label: + chunk->label = stream->undo->getLabel() ? + stream->undo->getLabel(): undo_actions[chunk->type].name; undo_stream_push_chunk(stream, chunk); diff --git a/src/raster/undo.h b/src/raster/undo.h index 08dc798bd..6a5bc2a84 100644 --- a/src/raster/undo.h +++ b/src/raster/undo.h @@ -45,15 +45,6 @@ public: class Undo : public GfxObj { public: - Sprite* sprite; /* related sprite */ - UndoStream *undo_stream; - UndoStream *redo_stream; - int diff_count; - int diff_saved; - unsigned enabled : 1; /* is undo enabled? */ - const char *label; /* current label to be applied to all - next undo operations */ - Undo(Sprite* sprite); virtual ~Undo(); @@ -68,43 +59,62 @@ public: void clearRedo(); + const char* getLabel(); void setLabel(const char* label); + const char* getNextUndoLabel() const; const char* getNextRedoLabel() const; + bool isSavedState() const; + void markSavedState(); + + void undo_open(); + void undo_close(); + void undo_data(GfxObj *gfxobj, void *data, int size); + void undo_image(Image *image, int x, int y, int w, int h); + void undo_flip(Image *image, int x1, int y1, int x2, int y2, bool horz); + void undo_dirty(Dirty *dirty); + void undo_add_image(Stock *stock, int image_index); + void undo_remove_image(Stock *stock, int image_index); + void undo_replace_image(Stock *stock, int image_index); + void undo_set_layer_name(Layer *layer); + void undo_add_cel(Layer *layer, Cel *cel); + void undo_remove_cel(Layer *layer, Cel *cel); + void undo_add_layer(Layer *set, Layer *layer); + void undo_remove_layer(Layer *layer); + void undo_move_layer(Layer *layer); + void undo_set_layer(Sprite* sprite); + void undo_add_palette(Sprite* sprite, Palette* palette); + void undo_remove_palette(Sprite* sprite, Palette* palette); + void undo_remap_palette(Sprite* sprite, int frame_from, int frame_to, + const std::vector& mapping); + void undo_set_mask(Sprite* sprite); + void undo_set_imgtype(Sprite* sprite); + void undo_set_size(Sprite* sprite); + void undo_set_frame(Sprite* sprite); + void undo_set_frames(Sprite* sprite); + void undo_set_frlen(Sprite* sprite, int frame); + + void undo_int(GfxObj* gfxobj, int* value_address) { + undo_data(gfxobj, (void*)(value_address), sizeof(int)); + } + + void undo_double(GfxObj* gfxobj, double* value_address) { + undo_data(gfxobj, (void*)(value_address), sizeof(double)); + } + +private: + void runUndo(int state); + void discardTail(); + void updateUndo(); + + Sprite* m_sprite; // Related sprite + UndoStream* m_undoStream; + UndoStream* m_redoStream; + int m_diffCount; + int m_diffSaved; + bool m_enabled; // Is undo enabled? + const char* m_label; // Current label to be applied to all next undo operations. }; -void undo_open(Undo* undo); -void undo_close(Undo* undo); -void undo_data(Undo* undo, GfxObj *gfxobj, void *data, int size); -void undo_image(Undo* undo, Image *image, int x, int y, int w, int h); -void undo_flip(Undo* undo, Image *image, int x1, int y1, int x2, int y2, bool horz); -void undo_dirty(Undo* undo, Dirty *dirty); -void undo_add_image(Undo* undo, Stock *stock, int image_index); -void undo_remove_image(Undo* undo, Stock *stock, int image_index); -void undo_replace_image(Undo* undo, Stock *stock, int image_index); -void undo_set_layer_name(Undo* undo, Layer *layer); -void undo_add_cel(Undo* undo, Layer *layer, Cel *cel); -void undo_remove_cel(Undo* undo, Layer *layer, Cel *cel); -void undo_add_layer(Undo* undo, Layer *set, Layer *layer); -void undo_remove_layer(Undo* undo, Layer *layer); -void undo_move_layer(Undo* undo, Layer *layer); -void undo_set_layer(Undo* undo, Sprite* sprite); -void undo_add_palette(Undo* undo, Sprite* sprite, Palette* palette); -void undo_remove_palette(Undo* undo, Sprite* sprite, Palette* palette); -void undo_remap_palette(Undo* undo, Sprite* sprite, int frame_from, int frame_to, - const std::vector& mapping); -void undo_set_mask(Undo* undo, Sprite* sprite); -void undo_set_imgtype(Undo* undo, Sprite* sprite); -void undo_set_size(Undo* undo, Sprite* sprite); -void undo_set_frame(Undo* undo, Sprite* sprite); -void undo_set_frames(Undo* undo, Sprite* sprite); -void undo_set_frlen(Undo* undo, Sprite* sprite, int frame); - -#define undo_int(undo, gfxobj, value_address) \ - undo_data((undo), (gfxobj), (void *)(value_address), sizeof(int)) - -#define undo_double(undo, gfxobj, value_address) \ - undo_data((undo), (gfxobj), (void *)(value_address), sizeof(double)) - #endif diff --git a/src/tools/inks.h b/src/tools/inks.h index 1dd832187..ee7eaa33b 100644 --- a/src/tools/inks.h +++ b/src/tools/inks.h @@ -258,7 +258,7 @@ public: if (state) { if (loop->getSprite()->getUndo()->isEnabled()) - undo_set_mask(loop->getSprite()->getUndo(), loop->getSprite()); + loop->getSprite()->getUndo()->undo_set_mask(loop->getSprite()); loop->getMask()->freeze(); loop->getMask()->reserve(0, 0, loop->getSprite()->getWidth(), loop->getSprite()->getHeight()); diff --git a/src/undoable.cpp b/src/undoable.cpp index 67568e089..2c14bf04e 100644 --- a/src/undoable.cpp +++ b/src/undoable.cpp @@ -52,7 +52,7 @@ Undoable::Undoable(SpriteWriter& sprite, const char* label) if (isEnabled()) { m_sprite->getUndo()->setLabel(label); - undo_open(m_sprite->getUndo()); + m_sprite->getUndo()->undo_open(); } } @@ -60,7 +60,7 @@ Undoable::~Undoable() { if (isEnabled()) { // close the undo information - undo_close(m_sprite->getUndo()); + m_sprite->getUndo()->undo_close(); // if it isn't committed, we have to rollback all changes if (!m_committed) { @@ -92,7 +92,7 @@ void Undoable::setNumberOfFrames(int frames) // Save in undo the current totalFrames property if (isEnabled()) - undo_set_frames(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_frames(m_sprite); // Change the property m_sprite->setTotalFrames(frames); @@ -103,7 +103,7 @@ void Undoable::setCurrentFrame(int frame) ASSERT(frame >= 0); if (isEnabled()) - undo_set_frame(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_frame(m_sprite); m_sprite->setCurrentFrame(frame); } @@ -117,7 +117,7 @@ void Undoable::setCurrentFrame(int frame) void Undoable::setCurrentLayer(Layer* layer) { if (isEnabled()) - undo_set_layer(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_layer(m_sprite); m_sprite->setCurrentLayer(layer); } @@ -128,7 +128,7 @@ void Undoable::setSpriteSize(int w, int h) ASSERT(h > 0); if (isEnabled()) - undo_set_size(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_size(m_sprite); m_sprite->setSize(w, h); } @@ -198,7 +198,7 @@ void Undoable::setImgType(int new_imgtype, int dithering_method) /* change imgtype of the stock of images */ if (isEnabled()) - undo_int(m_sprite->getUndo(), m_sprite->getStock(), &m_sprite->getStock()->m_imgtype); + m_sprite->getUndo()->undo_int(m_sprite->getStock(), &m_sprite->getStock()->m_imgtype); m_sprite->getStock()->setImgType(new_imgtype); @@ -218,7 +218,7 @@ void Undoable::setImgType(int new_imgtype, int dithering_method) we should undo all work done */ if (isEnabled()) - undo_replace_image(m_sprite->getUndo(), m_sprite->getStock(), c); + m_sprite->getUndo()->undo_replace_image(m_sprite->getStock(), c); image_free(old_image); m_sprite->getStock()->replaceImage(c, new_image); @@ -226,7 +226,7 @@ void Undoable::setImgType(int new_imgtype, int dithering_method) /* change "sprite.imgtype" field */ if (isEnabled()) - undo_set_imgtype(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_imgtype(m_sprite); m_sprite->setImgType(new_imgtype); @@ -237,7 +237,7 @@ void Undoable::setImgType(int new_imgtype, int dithering_method) PalettesList palettes = m_sprite->getPalettes(); for (PalettesList::iterator it = palettes.begin(); it != palettes.end(); ++it) { Palette* palette = *it; - undo_remove_palette(m_sprite->getUndo(), m_sprite, palette); + m_sprite->getUndo()->undo_remove_palette(m_sprite, palette); } } @@ -262,7 +262,7 @@ int Undoable::addImageInStock(Image* image) int image_index = m_sprite->getStock()->addImage(image); if (isEnabled()) - undo_add_image(m_sprite->getUndo(), m_sprite->getStock(), image_index); + m_sprite->getUndo()->undo_add_image(m_sprite->getStock(), image_index); return image_index; } @@ -278,7 +278,7 @@ void Undoable::removeImageFromStock(int image_index) ASSERT(image); if (isEnabled()) - undo_remove_image(m_sprite->getUndo(), m_sprite->getStock(), image_index); + m_sprite->getUndo()->undo_remove_image(m_sprite->getStock(), image_index); m_sprite->getStock()->removeImage(image); image_free(image); @@ -292,7 +292,7 @@ void Undoable::replaceStockImage(int image_index, Image* new_image) // replace the image in the stock if (isEnabled()) - undo_replace_image(m_sprite->getUndo(), m_sprite->getStock(), image_index); + m_sprite->getUndo()->undo_replace_image(m_sprite->getStock(), image_index); m_sprite->getStock()->replaceImage(image_index, new_image); @@ -313,7 +313,7 @@ Layer* Undoable::newLayer() // add the layer in the sprite set if (isEnabled()) - undo_add_layer(m_sprite->getUndo(), m_sprite->getFolder(), layer); + m_sprite->getUndo()->undo_add_layer(m_sprite->getFolder(), layer); m_sprite->getFolder()->add_layer(layer); @@ -351,7 +351,7 @@ void Undoable::removeLayer(Layer* layer) // remove the layer if (isEnabled()) - undo_remove_layer(m_sprite->getUndo(), layer); + m_sprite->getUndo()->undo_remove_layer(layer); parent->remove_layer(layer); @@ -362,7 +362,7 @@ void Undoable::removeLayer(Layer* layer) void Undoable::moveLayerAfter(Layer* layer, Layer* after_this) { if (isEnabled()) - undo_move_layer(m_sprite->getUndo(), layer); + m_sprite->getUndo()->undo_move_layer(layer); layer->get_parent()->move_layer(layer, after_this); } @@ -451,7 +451,7 @@ void Undoable::backgroundFromLayer(LayerImage* layer, int bgcolor) if (bg_image->w == cel_image->w && bg_image->h == cel_image->h) { if (isEnabled()) - undo_image(m_sprite->getUndo(), cel_image, 0, 0, cel_image->w, cel_image->h); + m_sprite->getUndo()->undo_image(cel_image, 0, 0, cel_image->w, cel_image->h); image_copy(cel_image, bg_image, 0, 0); } @@ -489,12 +489,12 @@ void Undoable::layerFromBackground() ASSERT(m_sprite->getCurrentLayer()->is_background()); if (isEnabled()) { - undo_data(m_sprite->getUndo(), + m_sprite->getUndo()->undo_data( m_sprite->getCurrentLayer(), m_sprite->getCurrentLayer()->flags_addr(), sizeof(*m_sprite->getCurrentLayer()->flags_addr())); - undo_set_layer_name(m_sprite->getUndo(), m_sprite->getCurrentLayer()); + m_sprite->getUndo()->undo_set_layer_name(m_sprite->getCurrentLayer()); } m_sprite->getCurrentLayer()->set_background(false); @@ -521,12 +521,12 @@ void Undoable::flattenLayers(int bgcolor) background = new LayerImage(m_sprite); if (isEnabled()) - undo_add_layer(m_sprite->getUndo(), m_sprite->getFolder(), background); + m_sprite->getUndo()->undo_add_layer(m_sprite->getFolder(), background); m_sprite->getFolder()->add_layer(background); if (isEnabled()) - undo_move_layer(m_sprite->getUndo(), background); + m_sprite->getUndo()->undo_move_layer(background); background->configureAsBackground(); } @@ -546,7 +546,7 @@ void Undoable::flattenLayers(int bgcolor) if (isEnabled()) { Dirty* dirty = dirty_new_from_differences(cel_image, image); dirty_save_image_data(dirty); - undo_dirty(m_sprite->getUndo(), dirty); + m_sprite->getUndo()->undo_dirty(dirty); } } else { @@ -569,7 +569,7 @@ void Undoable::flattenLayers(int bgcolor) /* select the background */ if (m_sprite->getCurrentLayer() != background) { if (isEnabled()) - undo_set_layer(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_layer(m_sprite); m_sprite->setCurrentLayer(background); } @@ -585,7 +585,7 @@ void Undoable::flattenLayers(int bgcolor) // remove the layer if (isEnabled()) - undo_remove_layer(m_sprite->getUndo(), old_layer); + m_sprite->getUndo()->undo_remove_layer(old_layer); m_sprite->getFolder()->remove_layer(old_layer); @@ -598,9 +598,9 @@ void Undoable::flattenLayers(int bgcolor) void Undoable::configureLayerAsBackground(LayerImage* layer) { if (isEnabled()) { - undo_data(m_sprite->getUndo(), layer, layer->flags_addr(), sizeof(*layer->flags_addr())); - undo_set_layer_name(m_sprite->getUndo(), layer); - undo_move_layer(m_sprite->getUndo(), layer); + m_sprite->getUndo()->undo_data(layer, layer->flags_addr(), sizeof(*layer->flags_addr())); + m_sprite->getUndo()->undo_set_layer_name(layer); + m_sprite->getUndo()->undo_move_layer(layer); } layer->configureAsBackground(); @@ -734,7 +734,7 @@ void Undoable::addCel(LayerImage* layer, Cel* cel) ASSERT(cel); if (isEnabled()) - undo_add_cel(m_sprite->getUndo(), layer, cel); + m_sprite->getUndo()->undo_add_cel(layer, cel); layer->addCel(cel); } @@ -761,7 +761,7 @@ void Undoable::removeCel(LayerImage* layer, Cel* cel) removeImageFromStock(cel->image); if (isEnabled()) - undo_remove_cel(m_sprite->getUndo(), layer, cel); + m_sprite->getUndo()->undo_remove_cel(layer, cel); // remove the cel from the layer layer->removeCel(cel); @@ -776,7 +776,7 @@ void Undoable::setCelFramePosition(Cel* cel, int frame) ASSERT(frame >= 0); if (isEnabled()) - undo_int(m_sprite->getUndo(), cel, &cel->frame); + m_sprite->getUndo()->undo_int(cel, &cel->frame); cel->frame = frame; } @@ -786,8 +786,8 @@ void Undoable::setCelPosition(Cel* cel, int x, int y) ASSERT(cel); if (isEnabled()) { - undo_int(m_sprite->getUndo(), cel, &cel->x); - undo_int(m_sprite->getUndo(), cel, &cel->y); + m_sprite->getUndo()->undo_int(cel, &cel->x); + m_sprite->getUndo()->undo_int(cel, &cel->y); } cel->x = x; @@ -797,7 +797,7 @@ void Undoable::setCelPosition(Cel* cel, int x, int y) void Undoable::setFrameDuration(int frame, int msecs) { if (isEnabled()) - undo_set_frlen(m_sprite->getUndo(), m_sprite, frame); + m_sprite->getUndo()->undo_set_frlen(m_sprite, frame); m_sprite->setFrameDuration(frame, msecs); } @@ -806,7 +806,7 @@ void Undoable::setConstantFrameRate(int msecs) { if (isEnabled()) { for (int fr=0; frgetTotalFrames(); ++fr) - undo_set_frlen(m_sprite->getUndo(), m_sprite, fr); + m_sprite->getUndo()->undo_set_frlen(m_sprite, fr); } m_sprite->setDurationForAllFrames(msecs); @@ -944,7 +944,7 @@ void Undoable::clearMask(int bgcolor) // if the layer is the background then we clear the image if (m_sprite->getCurrentLayer()->is_background()) { if (isEnabled()) - undo_image(m_sprite->getUndo(), image, 0, 0, image->w, image->h); + m_sprite->getUndo()->undo_image(image, 0, 0, image->w, image->h); // clear all image_clear(image, bgcolor); @@ -969,7 +969,7 @@ void Undoable::clearMask(int bgcolor) return; if (isEnabled()) - undo_image(m_sprite->getUndo(), image, x1, y1, x2-x1+1, y2-y1+1); + m_sprite->getUndo()->undo_image(image, x1, y1, x2-x1+1, y2-y1+1); // clear the masked zones for (v=0; vgetMask()->h; v++) { @@ -995,10 +995,10 @@ void Undoable::flipImage(Image* image, int x1, int y1, int x2, int y2, // insert the undo operation if (isEnabled()) { if (flip_horizontal) - undo_flip(m_sprite->getUndo(), image, x1, y1, x2, y2, true); + m_sprite->getUndo()->undo_flip(image, x1, y1, x2, y2, true); if (flip_vertical) - undo_flip(m_sprite->getUndo(), image, x1, y1, x2, y2, false); + m_sprite->getUndo()->undo_flip(image, x1, y1, x2, y2, false); } // flip the portion of the bitmap @@ -1040,7 +1040,7 @@ void Undoable::copyToCurrentMask(Mask* mask) ASSERT(mask); if (isEnabled()) - undo_set_mask(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_mask(m_sprite); mask_copy(m_sprite->getMask(), mask); } @@ -1050,8 +1050,8 @@ void Undoable::setMaskPosition(int x, int y) ASSERT(m_sprite->getMask()); if (isEnabled()) { - undo_int(m_sprite->getUndo(), m_sprite->getMask(), &m_sprite->getMask()->x); - undo_int(m_sprite->getUndo(), m_sprite->getMask(), &m_sprite->getMask()->y); + m_sprite->getUndo()->undo_int(m_sprite->getMask(), &m_sprite->getMask()->x); + m_sprite->getUndo()->undo_int(m_sprite->getMask(), &m_sprite->getMask()->y); } m_sprite->getMask()->x = x; @@ -1073,7 +1073,7 @@ void Undoable::deselectMask() m_sprite->addMask(mask); if (isEnabled()) - undo_set_mask(m_sprite->getUndo(), m_sprite); + m_sprite->getUndo()->undo_set_mask(m_sprite); /// Deselect the mask mask_none(m_sprite->getMask()); diff --git a/src/util/celmove.cpp b/src/util/celmove.cpp index c8408034c..5c6d61168 100644 --- a/src/util/celmove.cpp +++ b/src/util/celmove.cpp @@ -71,10 +71,10 @@ void move_cel(SpriteWriter& sprite) if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Move Cel"); - undo_open(sprite->getUndo()); + sprite->getUndo()->undo_open(); - undo_set_layer(sprite->getUndo(), sprite); - undo_set_frame(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_layer(sprite); + sprite->getUndo()->undo_set_frame(sprite); } sprite->setCurrentLayer(dst_layer); @@ -89,14 +89,14 @@ void move_cel(SpriteWriter& sprite) if (src_cel != NULL) { if (src_layer == dst_layer) { if (sprite->getUndo()->isEnabled()) - undo_int(sprite->getUndo(), (GfxObj *)src_cel, &src_cel->frame); + sprite->getUndo()->undo_int(src_cel, &src_cel->frame); src_cel->frame = dst_frame; } /* move the cel in different layers */ else { if (sprite->getUndo()->isEnabled()) - undo_remove_cel(sprite->getUndo(), src_layer, src_cel); + sprite->getUndo()->undo_remove_cel(src_layer, src_cel); static_cast(src_layer)->removeCel(src_cel); src_cel->frame = dst_frame; @@ -114,10 +114,10 @@ void move_cel(SpriteWriter& sprite) sprite->getHeight(), 0); if (sprite->getUndo()->isEnabled()) { - undo_replace_image(sprite->getUndo(), sprite->getStock(), src_cel->image); - undo_int(sprite->getUndo(), (GfxObj *)src_cel, &src_cel->x); - undo_int(sprite->getUndo(), (GfxObj *)src_cel, &src_cel->y); - undo_int(sprite->getUndo(), (GfxObj *)src_cel, &src_cel->opacity); + sprite->getUndo()->undo_replace_image(sprite->getStock(), src_cel->image); + sprite->getUndo()->undo_int(src_cel, &src_cel->x); + sprite->getUndo()->undo_int(src_cel, &src_cel->y); + sprite->getUndo()->undo_int(src_cel, &src_cel->opacity); } image_clear(dst_image, app_get_color_to_clear_layer(dst_layer)); @@ -132,14 +132,14 @@ void move_cel(SpriteWriter& sprite) } if (sprite->getUndo()->isEnabled()) - undo_add_cel(sprite->getUndo(), dst_layer, src_cel); + sprite->getUndo()->undo_add_cel(dst_layer, src_cel); static_cast(dst_layer)->addCel(src_cel); } } if (sprite->getUndo()->isEnabled()) - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_close(); set_frame_to_handle(NULL, 0, NULL, 0); } @@ -158,10 +158,10 @@ void copy_cel(SpriteWriter& sprite) if (sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Move Cel"); - undo_open(sprite->getUndo()); + sprite->getUndo()->undo_open(); - undo_set_layer(sprite->getUndo(), sprite); - undo_set_frame(sprite->getUndo(), sprite); + sprite->getUndo()->undo_set_layer(sprite); + sprite->getUndo()->undo_set_frame(sprite); } sprite->setCurrentLayer(dst_layer); @@ -209,7 +209,7 @@ void copy_cel(SpriteWriter& sprite) /* add the image in the stock */ image_index = sprite->getStock()->addImage(dst_image); if (sprite->getUndo()->isEnabled()) - undo_add_image(sprite->getUndo(), sprite->getStock(), image_index); + sprite->getUndo()->undo_add_image(sprite->getStock(), image_index); /* create the new cel */ dst_cel = cel_new(dst_frame, image_index); @@ -217,13 +217,13 @@ void copy_cel(SpriteWriter& sprite) cel_set_opacity(dst_cel, dst_cel_opacity); if (sprite->getUndo()->isEnabled()) - undo_add_cel(sprite->getUndo(), dst_layer, dst_cel); + sprite->getUndo()->undo_add_cel(dst_layer, dst_cel); static_cast(dst_layer)->addCel(dst_cel); } if (sprite->getUndo()->isEnabled()) - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_close(); set_frame_to_handle(NULL, 0, NULL, 0); } @@ -248,7 +248,7 @@ static void remove_cel(Sprite* sprite, LayerImage *layer, Cel *cel) } if (sprite->getUndo()->isEnabled()) - undo_open(sprite->getUndo()); + sprite->getUndo()->undo_open(); if (!used) { /* if the image is only used by this cel, we can remove the @@ -256,15 +256,15 @@ static void remove_cel(Sprite* sprite, LayerImage *layer, Cel *cel) image = sprite->getStock()->getImage(cel->image); if (sprite->getUndo()->isEnabled()) - undo_remove_image(sprite->getUndo(), sprite->getStock(), cel->image); + sprite->getUndo()->undo_remove_image(sprite->getStock(), cel->image); sprite->getStock()->removeImage(image); image_free(image); } if (sprite->getUndo()->isEnabled()) { - undo_remove_cel(sprite->getUndo(), layer, cel); - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_remove_cel(layer, cel); + sprite->getUndo()->undo_close(); } // Remove the cel diff --git a/src/util/clipboard.cpp b/src/util/clipboard.cpp index 62892875e..5dbe4e7e7 100644 --- a/src/util/clipboard.cpp +++ b/src/util/clipboard.cpp @@ -225,7 +225,7 @@ void clipboard::paste(SpriteWriter& sprite) // Add the new image in the stock int dst_image_index = sprite->getStock()->addImage(dst_image); if (sprite->getUndo()->isEnabled()) - undo_add_image(sprite->getUndo(), sprite->getStock(), dst_image_index); + sprite->getUndo()->undo_add_image(sprite->getStock(), dst_image_index); // Create the new cel in the current frame with the recently // created image @@ -285,7 +285,7 @@ void clipboard::paste(SpriteWriter& sprite) if (w >= 1 && h >= 1) { /* undo region */ if (sprite->getUndo()->isEnabled()) - undo_image(sprite->getUndo(), dst_image, u1, v1, w, h); + sprite->getUndo()->undo_image(dst_image, u1, v1, w, h); /* draw the transformed image */ image_parallelogram(dst_image, src_image, diff --git a/src/util/misc.cpp b/src/util/misc.cpp index d595673fa..684d52c60 100644 --- a/src/util/misc.cpp +++ b/src/util/misc.cpp @@ -153,10 +153,10 @@ int interactive_move_layer(int mode, bool use_undo, int (*callback)()) if (!editor->editor_click_cancel()) { if (use_undo && sprite->getUndo()->isEnabled()) { sprite->getUndo()->setLabel("Cel Movement"); - undo_open(sprite->getUndo()); - undo_int(sprite->getUndo(), (GfxObj *)cel, &cel->x); - undo_int(sprite->getUndo(), (GfxObj *)cel, &cel->y); - undo_close(sprite->getUndo()); + sprite->getUndo()->undo_open(); + sprite->getUndo()->undo_int(cel, &cel->x); + sprite->getUndo()->undo_int(cel, &cel->y); + sprite->getUndo()->undo_close(); } cel_set_position(cel, new_x, new_y); diff --git a/src/widgets/editor/editor.cpp b/src/widgets/editor/editor.cpp index 848969e1f..81af22c86 100644 --- a/src/widgets/editor/editor.cpp +++ b/src/widgets/editor/editor.cpp @@ -1934,10 +1934,10 @@ public: /* we create the undo information (for the new cel_image in the stock and the new cel in the layer)... */ - undo_open(m_sprite->getUndo()); - undo_add_image(m_sprite->getUndo(), m_sprite->getStock(), m_cel->image); - undo_add_cel(m_sprite->getUndo(), m_sprite->getCurrentLayer(), m_cel); - undo_close(m_sprite->getUndo()); + m_sprite->getUndo()->undo_open(); + m_sprite->getUndo()->undo_add_image(m_sprite->getStock(), m_cel->image); + m_sprite->getUndo()->undo_add_cel(m_sprite->getCurrentLayer(), m_cel); + m_sprite->getUndo()->undo_close(); /* and finally we add the cel again in the layer */ static_cast(m_sprite->getCurrentLayer())->addCel(m_cel); @@ -1952,7 +1952,7 @@ public: dirty_save_image_data(dirty); if (dirty != NULL) - undo_dirty(m_sprite->getUndo(), dirty); + m_sprite->getUndo()->undo_dirty(dirty); dirty_free(dirty); } @@ -1965,23 +1965,23 @@ public: the entire image */ else { if (m_sprite->getUndo()->isEnabled()) { - undo_open(m_sprite->getUndo()); + m_sprite->getUndo()->undo_open(); if (m_cel->x != m_old_cel_x) { int x = m_cel->x; m_cel->x = m_old_cel_x; - undo_int(m_sprite->getUndo(), (GfxObj*)m_cel, &m_cel->x); + m_sprite->getUndo()->undo_int(m_cel, &m_cel->x); m_cel->x = x; } if (m_cel->y != m_old_cel_y) { int y = m_cel->y; m_cel->y = m_old_cel_y; - undo_int(m_sprite->getUndo(), (GfxObj*)m_cel, &m_cel->y); + m_sprite->getUndo()->undo_int(m_cel, &m_cel->y); m_cel->y = y; } - undo_replace_image(m_sprite->getUndo(), m_sprite->getStock(), m_cel->image); - undo_close(m_sprite->getUndo()); + m_sprite->getUndo()->undo_replace_image(m_sprite->getStock(), m_cel->image); + m_sprite->getUndo()->undo_close(); } /* replace the image in the stock */