Remove UndoHistory::undo_* member functions to use Undoers directly

and to avoid undo-lib <-> undoers circular dependency.
This commit is contained in:
David Capello 2011-03-30 18:27:52 -07:00
parent 5576ea7e7c
commit dc58651f79
20 changed files with 227 additions and 327 deletions

View File

@ -28,6 +28,9 @@
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undo_transaction.h" #include "undo_transaction.h"
#include "undoers/add_layer.h"
#include "undoers/move_layer.h"
#include "undoers/set_current_layer.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Duplicate Layer command // Duplicate Layer command
@ -68,15 +71,23 @@ void DuplicateLayerCommand::onExecute(Context* context)
// Create a new layer // Create a new layer
UniquePtr<LayerImage> newLayerPtr(new LayerImage(sprite)); UniquePtr<LayerImage> newLayerPtr(new LayerImage(sprite));
// Disable undo because the layer content is added as a whole with
// AddLayer() undoer.
document->getUndoHistory()->setEnabled(false);
// Copy the layer content (cels + images) // Copy the layer content (cels + images)
document->copyLayerContent(sourceLayer, document, newLayerPtr); document->copyLayerContent(sourceLayer, document, newLayerPtr);
// Restore enabled status.
document->getUndoHistory()->setEnabled(undoTransaction.isEnabled());
// Copy the layer name // Copy the layer name
newLayerPtr->setName(newLayerPtr->getName() + " Copy"); newLayerPtr->setName(newLayerPtr->getName() + " Copy");
// Add the new layer in the sprite. // Add the new layer in the sprite.
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_layer(sourceLayer->get_parent(), newLayerPtr); undo->pushUndoer(new undoers::AddLayer(undo->getObjects(),
sourceLayer->get_parent(), newLayerPtr));
sourceLayer->get_parent()->add_layer(newLayerPtr); sourceLayer->get_parent()->add_layer(newLayerPtr);
@ -84,8 +95,8 @@ void DuplicateLayerCommand::onExecute(Context* context)
Layer* newLayer = newLayerPtr.release(); Layer* newLayer = newLayerPtr.release();
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->undo_move_layer(newLayer); undo->pushUndoer(new undoers::MoveLayer(undo->getObjects(), newLayer));
undo->undo_set_layer(sprite); undo->pushUndoer(new undoers::SetCurrentLayer(undo->getObjects(), sprite));
} }
undoTransaction.commit(); undoTransaction.commit();

View File

@ -26,6 +26,7 @@
#include "raster/mask.h" #include "raster/mask.h"
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_mask.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// invert_mask // invert_mask
@ -80,7 +81,7 @@ void InvertMaskCommand::onExecute(Context* context)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Mask Invert"); undo->setLabel("Mask Invert");
undo->setModification(undo::DoesntModifyDocument); undo->setModification(undo::DoesntModifyDocument);
undo->undo_set_mask(document); undo->pushUndoer(new undoers::SetMask(undo->getObjects(), document));
} }
/* create a new mask */ /* create a new mask */

View File

@ -27,6 +27,7 @@
#include "raster/mask.h" #include "raster/mask.h"
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_mask.h"
#include "util/msk_file.h" #include "util/msk_file.h"
class LoadMaskCommand : public Command class LoadMaskCommand : public Command
@ -89,7 +90,7 @@ void LoadMaskCommand::onExecute(Context* context)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Mask Load"); undo->setLabel("Mask Load");
undo->setModification(undo::DoesntModifyDocument); undo->setModification(undo::DoesntModifyDocument);
undo->undo_set_mask(documentWriter); undo->pushUndoer(new undoers::SetMask(undo->getObjects(), documentWriter));
} }
documentWriter->setMask(mask); documentWriter->setMask(mask);

View File

@ -24,6 +24,7 @@
#include "raster/mask.h" #include "raster/mask.h"
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_mask.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// mask_all // mask_all
@ -62,7 +63,7 @@ void MaskAllCommand::onExecute(Context* context)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Mask All"); undo->setLabel("Mask All");
undo->setModification(undo::DoesntModifyDocument); undo->setModification(undo::DoesntModifyDocument);
undo->undo_set_mask(document); undo->pushUndoer(new undoers::SetMask(undo->getObjects(), document));
} }
// Change the selection // Change the selection

View File

@ -29,7 +29,14 @@
#include "raster/sprite.h" #include "raster/sprite.h"
#include "raster/stock.h" #include "raster/stock.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/add_cel.h"
#include "undoers/add_image.h"
#include "undoers/close_group.h"
#include "undoers/open_group.h"
#include "undoers/remove_layer.h"
#include "undoers/replace_image.h"
#include "undoers/set_cel_position.h" #include "undoers/set_cel_position.h"
#include "undoers/set_current_layer.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// merge_down_layer // merge_down_layer
@ -86,15 +93,15 @@ void MergeDownLayerCommand::onExecute(Context* context)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Merge Down Layer"); undo->setLabel("Merge Down Layer");
undo->setModification(undo::ModifyDocument); undo->setModification(undo::ModifyDocument);
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
} }
for (frpos=0; frpos<sprite->getTotalFrames(); ++frpos) { for (frpos=0; frpos<sprite->getTotalFrames(); ++frpos) {
/* get frames */ // Get frames
src_cel = static_cast<LayerImage*>(src_layer)->getCel(frpos); src_cel = static_cast<LayerImage*>(src_layer)->getCel(frpos);
dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(frpos); dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(frpos);
/* get images */ // Get images
if (src_cel != NULL) if (src_cel != NULL)
src_image = sprite->getStock()->getImage(src_cel->getImage()); src_image = sprite->getStock()->getImage(src_cel->getImage());
else else
@ -105,27 +112,28 @@ void MergeDownLayerCommand::onExecute(Context* context)
else else
dst_image = NULL; dst_image = NULL;
/* with source image? */ // With source image?
if (src_image != NULL) { if (src_image != NULL) {
/* no destination image */ // No destination image
if (dst_image == NULL) { /* only a transparent layer can have a null cel */ if (dst_image == NULL) { // Only a transparent layer can have a null cel
/* copy this cel to the destination layer... */ // Copy this cel to the destination layer...
/* creating a copy of the image */ // Creating a copy of the image
dst_image = image_new_copy(src_image); dst_image = image_new_copy(src_image);
/* adding it in the stock of images */ // Adding it in the stock of images
index = sprite->getStock()->addImage(dst_image); index = sprite->getStock()->addImage(dst_image);
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_image(sprite->getStock(), index); undo->pushUndoer(new undoers::AddImage(
undo->getObjects(), sprite->getStock(), index));
/* creating a copy of the cell */ // Creating a copy of the cell
dst_cel = new Cel(frpos, index); dst_cel = new Cel(frpos, index);
dst_cel->setPosition(src_cel->getX(), src_cel->getY()); dst_cel->setPosition(src_cel->getX(), src_cel->getY());
dst_cel->setOpacity(src_cel->getOpacity()); dst_cel->setOpacity(src_cel->getOpacity());
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_cel(dst_layer, dst_cel); undo->pushUndoer(new undoers::AddCel(undo->getObjects(), dst_layer, dst_cel));
static_cast<LayerImage*>(dst_layer)->addCel(dst_cel); static_cast<LayerImage*>(dst_layer)->addCel(dst_cel);
} }
@ -169,7 +177,8 @@ void MergeDownLayerCommand::onExecute(Context* context)
dst_cel->setPosition(x1, y1); dst_cel->setPosition(x1, y1);
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_replace_image(sprite->getStock(), dst_cel->getImage()); undo->pushUndoer(new undoers::ReplaceImage(undo->getObjects(),
sprite->getStock(), dst_cel->getImage()));
sprite->getStock()->replaceImage(dst_cel->getImage(), new_image); sprite->getStock()->replaceImage(dst_cel->getImage(), new_image);
@ -179,9 +188,9 @@ void MergeDownLayerCommand::onExecute(Context* context)
} }
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->undo_set_layer(sprite); undo->pushUndoer(new undoers::SetCurrentLayer(undo->getObjects(), sprite));
undo->undo_remove_layer(src_layer); undo->pushUndoer(new undoers::RemoveLayer(undo->getObjects(), src_layer));
undo->undo_close(); undo->pushUndoer(new undoers::CloseGroup());
} }
sprite->setCurrentLayer(dst_layer); sprite->setCurrentLayer(dst_layer);

View File

@ -45,6 +45,7 @@
#include "skin/skin_slider_property.h" #include "skin/skin_slider_property.h"
#include "ui_context.h" #include "ui_context.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_palette_colors.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "widgets/color_sliders.h" #include "widgets/color_sliders.h"
#include "widgets/editor/editor.h" #include "widgets/editor/editor.h"
@ -665,7 +666,8 @@ void PaletteEntryEditor::updateCurrentSpritePalette(const char* operationName)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel(operationName); undo->setLabel(operationName);
undo->setModification(undo::ModifyDocument); undo->setModification(undo::ModifyDocument);
undo->undo_set_palette_colors(sprite, currentSpritePalette, from, to); undo->pushUndoer(new undoers::SetPaletteColors(undo->getObjects(),
sprite, currentSpritePalette, from, to));
} }
// Change the sprite palette // Change the sprite palette

View File

@ -24,6 +24,7 @@
#include "raster/mask.h" #include "raster/mask.h"
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_mask.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// reselect_mask // reselect_mask
@ -65,7 +66,7 @@ void ReselectMaskCommand::onExecute(Context* context)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Mask Reselection"); undo->setLabel("Mask Reselection");
undo->setModification(undo::DoesntModifyDocument); undo->setModification(undo::DoesntModifyDocument);
undo->undo_set_mask(document); undo->pushUndoer(new undoers::SetMask(undo->getObjects(), document));
} }
// Make the mask visible again. // Make the mask visible again.

View File

@ -36,6 +36,9 @@
#include "raster/sprite.h" #include "raster/sprite.h"
#include "raster/stock.h" #include "raster/stock.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/close_group.h"
#include "undoers/image_area.h"
#include "undoers/open_group.h"
#include "widgets/editor/editor.h" #include "widgets/editor/editor.h"
#include <cstdlib> #include <cstdlib>
@ -209,7 +212,7 @@ void FilterManagerImpl::apply()
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel(m_filter->getName()); undo->setLabel(m_filter->getName());
undo->setModification(undo::ModifyDocument); undo->setModification(undo::ModifyDocument);
undo->undo_image(m_src, m_x, m_y, m_w, m_h); undo->pushUndoer(new undoers::ImageArea(undo->getObjects(), m_src, m_x, m_y, m_w, m_h));
} }
// Copy "dst" to "src" // Copy "dst" to "src"
@ -236,7 +239,7 @@ void FilterManagerImpl::applyToTarget()
// Open group of undo operations // Open group of undo operations
if (images.size() > 1) { if (images.size() > 1) {
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
} }
m_progressBase = 0.0f; m_progressBase = 0.0f;
@ -259,7 +262,7 @@ void FilterManagerImpl::applyToTarget()
// Close group of undo operations // Close group of undo operations
if (images.size() > 1) { if (images.size() > 1) {
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_close(); undo->pushUndoer(new undoers::CloseGroup());
} }
} }

View File

@ -38,6 +38,7 @@
#include "raster/mask.h" #include "raster/mask.h"
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_mask.h"
#include "util/misc.h" #include "util/misc.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "widgets/color_button.h" #include "widgets/color_button.h"
@ -143,7 +144,7 @@ void dialogs_mask_color(Document* document)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Mask by Color"); undo->setLabel("Mask by Color");
undo->setModification(undo::DoesntModifyDocument); undo->setModification(undo::DoesntModifyDocument);
undo->undo_set_mask(document); undo->pushUndoer(new undoers::SetMask(undo->getObjects(), document));
} }
/* change the mask */ /* change the mask */

View File

@ -33,6 +33,8 @@
#include "raster/sprite.h" #include "raster/sprite.h"
#include "raster/stock.h" #include "raster/stock.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/add_image.h"
#include "undoers/add_layer.h"
#include "util/boundary.h" #include "util/boundary.h"
using namespace undo; using namespace undo;
@ -290,6 +292,8 @@ void Document::setMaskVisible(bool visible)
void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, Layer* destLayer0) const void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, Layer* destLayer0) const
{ {
UndoHistory* undo = destDoc->getUndoHistory();
// Copy the layer name // Copy the layer name
destLayer0->setName(sourceLayer0->getName()); destLayer0->setName(sourceLayer0->getName());
@ -312,12 +316,13 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
ASSERT(sourceImage != NULL); ASSERT(sourceImage != NULL);
Image* newImage = image_new_copy(sourceImage); Image* newImage = image_new_copy(sourceImage);
newCel->setImage(destLayer->getSprite()->getStock()->addImage(newImage)); newCel->setImage(destLayer->getSprite()->getStock()->addImage(newImage));
if (destDoc->getUndoHistory()->isEnabled()) if (undo->isEnabled()) {
destDoc->getUndoHistory()->undo_add_image(destLayer->getSprite()->getStock(), undo->pushUndoer(new undoers::AddImage(undo->getObjects(),
newCel->getImage()); destLayer->getSprite()->getStock(),
newCel->getImage()));
}
destLayer->addCel(newCel); destLayer->addCel(newCel);
newCel.release(); newCel.release();
@ -349,8 +354,9 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
ASSERT(destChild != NULL); ASSERT(destChild != NULL);
// Add the new layer in the sprite. // Add the new layer in the sprite.
if (destDoc->getUndoHistory()->isEnabled()) if (undo->isEnabled())
destDoc->getUndoHistory()->undo_add_layer(destLayer, destChild); undo->pushUndoer(new undoers::AddLayer(undo->getObjects(),
destLayer, destChild));
destLayer->add_layer(destChild); destLayer->add_layer(destChild);
destChild.release(); destChild.release();

View File

@ -23,6 +23,7 @@
#include "context.h" #include "context.h"
#include "document.h" #include "document.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/set_mask.h"
// Ink used for tools which paint with primary/secondary // Ink used for tools which paint with primary/secondary
@ -259,8 +260,9 @@ public:
m_modify_selection = state; m_modify_selection = state;
if (state) { if (state) {
if (loop->getDocument()->getUndoHistory()->isEnabled()) undo::UndoHistory* undo = loop->getDocument()->getUndoHistory();
loop->getDocument()->getUndoHistory()->undo_set_mask(loop->getDocument()); if (undo->isEnabled())
undo->pushUndoer(new undoers::SetMask(undo->getObjects(), loop->getDocument()));
loop->getMask()->freeze(); loop->getMask()->freeze();
loop->getMask()->reserve(0, 0, loop->getSprite()->getWidth(), loop->getSprite()->getHeight()); loop->getMask()->reserve(0, 0, loop->getSprite()->getWidth(), loop->getSprite()->getHeight());

View File

@ -3,5 +3,4 @@
add_library(undo-lib add_library(undo-lib
undo_history.cpp undo_history.cpp
undo_history_backward.cpp
undoers_stack.cpp) undoers_stack.cpp)

View File

@ -12,18 +12,6 @@
#include <vector> #include <vector>
// TODO Remove this (it is here only for backward compatibility)
class Cel;
class Dirty;
class Document;
class GfxObj;
class Image;
class Layer;
class Mask;
class Palette;
class Sprite;
class Stock;
namespace undo { namespace undo {
class ObjectsContainer; class ObjectsContainer;
@ -67,33 +55,6 @@ public:
// UndoersCollector interface // UndoersCollector interface
void pushUndoer(Undoer* undoer); void pushUndoer(Undoer* undoer);
// Backward compatibility methods
void undo_open();
void undo_close();
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(Image* image, 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_set_palette_colors(Sprite* sprite, Palette* palette, int from, int to);
void undo_remap_palette(Sprite* sprite, int frame_from, int frame_to, const std::vector<uint8_t>& mapping);
void undo_set_mask(Document* document);
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);
private: private:
enum Direction { UndoDirection, RedoDirection }; enum Direction { UndoDirection, RedoDirection };

View File

@ -1,166 +0,0 @@
// ASEPRITE Undo Library
// Copyright (C) 2001-2011 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#include "config.h"
#include "undo/undo_history.h"
#include "raster/palette.h"
#include "undo/undoers_stack.h"
#include "undoers/add_cel.h"
#include "undoers/add_image.h"
#include "undoers/add_layer.h"
#include "undoers/add_palette.h"
#include "undoers/close_group.h"
#include "undoers/dirty_area.h"
#include "undoers/flip_image.h"
#include "undoers/image_area.h"
#include "undoers/move_layer.h"
#include "undoers/open_group.h"
#include "undoers/remap_palette.h"
#include "undoers/remove_cel.h"
#include "undoers/remove_image.h"
#include "undoers/remove_layer.h"
#include "undoers/remove_palette.h"
#include "undoers/replace_image.h"
#include "undoers/set_current_frame.h"
#include "undoers/set_current_layer.h"
#include "undoers/set_frame_duration.h"
#include "undoers/set_layer_name.h"
#include "undoers/set_mask.h"
#include "undoers/set_palette_colors.h"
#include "undoers/set_sprite_imgtype.h"
#include "undoers/set_sprite_size.h"
#include "undoers/set_total_frames.h"
using namespace undo;
void UndoHistory::undo_open()
{
pushUndoer(new undoers::OpenGroup());
}
void UndoHistory::undo_close()
{
pushUndoer(new undoers::CloseGroup());
}
void UndoHistory::undo_image(Image* image, int x, int y, int w, int h)
{
pushUndoer(new undoers::ImageArea(getObjects(), image, x, y, w, h));
}
void UndoHistory::undo_flip(Image* image, int x1, int y1, int x2, int y2, bool horz)
{
pushUndoer(new undoers::FlipImage(getObjects(), image, x1, y1, x2-x1+1, y2-y1+1,
(horz ? undoers::FlipImage::FlipHorizontal:
undoers::FlipImage::FlipVertical)));
}
void UndoHistory::undo_dirty(Image* image, Dirty* dirty)
{
pushUndoer(new undoers::DirtyArea(getObjects(), image, dirty));
}
void UndoHistory::undo_add_image(Stock* stock, int imageIndex)
{
pushUndoer(new undoers::AddImage(getObjects(), stock, imageIndex));
}
void UndoHistory::undo_remove_image(Stock *stock, int imageIndex)
{
pushUndoer(new undoers::RemoveImage(getObjects(), stock, imageIndex));
}
void UndoHistory::undo_replace_image(Stock *stock, int imageIndex)
{
pushUndoer(new undoers::ReplaceImage(getObjects(), stock, imageIndex));
}
void UndoHistory::undo_add_cel(Layer* layer, Cel* cel)
{
pushUndoer(new undoers::AddCel(getObjects(), layer, cel));
}
void UndoHistory::undo_remove_cel(Layer* layer, Cel* cel)
{
pushUndoer(new undoers::RemoveCel(getObjects(), layer, cel));
}
void UndoHistory::undo_set_layer_name(Layer* layer)
{
pushUndoer(new undoers::SetLayerName(getObjects(), layer));
}
void UndoHistory::undo_add_layer(Layer* folder, Layer* layer)
{
pushUndoer(new undoers::AddLayer(getObjects(), folder, layer));
}
void UndoHistory::undo_remove_layer(Layer* layer)
{
pushUndoer(new undoers::RemoveLayer(getObjects(), layer));
}
void UndoHistory::undo_move_layer(Layer* layer)
{
pushUndoer(new undoers::MoveLayer(getObjects(), layer));
}
void UndoHistory::undo_set_layer(Sprite* sprite)
{
pushUndoer(new undoers::SetCurrentLayer(getObjects(), sprite));
}
void UndoHistory::undo_add_palette(Sprite* sprite, Palette* palette)
{
pushUndoer(new undoers::AddPalette(getObjects(), sprite, palette->getFrame()));
}
void UndoHistory::undo_remove_palette(Sprite* sprite, Palette* palette)
{
pushUndoer(new undoers::RemovePalette(getObjects(), sprite, palette->getFrame()));
}
void UndoHistory::undo_set_palette_colors(Sprite* sprite, Palette* palette, int from, int to)
{
pushUndoer(new undoers::SetPaletteColors(getObjects(), sprite, palette, from, to));
}
void UndoHistory::undo_remap_palette(Sprite* sprite, int frameFrom, int frameTo, const std::vector<uint8_t>& mapping)
{
pushUndoer(new undoers::RemapPalette(getObjects(), sprite, frameFrom, frameTo, mapping));
}
void UndoHistory::undo_set_mask(Document* document)
{
pushUndoer(new undoers::SetMask(getObjects(), document));
}
void UndoHistory::undo_set_imgtype(Sprite* sprite)
{
pushUndoer(new undoers::SetSpriteImgType(getObjects(), sprite));
}
void UndoHistory::undo_set_size(Sprite* sprite)
{
pushUndoer(new undoers::SetSpriteSize(getObjects(), sprite));
}
void UndoHistory::undo_set_frame(Sprite* sprite)
{
pushUndoer(new undoers::SetCurrentFrame(getObjects(), sprite));
}
void UndoHistory::undo_set_frames(Sprite* sprite)
{
pushUndoer(new undoers::SetTotalFrames(getObjects(), sprite));
}
void UndoHistory::undo_set_frlen(Sprite* sprite, int frame)
{
pushUndoer(new undoers::SetFrameDuration(getObjects(), sprite, frame));
}

View File

@ -33,11 +33,33 @@
#include "raster/sprite.h" #include "raster/sprite.h"
#include "raster/stock.h" #include "raster/stock.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/add_cel.h"
#include "undoers/add_image.h"
#include "undoers/add_layer.h"
#include "undoers/close_group.h"
#include "undoers/dirty_area.h"
#include "undoers/flip_image.h"
#include "undoers/image_area.h"
#include "undoers/move_layer.h"
#include "undoers/open_group.h"
#include "undoers/remove_cel.h"
#include "undoers/remove_image.h"
#include "undoers/remove_layer.h"
#include "undoers/remove_palette.h"
#include "undoers/replace_image.h"
#include "undoers/set_cel_frame.h" #include "undoers/set_cel_frame.h"
#include "undoers/set_cel_position.h" #include "undoers/set_cel_position.h"
#include "undoers/set_current_frame.h"
#include "undoers/set_current_layer.h"
#include "undoers/set_frame_duration.h"
#include "undoers/set_layer_flags.h" #include "undoers/set_layer_flags.h"
#include "undoers/set_layer_name.h"
#include "undoers/set_mask.h"
#include "undoers/set_mask_position.h" #include "undoers/set_mask_position.h"
#include "undoers/set_sprite_imgtype.h"
#include "undoers/set_sprite_size.h"
#include "undoers/set_stock_imgtype.h" #include "undoers/set_stock_imgtype.h"
#include "undoers/set_total_frames.h"
UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Modification modification) UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Modification modification)
{ {
@ -53,7 +75,7 @@ UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Mo
if (isEnabled()) { if (isEnabled()) {
m_undoHistory->setLabel(label); m_undoHistory->setLabel(label);
m_undoHistory->setModification(modification); m_undoHistory->setModification(modification);
m_undoHistory->undo_open(); m_undoHistory->pushUndoer(new undoers::OpenGroup());
} }
} }
@ -82,7 +104,7 @@ void UndoTransaction::closeUndoGroup()
if (isEnabled()) { if (isEnabled()) {
// Close the undo information. // Close the undo information.
m_undoHistory->undo_close(); m_undoHistory->pushUndoer(new undoers::CloseGroup());
m_closed = true; m_closed = true;
} }
} }
@ -122,7 +144,7 @@ void UndoTransaction::setNumberOfFrames(int frames)
// Save in undo the current totalFrames property // Save in undo the current totalFrames property
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_frames(m_sprite); m_undoHistory->pushUndoer(new undoers::SetTotalFrames(m_undoHistory->getObjects(), m_sprite));
// Change the property // Change the property
m_sprite->setTotalFrames(frames); m_sprite->setTotalFrames(frames);
@ -133,7 +155,7 @@ void UndoTransaction::setCurrentFrame(int frame)
ASSERT(frame >= 0); ASSERT(frame >= 0);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_frame(m_sprite); m_undoHistory->pushUndoer(new undoers::SetCurrentFrame(m_undoHistory->getObjects(), m_sprite));
m_sprite->setCurrentFrame(frame); m_sprite->setCurrentFrame(frame);
} }
@ -147,7 +169,8 @@ void UndoTransaction::setCurrentFrame(int frame)
void UndoTransaction::setCurrentLayer(Layer* layer) void UndoTransaction::setCurrentLayer(Layer* layer)
{ {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_layer(m_sprite); m_undoHistory->pushUndoer(new undoers::SetCurrentLayer(
m_undoHistory->getObjects(), m_sprite));
m_sprite->setCurrentLayer(layer); m_sprite->setCurrentLayer(layer);
} }
@ -158,7 +181,7 @@ void UndoTransaction::setSpriteSize(int w, int h)
ASSERT(h > 0); ASSERT(h > 0);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_size(m_sprite); m_undoHistory->pushUndoer(new undoers::SetSpriteSize(m_undoHistory->getObjects(), m_sprite));
m_sprite->setSize(w, h); m_sprite->setSize(w, h);
} }
@ -250,7 +273,7 @@ void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_meth
// Change sprite's "imgtype" field. // Change sprite's "imgtype" field.
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_imgtype(m_sprite); m_undoHistory->pushUndoer(new undoers::SetSpriteImgType(m_undoHistory->getObjects(), m_sprite));
m_sprite->setImgType(new_imgtype); m_sprite->setImgType(new_imgtype);
@ -264,7 +287,8 @@ void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_meth
PalettesList palettes = m_sprite->getPalettes(); PalettesList palettes = m_sprite->getPalettes();
for (PalettesList::iterator it = palettes.begin(); it != palettes.end(); ++it) { for (PalettesList::iterator it = palettes.begin(); it != palettes.end(); ++it) {
Palette* palette = *it; Palette* palette = *it;
m_undoHistory->undo_remove_palette(m_sprite, palette); m_undoHistory->pushUndoer(new undoers::RemovePalette(
m_undoHistory->getObjects(), m_sprite, palette->getFrame()));
} }
} }
@ -289,7 +313,8 @@ int UndoTransaction::addImageInStock(Image* image)
int image_index = m_sprite->getStock()->addImage(image); int image_index = m_sprite->getStock()->addImage(image);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_add_image(m_sprite->getStock(), image_index); m_undoHistory->pushUndoer(new undoers::AddImage(m_undoHistory->getObjects(),
m_sprite->getStock(), image_index));
return image_index; return image_index;
} }
@ -305,7 +330,8 @@ void UndoTransaction::removeImageFromStock(int image_index)
ASSERT(image); ASSERT(image);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_remove_image(m_sprite->getStock(), image_index); m_undoHistory->pushUndoer(new undoers::RemoveImage(m_undoHistory->getObjects(),
m_sprite->getStock(), image_index));
m_sprite->getStock()->removeImage(image); m_sprite->getStock()->removeImage(image);
image_free(image); image_free(image);
@ -319,7 +345,8 @@ void UndoTransaction::replaceStockImage(int image_index, Image* new_image)
// replace the image in the stock // replace the image in the stock
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_replace_image(m_sprite->getStock(), image_index); m_undoHistory->pushUndoer(new undoers::ReplaceImage(m_undoHistory->getObjects(),
m_sprite->getStock(), image_index));
m_sprite->getStock()->replaceImage(image_index, new_image); m_sprite->getStock()->replaceImage(image_index, new_image);
@ -337,7 +364,8 @@ Layer* UndoTransaction::newLayer()
// add the layer in the sprite set // add the layer in the sprite set
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_add_layer(m_sprite->getFolder(), layer); m_undoHistory->pushUndoer(new undoers::AddLayer(m_undoHistory->getObjects(),
m_sprite->getFolder(), layer));
m_sprite->getFolder()->add_layer(layer); m_sprite->getFolder()->add_layer(layer);
@ -375,7 +403,8 @@ void UndoTransaction::removeLayer(Layer* layer)
// remove the layer // remove the layer
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_remove_layer(layer); m_undoHistory->pushUndoer(new undoers::RemoveLayer(m_undoHistory->getObjects(),
layer));
parent->remove_layer(layer); parent->remove_layer(layer);
@ -386,7 +415,7 @@ void UndoTransaction::removeLayer(Layer* layer)
void UndoTransaction::moveLayerAfter(Layer* layer, Layer* after_this) void UndoTransaction::moveLayerAfter(Layer* layer, Layer* after_this)
{ {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_move_layer(layer); m_undoHistory->pushUndoer(new undoers::MoveLayer(m_undoHistory->getObjects(), layer));
layer->get_parent()->move_layer(layer, after_this); layer->get_parent()->move_layer(layer, after_this);
} }
@ -475,7 +504,8 @@ void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor)
if (bg_image->w == cel_image->w && if (bg_image->w == cel_image->w &&
bg_image->h == cel_image->h) { bg_image->h == cel_image->h) {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_image(cel_image, 0, 0, cel_image->w, cel_image->h); m_undoHistory->pushUndoer(new undoers::ImageArea(m_undoHistory->getObjects(),
cel_image, 0, 0, cel_image->w, cel_image->h));
image_copy(cel_image, bg_image, 0, 0); image_copy(cel_image, bg_image, 0, 0);
} }
@ -513,10 +543,8 @@ void UndoTransaction::layerFromBackground()
ASSERT(m_sprite->getCurrentLayer()->is_background()); ASSERT(m_sprite->getCurrentLayer()->is_background());
if (isEnabled()) { if (isEnabled()) {
m_undoHistory->pushUndoer(new undoers::SetLayerFlags(m_undoHistory->getObjects(), m_undoHistory->pushUndoer(new undoers::SetLayerFlags(m_undoHistory->getObjects(), m_sprite->getCurrentLayer()));
m_sprite->getCurrentLayer())); m_undoHistory->pushUndoer(new undoers::SetLayerName(m_undoHistory->getObjects(), m_sprite->getCurrentLayer()));
m_undoHistory->undo_set_layer_name(m_sprite->getCurrentLayer());
} }
m_sprite->getCurrentLayer()->set_background(false); m_sprite->getCurrentLayer()->set_background(false);
@ -543,12 +571,14 @@ void UndoTransaction::flattenLayers(int bgcolor)
background = new LayerImage(m_sprite); background = new LayerImage(m_sprite);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_add_layer(m_sprite->getFolder(), background); m_undoHistory->pushUndoer(new undoers::AddLayer(m_undoHistory->getObjects(),
m_sprite->getFolder(), background));
m_sprite->getFolder()->add_layer(background); m_sprite->getFolder()->add_layer(background);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_move_layer(background); m_undoHistory->pushUndoer(new undoers::MoveLayer(m_undoHistory->getObjects(),
background));
background->configureAsBackground(); background->configureAsBackground();
} }
@ -568,7 +598,8 @@ void UndoTransaction::flattenLayers(int bgcolor)
if (isEnabled()) { if (isEnabled()) {
Dirty* dirty = new Dirty(cel_image, image); Dirty* dirty = new Dirty(cel_image, image);
dirty->saveImagePixels(cel_image); dirty->saveImagePixels(cel_image);
m_undoHistory->undo_dirty(cel_image, dirty); m_undoHistory->pushUndoer(new undoers::DirtyArea(
m_undoHistory->getObjects(), cel_image, dirty));
delete dirty; delete dirty;
} }
} }
@ -592,7 +623,8 @@ void UndoTransaction::flattenLayers(int bgcolor)
/* select the background */ /* select the background */
if (m_sprite->getCurrentLayer() != background) { if (m_sprite->getCurrentLayer() != background) {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_layer(m_sprite); m_undoHistory->pushUndoer(new undoers::SetCurrentLayer(
m_undoHistory->getObjects(), m_sprite));
m_sprite->setCurrentLayer(background); m_sprite->setCurrentLayer(background);
} }
@ -608,7 +640,8 @@ void UndoTransaction::flattenLayers(int bgcolor)
// Remove the layer // Remove the layer
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_remove_layer(old_layer); m_undoHistory->pushUndoer(new undoers::RemoveLayer(m_undoHistory->getObjects(),
old_layer));
m_sprite->getFolder()->remove_layer(old_layer); m_sprite->getFolder()->remove_layer(old_layer);
@ -622,8 +655,8 @@ void UndoTransaction::configureLayerAsBackground(LayerImage* layer)
{ {
if (isEnabled()) { if (isEnabled()) {
m_undoHistory->pushUndoer(new undoers::SetLayerFlags(m_undoHistory->getObjects(), layer)); m_undoHistory->pushUndoer(new undoers::SetLayerFlags(m_undoHistory->getObjects(), layer));
m_undoHistory->undo_set_layer_name(layer); m_undoHistory->pushUndoer(new undoers::SetLayerName(m_undoHistory->getObjects(), layer));
m_undoHistory->undo_move_layer(layer); m_undoHistory->pushUndoer(new undoers::MoveLayer(m_undoHistory->getObjects(), layer));
} }
layer->configureAsBackground(); layer->configureAsBackground();
@ -757,7 +790,8 @@ void UndoTransaction::addCel(LayerImage* layer, Cel* cel)
ASSERT(cel); ASSERT(cel);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_add_cel(layer, cel); m_undoHistory->pushUndoer(new undoers::AddCel(m_undoHistory->getObjects(),
layer, cel));
layer->addCel(cel); layer->addCel(cel);
} }
@ -784,7 +818,8 @@ void UndoTransaction::removeCel(LayerImage* layer, Cel* cel)
removeImageFromStock(cel->getImage()); removeImageFromStock(cel->getImage());
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_remove_cel(layer, cel); m_undoHistory->pushUndoer(new undoers::RemoveCel(m_undoHistory->getObjects(),
layer, cel));
// remove the cel from the layer // remove the cel from the layer
layer->removeCel(cel); layer->removeCel(cel);
@ -817,7 +852,8 @@ void UndoTransaction::setCelPosition(Cel* cel, int x, int y)
void UndoTransaction::setFrameDuration(int frame, int msecs) void UndoTransaction::setFrameDuration(int frame, int msecs)
{ {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_frlen(m_sprite, frame); m_undoHistory->pushUndoer(new undoers::SetFrameDuration(
m_undoHistory->getObjects(), m_sprite, frame));
m_sprite->setFrameDuration(frame, msecs); m_sprite->setFrameDuration(frame, msecs);
} }
@ -826,7 +862,8 @@ void UndoTransaction::setConstantFrameRate(int msecs)
{ {
if (isEnabled()) { if (isEnabled()) {
for (int fr=0; fr<m_sprite->getTotalFrames(); ++fr) for (int fr=0; fr<m_sprite->getTotalFrames(); ++fr)
m_undoHistory->undo_set_frlen(m_sprite, fr); m_undoHistory->pushUndoer(new undoers::SetFrameDuration(
m_undoHistory->getObjects(), m_sprite, fr));
} }
m_sprite->setDurationForAllFrames(msecs); m_sprite->setDurationForAllFrames(msecs);
@ -966,7 +1003,8 @@ void UndoTransaction::clearMask(int bgcolor)
// if the layer is the background then we clear the image // if the layer is the background then we clear the image
if (m_sprite->getCurrentLayer()->is_background()) { if (m_sprite->getCurrentLayer()->is_background()) {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_image(image, 0, 0, image->w, image->h); m_undoHistory->pushUndoer(new undoers::ImageArea(m_undoHistory->getObjects(),
image, 0, 0, image->w, image->h));
// clear all // clear all
image_clear(image, bgcolor); image_clear(image, bgcolor);
@ -991,7 +1029,8 @@ void UndoTransaction::clearMask(int bgcolor)
return; return;
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_image(image, x1, y1, x2-x1+1, y2-y1+1); m_undoHistory->pushUndoer(new undoers::ImageArea(m_undoHistory->getObjects(),
image, x1, y1, x2-x1+1, y2-y1+1));
// clear the masked zones // clear the masked zones
for (v=0; v<mask->h; v++) { for (v=0; v<mask->h; v++) {
@ -1014,16 +1053,16 @@ void UndoTransaction::clearMask(int bgcolor)
void UndoTransaction::flipImage(Image* image, int x1, int y1, int x2, int y2, void UndoTransaction::flipImage(Image* image, int x1, int y1, int x2, int y2,
bool flip_horizontal, bool flip_vertical) bool flip_horizontal, bool flip_vertical)
{ {
// insert the undo operation // Insert the undo operation.
if (isEnabled()) { if (isEnabled()) {
if (flip_horizontal) m_undoHistory->pushUndoer
m_undoHistory->undo_flip(image, x1, y1, x2, y2, true); (new undoers::FlipImage
(m_undoHistory->getObjects(), image, x1, y1, x2-x1+1, y2-y1+1,
if (flip_vertical) (flip_horizontal ? undoers::FlipImage::FlipHorizontal: 0) |
m_undoHistory->undo_flip(image, x1, y1, x2, y2, false); (flip_vertical ? undoers::FlipImage::FlipVertical: 0)));
} }
// flip the portion of the bitmap // Flip the portion of the bitmap.
Image* area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1, 0); Image* area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1, 0);
int x, y; int x, y;
@ -1062,7 +1101,8 @@ void UndoTransaction::copyToCurrentMask(Mask* mask)
ASSERT(mask); ASSERT(mask);
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_mask(m_document); m_undoHistory->pushUndoer(new undoers::SetMask(m_undoHistory->getObjects(),
m_document));
mask_copy(m_document->getMask(), mask); mask_copy(m_document->getMask(), mask);
} }
@ -1081,7 +1121,8 @@ void UndoTransaction::setMaskPosition(int x, int y)
void UndoTransaction::deselectMask() void UndoTransaction::deselectMask()
{ {
if (isEnabled()) if (isEnabled())
m_undoHistory->undo_set_mask(m_document); m_undoHistory->pushUndoer(new undoers::SetMask(m_undoHistory->getObjects(),
m_document));
m_document->setMaskVisible(false); m_document->setMaskVisible(false);
} }

View File

@ -29,11 +29,11 @@
using namespace undo; using namespace undo;
using namespace undoers; using namespace undoers;
FlipImage::FlipImage(ObjectsContainer* objects, Image* image, int x, int y, int w, int h, FlipType flipType) FlipImage::FlipImage(ObjectsContainer* objects, Image* image, int x, int y, int w, int h, int flipFlags)
: m_imageId(objects->addObject(image)) : m_imageId(objects->addObject(image))
, m_imgtype(image->imgtype) , m_imgtype(image->imgtype)
, m_x(x), m_y(y), m_w(w), m_h(h) , m_x(x), m_y(y), m_w(w), m_h(h)
, m_flipType(flipType) , m_flipFlags(flipFlags)
{ {
ASSERT(w >= 1 && h >= 1); ASSERT(w >= 1 && h >= 1);
ASSERT(x >= 0 && y >= 0 && x+w <= image->w && y+h <= image->h); ASSERT(x >= 0 && y >= 0 && x+w <= image->w && y+h <= image->h);
@ -51,7 +51,7 @@ void FlipImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
if (image->imgtype != m_imgtype) if (image->imgtype != m_imgtype)
throw UndoException("Image type does not match"); throw UndoException("Image type does not match");
redoers->pushUndoer(new FlipImage(objects, image, m_x, m_y, m_w, m_h, m_flipType)); redoers->pushUndoer(new FlipImage(objects, image, m_x, m_y, m_w, m_h, m_flipFlags));
UniquePtr<Image> area(image_crop(image, m_x, m_y, m_w, m_h, 0)); UniquePtr<Image> area(image_crop(image, m_x, m_y, m_w, m_h, 0));
int x, y; int x, y;
@ -61,7 +61,7 @@ void FlipImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
for (y=0; y<m_h; ++y) for (y=0; y<m_h; ++y)
for (x=0; x<m_w; ++x) for (x=0; x<m_w; ++x)
image_putpixel(image, image_putpixel(image,
m_flipType == FlipHorizontal ? x2-x: m_x+x, ((m_flipFlags & FlipHorizontal) == FlipHorizontal ? x2-x: m_x+x),
m_flipType == FlipVertical ? y2-y: m_y+y, ((m_flipFlags & FlipVertical) == FlipVertical ? y2-y: m_y+y),
image_getpixel(area, x, y)); image_getpixel(area, x, y));
} }

View File

@ -29,9 +29,9 @@ namespace undoers {
class FlipImage : public UndoerBase class FlipImage : public UndoerBase
{ {
public: public:
enum FlipType { FlipHorizontal, FlipVertical }; enum FlipFlags { FlipHorizontal = 1, FlipVertical = 2 };
FlipImage(undo::ObjectsContainer* objects, Image* image, int x, int y, int w, int h, FlipType flipType); FlipImage(undo::ObjectsContainer* objects, Image* image, int x, int y, int w, int h, int flipFlags);
void dispose() OVERRIDE; void dispose() OVERRIDE;
int getMemSize() const OVERRIDE { return sizeof(*this); } int getMemSize() const OVERRIDE { return sizeof(*this); }
@ -41,7 +41,7 @@ private:
undo::ObjectId m_imageId; undo::ObjectId m_imageId;
uint8_t m_imgtype; uint8_t m_imgtype;
uint16_t m_x, m_y, m_w, m_h; uint16_t m_x, m_y, m_w, m_h;
FlipType m_flipType; uint8_t m_flipFlags;
}; };
} // namespace undoers } // namespace undoers

View File

@ -32,9 +32,18 @@
#include "raster/sprite.h" #include "raster/sprite.h"
#include "raster/stock.h" #include "raster/stock.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/add_cel.h"
#include "undoers/add_image.h"
#include "undoers/close_group.h"
#include "undoers/open_group.h"
#include "undoers/remove_cel.h"
#include "undoers/remove_image.h"
#include "undoers/replace_image.h"
#include "undoers/set_cel_frame.h" #include "undoers/set_cel_frame.h"
#include "undoers/set_cel_opacity.h" #include "undoers/set_cel_opacity.h"
#include "undoers/set_cel_position.h" #include "undoers/set_cel_position.h"
#include "undoers/set_current_frame.h"
#include "undoers/set_current_layer.h"
/* these variables indicate what cel to move (and the sprite's /* these variables indicate what cel to move (and the sprite's
frame indicates where to move it) */ frame indicates where to move it) */
@ -76,10 +85,10 @@ void move_cel(DocumentWriter& document)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Move Cel"); undo->setLabel("Move Cel");
undo->setModification(undo::ModifyDocument); undo->setModification(undo::ModifyDocument);
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
undo->undo_set_layer(sprite); undo->pushUndoer(new undoers::SetCurrentLayer(undo->getObjects(), sprite));
undo->undo_set_frame(sprite); undo->pushUndoer(new undoers::SetCurrentFrame(undo->getObjects(), sprite));
} }
sprite->setCurrentLayer(dst_layer); sprite->setCurrentLayer(dst_layer);
@ -101,7 +110,7 @@ void move_cel(DocumentWriter& document)
/* move the cel in different layers */ /* move the cel in different layers */
else { else {
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_remove_cel(src_layer, src_cel); undo->pushUndoer(new undoers::RemoveCel(undo->getObjects(), src_layer, src_cel));
static_cast<LayerImage*>(src_layer)->removeCel(src_cel); static_cast<LayerImage*>(src_layer)->removeCel(src_cel);
src_cel->setFrame(dst_frame); src_cel->setFrame(dst_frame);
@ -119,7 +128,8 @@ void move_cel(DocumentWriter& document)
sprite->getHeight(), 0); sprite->getHeight(), 0);
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->undo_replace_image(sprite->getStock(), src_cel->getImage()); undo->pushUndoer(new undoers::ReplaceImage(undo->getObjects(),
sprite->getStock(), src_cel->getImage()));
undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), src_cel)); undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), src_cel));
undo->pushUndoer(new undoers::SetCelOpacity(undo->getObjects(), src_cel)); undo->pushUndoer(new undoers::SetCelOpacity(undo->getObjects(), src_cel));
} }
@ -135,14 +145,14 @@ void move_cel(DocumentWriter& document)
} }
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_cel(dst_layer, src_cel); undo->pushUndoer(new undoers::AddCel(undo->getObjects(), dst_layer, src_cel));
static_cast<LayerImage*>(dst_layer)->addCel(src_cel); static_cast<LayerImage*>(dst_layer)->addCel(src_cel);
} }
} }
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_close(); undo->pushUndoer(new undoers::CloseGroup());
set_frame_to_handle(NULL, 0, NULL, 0); set_frame_to_handle(NULL, 0, NULL, 0);
} }
@ -164,10 +174,10 @@ void copy_cel(DocumentWriter& document)
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->setLabel("Move Cel"); undo->setLabel("Move Cel");
undo->setModification(undo::ModifyDocument); undo->setModification(undo::ModifyDocument);
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
undo->undo_set_layer(sprite); undo->pushUndoer(new undoers::SetCurrentLayer(undo->getObjects(), sprite));
undo->undo_set_frame(sprite); undo->pushUndoer(new undoers::SetCurrentFrame(undo->getObjects(), sprite));
} }
sprite->setCurrentLayer(dst_layer); sprite->setCurrentLayer(dst_layer);
@ -215,7 +225,8 @@ void copy_cel(DocumentWriter& document)
/* add the image in the stock */ /* add the image in the stock */
image_index = sprite->getStock()->addImage(dst_image); image_index = sprite->getStock()->addImage(dst_image);
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_image(sprite->getStock(), image_index); undo->pushUndoer(new undoers::AddImage(undo->getObjects(),
sprite->getStock(), image_index));
/* create the new cel */ /* create the new cel */
dst_cel = new Cel(dst_frame, image_index); dst_cel = new Cel(dst_frame, image_index);
@ -223,13 +234,13 @@ void copy_cel(DocumentWriter& document)
dst_cel->setOpacity(dst_cel_opacity); dst_cel->setOpacity(dst_cel_opacity);
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_cel(dst_layer, dst_cel); undo->pushUndoer(new undoers::AddCel(undo->getObjects(), dst_layer, dst_cel));
static_cast<LayerImage*>(dst_layer)->addCel(dst_cel); static_cast<LayerImage*>(dst_layer)->addCel(dst_cel);
} }
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_close(); undo->pushUndoer(new undoers::CloseGroup());
set_frame_to_handle(NULL, 0, NULL, 0); set_frame_to_handle(NULL, 0, NULL, 0);
} }
@ -254,23 +265,24 @@ static void remove_cel(Sprite* sprite, undo::UndoHistory* undo, LayerImage *laye
} }
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
if (!used) { if (!used) {
/* if the image is only used by this cel, we can remove the // If the image is only used by this cel, we can remove the
image from the stock */ // image from the stock.
image = sprite->getStock()->getImage(cel->getImage()); image = sprite->getStock()->getImage(cel->getImage());
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_remove_image(sprite->getStock(), cel->getImage()); undo->pushUndoer(new undoers::RemoveImage(undo->getObjects(),
sprite->getStock(), cel->getImage()));
sprite->getStock()->removeImage(image); sprite->getStock()->removeImage(image);
image_free(image); image_free(image);
} }
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->undo_remove_cel(layer, cel); undo->pushUndoer(new undoers::RemoveCel(undo->getObjects(), layer, cel));
undo->undo_close(); undo->pushUndoer(new undoers::CloseGroup());
} }
// Remove the cel // Remove the cel

View File

@ -40,6 +40,8 @@
#include "ui_context.h" #include "ui_context.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undo_transaction.h" #include "undo_transaction.h"
#include "undoers/add_image.h"
#include "undoers/image_area.h"
#include "util/clipboard.h" #include "util/clipboard.h"
#include "util/misc.h" #include "util/misc.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
@ -236,7 +238,8 @@ void clipboard::paste(DocumentWriter& document)
// Add the new image in the stock // Add the new image in the stock
int dst_image_index = sprite->getStock()->addImage(dst_image); int dst_image_index = sprite->getStock()->addImage(dst_image);
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_add_image(sprite->getStock(), dst_image_index); undo->pushUndoer(new undoers::AddImage(undo->getObjects(),
sprite->getStock(), dst_image_index));
// Create the new cel in the current frame with the recently // Create the new cel in the current frame with the recently
// created image // created image
@ -293,11 +296,12 @@ void clipboard::paste(DocumentWriter& document)
h = v2-v1+1; h = v2-v1+1;
if (w >= 1 && h >= 1) { if (w >= 1 && h >= 1) {
/* undo region */ // Add information to hold the modified region in the image.
if (undo->isEnabled()) if (undo->isEnabled())
undo->undo_image(dst_image, u1, v1, w, h); undo->pushUndoer(new undoers::ImageArea(undo->getObjects(),
dst_image, u1, v1, w, h));
/* draw the transformed image */ // Draw the transformed image.
image_parallelogram(dst_image, src_image, image_parallelogram(dst_image, src_image,
xout[0], yout[0], xout[1], yout[1], xout[0], yout[0], xout[1], yout[1],
xout[2], yout[2], xout[3], yout[3]); xout[2], yout[2], xout[3], yout[3]);

View File

@ -20,8 +20,7 @@
#include "config.h" #include "config.h"
#include <allegro.h> #include "widgets/editor/editor.h"
#include <stdio.h>
#include "app.h" #include "app.h"
#include "app/color.h" #include "app/color.h"
@ -41,15 +40,23 @@
#include "tools/tool.h" #include "tools/tool.h"
#include "ui_context.h" #include "ui_context.h"
#include "undo/undo_history.h" #include "undo/undo_history.h"
#include "undoers/add_cel.h"
#include "undoers/add_image.h"
#include "undoers/close_group.h"
#include "undoers/dirty_area.h"
#include "undoers/open_group.h"
#include "undoers/replace_image.h"
#include "undoers/set_cel_position.h" #include "undoers/set_cel_position.h"
#include "util/boundary.h" #include "util/boundary.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/render.h" #include "util/render.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "widgets/editor/editor.h"
#include "widgets/editor/pixels_movement.h" #include "widgets/editor/pixels_movement.h"
#include "widgets/statebar.h" #include "widgets/statebar.h"
#include <allegro.h>
#include <stdio.h>
#define has_shifts(msg,shift) \ #define has_shifts(msg,shift) \
(((msg)->any.shifts & (shift)) == (shift)) (((msg)->any.shifts & (shift)) == (shift))
@ -1935,10 +1942,12 @@ public:
// We create the undo information (for the new cel_image // We create the undo information (for the new cel_image
// in the stock and the new cel in the layer)... // in the stock and the new cel in the layer)...
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
undo->undo_add_image(m_sprite->getStock(), m_cel->getImage()); undo->pushUndoer(new undoers::AddImage(undo->getObjects(),
undo->undo_add_cel(m_sprite->getCurrentLayer(), m_cel); m_sprite->getStock(), m_cel->getImage()));
undo->undo_close(); undo->pushUndoer(new undoers::AddCel(undo->getObjects(),
m_sprite->getCurrentLayer(), m_cel));
undo->pushUndoer(new undoers::CloseGroup());
// And finally we add the cel again in the layer. // And finally we add the cel again in the layer.
static_cast<LayerImage*>(m_sprite->getCurrentLayer())->addCel(m_cel); static_cast<LayerImage*>(m_sprite->getCurrentLayer())->addCel(m_cel);
@ -1952,7 +1961,8 @@ public:
dirty->saveImagePixels(m_cel_image); dirty->saveImagePixels(m_cel_image);
if (dirty != NULL) if (dirty != NULL)
undo->undo_dirty(m_cel_image, dirty); undo->pushUndoer(new undoers::DirtyArea(undo->getObjects(),
m_cel_image, dirty));
delete dirty; delete dirty;
} }
@ -1965,7 +1975,7 @@ public:
// replace the entire image. // replace the entire image.
else { else {
if (undo->isEnabled()) { if (undo->isEnabled()) {
undo->undo_open(); undo->pushUndoer(new undoers::OpenGroup());
if (m_cel->getX() != m_old_cel_x || if (m_cel->getX() != m_old_cel_x ||
m_cel->getY() != m_old_cel_y) { m_cel->getY() != m_old_cel_y) {
@ -1978,8 +1988,9 @@ public:
m_cel->setPosition(x, y); m_cel->setPosition(x, y);
} }
undo->undo_replace_image(m_sprite->getStock(), m_cel->getImage()); undo->pushUndoer(new undoers::ReplaceImage(undo->getObjects(),
undo->undo_close(); m_sprite->getStock(), m_cel->getImage()));
undo->pushUndoer(new undoers::CloseGroup());
} }
// Replace the image in the stock. // Replace the image in the stock.