Rename Undoable to UndoTransaction.

This commit is contained in:
David Capello 2011-03-22 21:22:13 -03:00
parent 6e60d3200d
commit f08d049ab6
24 changed files with 248 additions and 260 deletions

View File

@ -83,7 +83,7 @@ add_library(aseprite-library
recent_files.cpp
resource_finder.cpp
ui_context.cpp
undoable.cpp
undo_transaction.cpp
xml_exception.cpp
xml_widgets.cpp
app/color.cpp

View File

@ -18,14 +18,14 @@
#include "config.h"
#include "app/color_utils.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "modules/gui.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/color_bar.h"
#include "app/color_utils.h"
class BackgroundFromLayerCommand : public Command
{
@ -69,9 +69,9 @@ void BackgroundFromLayerCommand::onExecute(Context* context)
bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor);
{
Undoable undoable(document, "Background from Layer");
undoable.backgroundFromLayer(static_cast<LayerImage*>(sprite->getCurrentLayer()), bgcolor);
undoable.commit();
UndoTransaction undo_transaction(document, "Background from Layer");
undo_transaction.backgroundFromLayer(static_cast<LayerImage*>(sprite->getCurrentLayer()), bgcolor);
undo_transaction.commit();
}
update_screen_for_document(document);
}

View File

@ -18,19 +18,18 @@
#include "config.h"
#include <allegro/unicode.h>
#include "gui/gui.h"
#include "app/color_utils.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/gui.h"
#include "raster/image.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/color_bar.h"
#include "app/color_utils.h"
#include <allegro/unicode.h>
class CanvasSizeCommand : public Command
{
@ -110,12 +109,12 @@ void CanvasSizeCommand::onExecute(Context* context)
if (y2 <= y1) y2 = y1+1;
{
Undoable undoable(document, "Canvas Size");
UndoTransaction undoTransaction(document, "Canvas Size");
int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType());
bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor);
undoable.cropSprite(x1, y1, x2-x1, y2-y1, bgcolor);
undoable.commit();
undoTransaction.cropSprite(x1, y1, x2-x1, y2-y1, bgcolor);
undoTransaction.commit();
}
document->generateMaskBoundaries();
update_screen_for_document(document);

View File

@ -18,17 +18,17 @@
#include "config.h"
#include <allegro/unicode.h>
#include "app.h"
#include "commands/command.h"
#include "commands/params.h"
#include "app.h"
#include "document_wrappers.h"
#include "modules/gui.h"
#include "modules/palettes.h"
#include "raster/image.h"
#include "raster/sprite.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
#include <allegro/unicode.h>
class ChangeImageTypeCommand : public Command
{
@ -103,9 +103,9 @@ void ChangeImageTypeCommand::onExecute(Context* context)
{
ActiveDocumentWriter document(context);
{
Undoable undoable(document, "Color Mode Change");
undoable.setImgType(m_imgtype, m_dithering);
undoable.commit();
UndoTransaction undoTransaction(document, "Color Mode Change");
undoTransaction.setImgType(m_imgtype, m_dithering);
undoTransaction.commit();
}
app_refresh_screen(document);
}

View File

@ -20,13 +20,13 @@
#include "app.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "modules/gui.h"
#include "raster/layer.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "raster/undo_history.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/color_bar.h"
//////////////////////////////////////////////////////////////////////
@ -68,11 +68,11 @@ void ClearCommand::onExecute(Context* context)
Sprite* sprite(document->getSprite());
bool empty_mask = sprite->getMask()->is_empty();
{
Undoable undoable(document, "Clear");
undoable.clearMask(app_get_color_to_clear_layer(sprite->getCurrentLayer()));
UndoTransaction undoTransaction(document, "Clear");
undoTransaction.clearMask(app_get_color_to_clear_layer(sprite->getCurrentLayer()));
if (!empty_mask)
undoable.deselectMask();
undoable.commit();
undoTransaction.deselectMask();
undoTransaction.commit();
}
if (!empty_mask)
document->generateMaskBoundaries();

View File

@ -18,19 +18,19 @@
#include "config.h"
#include "commands/command.h"
#include "app.h"
#include "app/color_utils.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "modules/gui.h"
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "widgets/color_bar.h"
#include "undo_transaction.h"
#include "util/autocrop.h"
#include "util/misc.h"
#include "document_wrappers.h"
#include "app/color_utils.h"
#include "widgets/color_bar.h"
//////////////////////////////////////////////////////////////////////
// crop_sprite
@ -68,15 +68,15 @@ void CropSpriteCommand::onExecute(Context* context)
ActiveDocumentWriter document(context);
Sprite* sprite(document->getSprite());
{
Undoable undoable(document, "Sprite Crop");
UndoTransaction undoTransaction(document, "Sprite Crop");
int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType());
undoable.cropSprite(sprite->getMask()->x,
sprite->getMask()->y,
sprite->getMask()->w,
sprite->getMask()->h,
bgcolor);
undoable.commit();
undoTransaction.cropSprite(sprite->getMask()->x,
sprite->getMask()->y,
sprite->getMask()->w,
sprite->getMask()->h,
bgcolor);
undoTransaction.commit();
}
document->generateMaskBoundaries();
update_screen_for_document(document);
@ -117,9 +117,9 @@ void AutocropSpriteCommand::onExecute(Context* context)
{
int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType());
Undoable undoable(document, "Sprite Autocrop");
undoable.autocropSprite(bgcolor);
undoable.commit();
UndoTransaction undoTransaction(document, "Sprite Autocrop");
undoTransaction.autocropSprite(bgcolor);
undoTransaction.commit();
}
document->generateMaskBoundaries();
update_screen_for_document(document);

View File

@ -19,11 +19,11 @@
#include "config.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "modules/gui.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
//////////////////////////////////////////////////////////////////////
// deselect_mask
@ -57,9 +57,9 @@ void DeselectMaskCommand::onExecute(Context* context)
{
ActiveDocumentWriter document(context);
{
Undoable undoable(document, "Mask Deselection");
undoable.deselectMask();
undoable.commit();
UndoTransaction undoTransaction(document, "Mask Deselection");
undoTransaction.deselectMask();
undoTransaction.commit();
}
document->generateMaskBoundaries();
update_screen_for_document(document);

View File

@ -63,7 +63,7 @@ void DuplicateLayerCommand::onExecute(Context* context)
ActiveDocumentWriter document(context);
Sprite* sprite = document->getSprite();
UndoHistory* undo = document->getUndoHistory();
Undoable undoable(document, "Layer Duplication");
UndoTransaction undoTransaction(document, "Layer Duplication");
// Clone the layer
UniquePtr<Layer> newLayerPtr(sprite->getCurrentLayer()->clone());
@ -85,7 +85,7 @@ void DuplicateLayerCommand::onExecute(Context* context)
undo->undo_set_layer(sprite);
}
undoable.commit();
undoTransaction.commit();
sprite->getCurrentLayer()->get_parent()->move_layer(newLayer, sprite->getCurrentLayer());
sprite->setCurrentLayer(newLayer);

View File

@ -18,14 +18,14 @@
#include "config.h"
#include "commands/command.h"
#include "app.h"
#include "app/color_utils.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "modules/gui.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/color_bar.h"
#include "document_wrappers.h"
#include "app/color_utils.h"
//////////////////////////////////////////////////////////////////////
// flatten_layers
@ -60,9 +60,9 @@ void FlattenLayersCommand::onExecute(Context* context)
Sprite* sprite = document->getSprite();
int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType());
{
Undoable undoable(document, "Flatten Layers");
undoable.flattenLayers(bgcolor);
undoable.commit();
UndoTransaction undoTransaction(document, "Flatten Layers");
undoTransaction.flattenLayers(bgcolor);
undoTransaction.commit();
}
update_screen_for_document(document);
}

View File

@ -18,10 +18,9 @@
#include "config.h"
#include <allegro/unicode.h>
#include "commands/command.h"
#include "commands/params.h"
#include "document_wrappers.h"
#include "gui/list.h"
#include "modules/editors.h"
#include "modules/gui.h"
@ -31,10 +30,11 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "raster/undo_history.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "util/misc.h"
#include <allegro/unicode.h>
class FlipCommand : public Command
{
bool m_flip_mask;
@ -86,12 +86,12 @@ void FlipCommand::onExecute(Context* context)
Sprite* sprite = document->getSprite();
{
Undoable undoable(document,
m_flip_mask ?
(m_flip_horizontal ? "Flip Horizontal":
"Flip Vertical"):
(m_flip_horizontal ? "Flip Canvas Horizontal":
"Flip Canvas Vertical"));
UndoTransaction undoTransaction(document,
m_flip_mask ?
(m_flip_horizontal ? "Flip Horizontal":
"Flip Vertical"):
(m_flip_horizontal ? "Flip Canvas Horizontal":
"Flip Canvas Vertical"));
if (m_flip_mask) {
Image* image;
@ -123,8 +123,8 @@ void FlipCommand::onExecute(Context* context)
y2 = MID(0, y2, image->h-1);
}
undoable.flipImage(image, x1, y1, x2, y2,
m_flip_horizontal, m_flip_vertical);
undoTransaction.flipImage(image, x1, y1, x2, y2,
m_flip_horizontal, m_flip_vertical);
}
else {
// get all sprite cels
@ -136,16 +136,17 @@ void FlipCommand::onExecute(Context* context)
Cel* cel = *it;
Image* image = sprite->getStock()->getImage(cel->image);
undoable.setCelPosition(cel,
m_flip_horizontal ? sprite->getWidth() - image->w - cel->x: cel->x,
m_flip_vertical ? sprite->getHeight() - image->h - cel->y: cel->y);
undoTransaction.setCelPosition
(cel,
m_flip_horizontal ? sprite->getWidth() - image->w - cel->x: cel->x,
m_flip_vertical ? sprite->getHeight() - image->h - cel->y: cel->y);
undoable.flipImage(image, 0, 0, image->w-1, image->h-1,
m_flip_horizontal, m_flip_vertical);
undoTransaction.flipImage(image, 0, 0, image->w-1, image->h-1,
m_flip_horizontal, m_flip_vertical);
}
}
undoable.commit();
undoTransaction.commit();
}
update_screen_for_document(document);

View File

@ -18,15 +18,14 @@
#include "config.h"
#include "gui/gui.h"
#include "base/convert_to.h"
#include "commands/command.h"
#include "commands/params.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/gui.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "document_wrappers.h"
#include "undo_transaction.h"
//////////////////////////////////////////////////////////////////////
// frame_properties
@ -123,16 +122,16 @@ void FramePropertiesCommand::onExecute(Context* context)
"<<Do you want to change the duration of all frames?"
"||&Yes||&No") == 1) {
DocumentWriter document_writer(document);
Undoable undoable(document_writer, "Constant Frame-Rate");
undoable.setConstantFrameRate(num);
undoable.commit();
UndoTransaction undoTransaction(document_writer, "Constant Frame-Rate");
undoTransaction.setConstantFrameRate(num);
undoTransaction.commit();
}
}
else {
DocumentWriter document_writer(document);
Undoable undoable(document_writer, "Frame Duration");
undoable.setFrameDuration(sprite_frame-1, num);
undoable.commit();
UndoTransaction undoTransaction(document_writer, "Frame Duration");
undoTransaction.setFrameDuration(sprite_frame-1, num);
undoTransaction.commit();
}
}
}

View File

@ -18,14 +18,13 @@
#include "config.h"
#include "gui/gui.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/gui.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "document_wrappers.h"
#include "undo_transaction.h"
//////////////////////////////////////////////////////////////////////
// layer_from_background
@ -65,9 +64,9 @@ void LayerFromBackgroundCommand::onExecute(Context* context)
{
ActiveDocumentWriter document(context);
{
Undoable undoable(document, "Layer from Background");
undoable.layerFromBackground();
undoable.commit();
UndoTransaction undoTransaction(document, "Layer from Background");
undoTransaction.layerFromBackground();
undoTransaction.commit();
}
update_screen_for_document(document);
}

View File

@ -18,20 +18,19 @@
#include "config.h"
#include "gui/gui.h"
#include "app.h"
#include "app/color.h"
#include "commands/command.h"
#include "console.h"
#include "app/color.h"
#include "app.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/gui.h"
#include "raster/cel.h"
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/statebar.h"
#include "document_wrappers.h"
#include <stdexcept>
@ -73,9 +72,9 @@ void NewFrameCommand::onExecute(Context* context)
ActiveDocumentWriter document(context);
Sprite* sprite(document->getSprite());
{
Undoable undoable(document, "New Frame");
undoable.newFrame();
undoable.commit();
UndoTransaction undoTransaction(document, "New Frame");
undoTransaction.newFrame();
undoTransaction.commit();
}
update_screen_for_document(document);
app_get_statusbar()

View File

@ -18,16 +18,15 @@
#include "config.h"
#include "gui/gui.h"
#include "app.h"
#include "commands/command.h"
#include "commands/params.h"
#include "app.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/gui.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "document_wrappers.h"
#include "undo_transaction.h"
#include "widgets/statebar.h"
//////////////////////////////////////////////////////////////////////
@ -106,9 +105,9 @@ void NewLayerCommand::onExecute(Context* context)
Layer* layer;
{
Undoable undoable(document, "New Layer");
layer = undoable.newLayer();
undoable.commit();
UndoTransaction undoTransaction(document, "New Layer");
layer = undoTransaction.newLayer();
undoTransaction.commit();
}
layer->setName(name);
update_screen_for_document(document);

View File

@ -23,7 +23,7 @@
#include "raster/cel.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "document_wrappers.h"
//////////////////////////////////////////////////////////////////////
@ -66,9 +66,9 @@ void RemoveCelCommand::onExecute(Context* context)
Sprite* sprite(document->getSprite());
Cel* cel = static_cast<LayerImage*>(sprite->getCurrentLayer())->getCel(sprite->getCurrentFrame());
{
Undoable undoable(document, "Remove Cel");
undoable.removeCel(static_cast<LayerImage*>(sprite->getCurrentLayer()), cel);
undoable.commit();
UndoTransaction undoTransaction(document, "Remove Cel");
undoTransaction.removeCel(static_cast<LayerImage*>(sprite->getCurrentLayer()), cel);
undoTransaction.commit();
}
update_screen_for_document(document);
}

View File

@ -18,13 +18,12 @@
#include "config.h"
#include "gui/gui.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/gui.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "document_wrappers.h"
#include "undo_transaction.h"
//////////////////////////////////////////////////////////////////////
// remove_frame
@ -61,9 +60,9 @@ void RemoveFrameCommand::onExecute(Context* context)
ActiveDocumentWriter document(context);
const Sprite* sprite(document->getSprite());
{
Undoable undoable(document, "Remove Frame");
undoable.removeFrame(sprite->getCurrentFrame());
undoable.commit();
UndoTransaction undoTransaction(document, "Remove Frame");
undoTransaction.removeFrame(sprite->getCurrentFrame());
undoTransaction.commit();
}
update_screen_for_document(document);
}

View File

@ -18,15 +18,14 @@
#include "config.h"
#include "gui/widget.h"
#include "app.h"
#include "commands/command.h"
#include "document_wrappers.h"
#include "gui/widget.h"
#include "modules/gui.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "document_wrappers.h"
#include "undo_transaction.h"
#include "widgets/statebar.h"
//////////////////////////////////////////////////////////////////////
@ -65,12 +64,12 @@ void RemoveLayerCommand::onExecute(Context* context)
ActiveDocumentWriter document(context);
Sprite* sprite(document->getSprite());
{
Undoable undoable(document, "Remove Layer");
UndoTransaction undoTransaction(document, "Remove Layer");
layer_name = sprite->getCurrentLayer()->getName();
undoable.removeLayer(sprite->getCurrentLayer());
undoable.commit();
undoTransaction.removeLayer(sprite->getCurrentLayer());
undoTransaction.commit();
}
update_screen_for_document(document);

View File

@ -18,13 +18,11 @@
#include "config.h"
#include <allegro/unicode.h>
#include "gui/gui.h"
#include "app.h"
#include "commands/command.h"
#include "commands/params.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "job.h"
#include "modules/gui.h"
#include "raster/cel.h"
@ -32,10 +30,11 @@
#include "raster/mask.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "document_wrappers.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/color_bar.h"
#include <allegro/unicode.h>
//////////////////////////////////////////////////////////////////////
// rotate_canvas
@ -76,7 +75,7 @@ protected:
*/
virtual void onJob()
{
Undoable undoable(m_document, "Rotate Canvas");
UndoTransaction undoTransaction(m_document, "Rotate Canvas");
// get all sprite cels
CelList cels;
@ -90,15 +89,15 @@ protected:
// change it location
switch (m_angle) {
case 180:
undoable.setCelPosition(cel,
m_sprite->getWidth() - cel->x - image->w,
m_sprite->getHeight() - cel->y - image->h);
undoTransaction.setCelPosition(cel,
m_sprite->getWidth() - cel->x - image->w,
m_sprite->getHeight() - cel->y - image->h);
break;
case 90:
undoable.setCelPosition(cel, m_sprite->getHeight() - cel->y - image->h, cel->x);
undoTransaction.setCelPosition(cel, m_sprite->getHeight() - cel->y - image->h, cel->x);
break;
case -90:
undoable.setCelPosition(cel, cel->y, m_sprite->getWidth() - cel->x - image->w);
undoTransaction.setCelPosition(cel, cel->y, m_sprite->getWidth() - cel->x - image->w);
break;
}
}
@ -115,13 +114,13 @@ protected:
m_angle == 180 ? image->h: image->w);
image_rotate(image, new_image, m_angle);
undoable.replaceStockImage(i, new_image);
undoTransaction.replaceStockImage(i, new_image);
jobProgress((float)i / m_sprite->getStock()->size());
// cancel all the operation?
if (isCanceled())
return; // Undoable destructor will undo all operations
return; // UndoTransaction destructor will undo all operations
}
// rotate mask
@ -151,7 +150,7 @@ protected:
image_rotate(m_sprite->getMask()->bitmap, new_mask->bitmap, m_angle);
// copy new mask
undoable.copyToCurrentMask(new_mask);
undoTransaction.copyToCurrentMask(new_mask);
mask_free(new_mask);
// regenerate mask
@ -160,10 +159,10 @@ protected:
// change the sprite's size
if (m_angle != 180)
undoable.setSpriteSize(m_sprite->getHeight(), m_sprite->getWidth());
undoTransaction.setSpriteSize(m_sprite->getHeight(), m_sprite->getWidth());
// commit changes
undoable.commit();
undoTransaction.commit();
}
};

View File

@ -18,13 +18,11 @@
#include "config.h"
#include <allegro/unicode.h>
#include "base/bind.h"
#include "gui/gui.h"
#include "commands/command.h"
#include "core/cfg.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "job.h"
#include "modules/gui.h"
#include "modules/palettes.h"
@ -33,9 +31,10 @@
#include "raster/mask.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "document_wrappers.h"
#include "ui_context.h"
#include "undoable.h"
#include "undo_transaction.h"
#include <allegro/unicode.h>
#define PERC_FORMAT "%.1f%%"
@ -69,7 +68,7 @@ protected:
*/
virtual void onJob()
{
Undoable undoable(m_document, "Sprite Size");
UndoTransaction undoTransaction(m_document, "Sprite Size");
// Get all sprite cels
CelList cels;
@ -81,7 +80,7 @@ protected:
Cel* cel = *it;
// Change its location
undoable.setCelPosition(cel, scale_x(cel->x), scale_y(cel->y));
undoTransaction.setCelPosition(cel, scale_x(cel->x), scale_y(cel->y));
// Get cel's image
Image* image = m_sprite->getStock()->getImage(cel->image);
@ -99,13 +98,13 @@ protected:
m_sprite->getPalette(cel->frame),
m_sprite->getRgbMap(cel->frame));
undoable.replaceStockImage(cel->image, new_image);
undoTransaction.replaceStockImage(cel->image, new_image);
jobProgress((float)progress / cels.size());
// cancel all the operation?
if (isCanceled())
return; // Undoable destructor will undo all operations
return; // UndoTransaction destructor will undo all operations
}
// resize mask
@ -132,7 +131,7 @@ protected:
new_mask->w, new_mask->h);
// copy new mask
undoable.copyToCurrentMask(new_mask);
undoTransaction.copyToCurrentMask(new_mask);
mask_free(new_mask);
// regenerate mask
@ -140,10 +139,10 @@ protected:
}
// resize sprite
undoable.setSpriteSize(m_new_width, m_new_height);
undoTransaction.setSpriteSize(m_new_width, m_new_height);
// commit changes
undoable.commit();
undoTransaction.commit();
}
};

View File

@ -34,7 +34,7 @@
#include "raster/raster.h"
#include "skin/skin_theme.h"
#include "ui_context.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "util/celmove.h"
#include "util/thmbnail.h"
@ -561,9 +561,9 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
anieditor->hot_frame != anieditor->clk_frame+1) {
{
DocumentWriter document_writer(document);
Undoable undoable(document_writer, "Move Frame");
undoable.moveFrameBefore(anieditor->clk_frame, anieditor->hot_frame);
undoable.commit();
UndoTransaction undoTransaction(document_writer, "Move Frame");
undoTransaction.moveFrameBefore(anieditor->clk_frame, anieditor->hot_frame);
undoTransaction.commit();
}
widget->invalidate();
}
@ -597,10 +597,10 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
DocumentWriter document_writer(document);
Sprite* sprite_writer = const_cast<Sprite*>(anieditor->sprite);
Undoable undoable(document_writer, "Move Layer");
undoable.moveLayerAfter(anieditor->layers[anieditor->clk_layer],
anieditor->layers[anieditor->hot_layer]);
undoable.commit();
UndoTransaction undoTransaction(document_writer, "Move Layer");
undoTransaction.moveLayerAfter(anieditor->layers[anieditor->clk_layer],
anieditor->layers[anieditor->hot_layer]);
undoTransaction.commit();
/* select the new layer */
sprite_writer->setCurrentLayer(anieditor->layers[anieditor->clk_layer]);

View File

@ -18,7 +18,7 @@
#include "config.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "base/unique_ptr.h"
#include "document_wrappers.h"
@ -35,13 +35,7 @@
#include "raster/stock.h"
#include "raster/undo_history.h"
/**
* Starts a undoable sequence of operations.
*
* All the operations will be grouped in the sprite's undo as an
* atomic operation.
*/
Undoable::Undoable(DocumentWriter& document, const char* label)
UndoTransaction::UndoTransaction(DocumentWriter& document, const char* label)
{
ASSERT(label != NULL);
@ -57,37 +51,30 @@ Undoable::Undoable(DocumentWriter& document, const char* label)
}
}
Undoable::~Undoable()
UndoTransaction::~UndoTransaction()
{
if (isEnabled()) {
// close the undo information
// Close the undo information.
m_undoHistory->undo_close();
// if it isn't committed, we have to rollback all changes
// If it isn't committed, we have to rollback all changes.
if (!m_committed) {
// undo the group of operations
// Undo the group of operations.
m_undoHistory->doUndo();
// clear the redo (sorry to the user, here we lost the old redo
// information)
// Clear the redo (sorry to the user, here we lost the old redo
// information).
m_undoHistory->clearRedo();
}
}
}
/**
* This must be called to commit all the changes, so the undo will be
* finally added in the sprite.
*
* If you don't use this routine, all the changes will be discarded
* (if the sprite's undo was enabled when the Undoable was created).
*/
void Undoable::commit()
void UndoTransaction::commit()
{
m_committed = true;
}
void Undoable::setNumberOfFrames(int frames)
void UndoTransaction::setNumberOfFrames(int frames)
{
ASSERT(frames >= 1);
@ -99,7 +86,7 @@ void Undoable::setNumberOfFrames(int frames)
m_sprite->setTotalFrames(frames);
}
void Undoable::setCurrentFrame(int frame)
void UndoTransaction::setCurrentFrame(int frame)
{
ASSERT(frame >= 0);
@ -115,7 +102,7 @@ void Undoable::setCurrentFrame(int frame)
* @param layer
* The layer to select. Can be NULL.
*/
void Undoable::setCurrentLayer(Layer* layer)
void UndoTransaction::setCurrentLayer(Layer* layer)
{
if (isEnabled())
m_undoHistory->undo_set_layer(m_sprite);
@ -123,7 +110,7 @@ void Undoable::setCurrentLayer(Layer* layer)
m_sprite->setCurrentLayer(layer);
}
void Undoable::setSpriteSize(int w, int h)
void UndoTransaction::setSpriteSize(int w, int h)
{
ASSERT(w > 0);
ASSERT(h > 0);
@ -134,7 +121,7 @@ void Undoable::setSpriteSize(int w, int h)
m_sprite->setSize(w, h);
}
void Undoable::cropSprite(int x, int y, int w, int h, int bgcolor)
void UndoTransaction::cropSprite(int x, int y, int w, int h, int bgcolor)
{
setSpriteSize(w, h);
@ -148,7 +135,7 @@ void Undoable::cropSprite(int x, int y, int w, int h, int bgcolor)
setMaskPosition(m_sprite->getMask()->x-x, m_sprite->getMask()->y-y);
}
void Undoable::autocropSprite(int bgcolor)
void UndoTransaction::autocropSprite(int bgcolor)
{
int old_frame = m_sprite->getCurrentFrame();
int x1, y1, x2, y2;
@ -188,7 +175,7 @@ void Undoable::autocropSprite(int bgcolor)
cropSprite(x1, y1, x2-x1+1, y2-y1+1, bgcolor);
}
void Undoable::setImgType(int new_imgtype, DitheringMethod dithering_method)
void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_method)
{
Image *old_image;
Image *new_image;
@ -252,7 +239,7 @@ void Undoable::setImgType(int new_imgtype, DitheringMethod dithering_method)
* @return
* The image index in the stock.
*/
int Undoable::addImageInStock(Image* image)
int UndoTransaction::addImageInStock(Image* image)
{
ASSERT(image);
@ -268,7 +255,7 @@ int Undoable::addImageInStock(Image* image)
/**
* Removes and destroys the specified image in the stock.
*/
void Undoable::removeImageFromStock(int image_index)
void UndoTransaction::removeImageFromStock(int image_index)
{
ASSERT(image_index >= 0);
@ -282,7 +269,7 @@ void Undoable::removeImageFromStock(int image_index)
image_free(image);
}
void Undoable::replaceStockImage(int image_index, Image* new_image)
void UndoTransaction::replaceStockImage(int image_index, Image* new_image)
{
// get the current image in the 'image_index' position
Image* old_image = m_sprite->getStock()->getImage(image_index);
@ -301,7 +288,7 @@ void Undoable::replaceStockImage(int image_index, Image* new_image)
/**
* Creates a new transparent layer.
*/
Layer* Undoable::newLayer()
Layer* UndoTransaction::newLayer()
{
// new layer
LayerImage* layer = new LayerImage(m_sprite);
@ -321,7 +308,7 @@ Layer* Undoable::newLayer()
/**
* Removes and destroys the specified layer.
*/
void Undoable::removeLayer(Layer* layer)
void UndoTransaction::removeLayer(Layer* layer)
{
ASSERT(layer);
@ -354,7 +341,7 @@ void Undoable::removeLayer(Layer* layer)
delete layer;
}
void Undoable::moveLayerAfter(Layer* layer, Layer* after_this)
void UndoTransaction::moveLayerAfter(Layer* layer, Layer* after_this)
{
if (isEnabled())
m_undoHistory->undo_move_layer(layer);
@ -362,7 +349,7 @@ void Undoable::moveLayerAfter(Layer* layer, Layer* after_this)
layer->get_parent()->move_layer(layer, after_this);
}
void Undoable::cropLayer(Layer* layer, int x, int y, int w, int h, int bgcolor)
void UndoTransaction::cropLayer(Layer* layer, int x, int y, int w, int h, int bgcolor)
{
if (!layer->is_image())
return;
@ -379,7 +366,7 @@ void Undoable::cropLayer(Layer* layer, int x, int y, int w, int h, int bgcolor)
/**
* Moves every frame in @a layer with the offset (@a dx, @a dy).
*/
void Undoable::displaceLayers(Layer* layer, int dx, int dy)
void UndoTransaction::displaceLayers(Layer* layer, int dx, int dy)
{
switch (layer->getType()) {
@ -404,7 +391,7 @@ void Undoable::displaceLayers(Layer* layer, int dx, int dy)
}
}
void Undoable::backgroundFromLayer(LayerImage* layer, int bgcolor)
void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor)
{
ASSERT(layer);
ASSERT(layer->is_image());
@ -474,7 +461,7 @@ void Undoable::backgroundFromLayer(LayerImage* layer, int bgcolor)
configureLayerAsBackground(layer);
}
void Undoable::layerFromBackground()
void UndoTransaction::layerFromBackground()
{
ASSERT(m_sprite->getBackgroundLayer() != NULL);
ASSERT(m_sprite->getCurrentLayer() != NULL);
@ -497,7 +484,7 @@ void Undoable::layerFromBackground()
m_sprite->getCurrentLayer()->setName("Layer 0");
}
void Undoable::flattenLayers(int bgcolor)
void UndoTransaction::flattenLayers(int bgcolor)
{
Image* cel_image;
Cel* cel;
@ -591,7 +578,7 @@ void Undoable::flattenLayers(int bgcolor)
}
}
void Undoable::configureLayerAsBackground(LayerImage* layer)
void UndoTransaction::configureLayerAsBackground(LayerImage* layer)
{
if (isEnabled()) {
m_undoHistory->undo_data(layer, layer->flags_addr(), sizeof(*layer->flags_addr()));
@ -602,7 +589,7 @@ void Undoable::configureLayerAsBackground(LayerImage* layer)
layer->configureAsBackground();
}
void Undoable::newFrame()
void UndoTransaction::newFrame()
{
// add a new cel to every layer
newFrameForLayer(m_sprite->getFolder(),
@ -615,7 +602,7 @@ void Undoable::newFrame()
setCurrentFrame(m_sprite->getCurrentFrame()+1);
}
void Undoable::newFrameForLayer(Layer* layer, int frame)
void UndoTransaction::newFrameForLayer(Layer* layer, int frame)
{
ASSERT(layer);
ASSERT(frame >= 0);
@ -645,7 +632,7 @@ void Undoable::newFrameForLayer(Layer* layer, int frame)
}
}
void Undoable::removeFrame(int frame)
void UndoTransaction::removeFrame(int frame)
{
ASSERT(frame >= 0);
@ -664,7 +651,7 @@ void Undoable::removeFrame(int frame)
setNumberOfFrames(newTotalFrames);
}
void Undoable::removeFrameOfLayer(Layer* layer, int frame)
void UndoTransaction::removeFrameOfLayer(Layer* layer, int frame)
{
ASSERT(layer);
ASSERT(frame >= 0);
@ -695,7 +682,7 @@ void Undoable::removeFrameOfLayer(Layer* layer, int frame)
/**
* Copies the previous cel of @a frame to @frame.
*/
void Undoable::copyPreviousFrame(Layer* layer, int frame)
void UndoTransaction::copyPreviousFrame(Layer* layer, int frame)
{
ASSERT(layer);
ASSERT(frame > 0);
@ -724,7 +711,7 @@ void Undoable::copyPreviousFrame(Layer* layer, int frame)
addCel(static_cast<LayerImage*>(layer), dst_cel);
}
void Undoable::addCel(LayerImage* layer, Cel* cel)
void UndoTransaction::addCel(LayerImage* layer, Cel* cel)
{
ASSERT(layer);
ASSERT(cel);
@ -735,7 +722,7 @@ void Undoable::addCel(LayerImage* layer, Cel* cel)
layer->addCel(cel);
}
void Undoable::removeCel(LayerImage* layer, Cel* cel)
void UndoTransaction::removeCel(LayerImage* layer, Cel* cel)
{
ASSERT(layer);
ASSERT(cel);
@ -766,7 +753,7 @@ void Undoable::removeCel(LayerImage* layer, Cel* cel)
cel_free(cel);
}
void Undoable::setCelFramePosition(Cel* cel, int frame)
void UndoTransaction::setCelFramePosition(Cel* cel, int frame)
{
ASSERT(cel);
ASSERT(frame >= 0);
@ -777,7 +764,7 @@ void Undoable::setCelFramePosition(Cel* cel, int frame)
cel->frame = frame;
}
void Undoable::setCelPosition(Cel* cel, int x, int y)
void UndoTransaction::setCelPosition(Cel* cel, int x, int y)
{
ASSERT(cel);
@ -790,7 +777,7 @@ void Undoable::setCelPosition(Cel* cel, int x, int y)
cel->y = y;
}
void Undoable::setFrameDuration(int frame, int msecs)
void UndoTransaction::setFrameDuration(int frame, int msecs)
{
if (isEnabled())
m_undoHistory->undo_set_frlen(m_sprite, frame);
@ -798,7 +785,7 @@ void Undoable::setFrameDuration(int frame, int msecs)
m_sprite->setFrameDuration(frame, msecs);
}
void Undoable::setConstantFrameRate(int msecs)
void UndoTransaction::setConstantFrameRate(int msecs)
{
if (isEnabled()) {
for (int fr=0; fr<m_sprite->getTotalFrames(); ++fr)
@ -808,7 +795,7 @@ void Undoable::setConstantFrameRate(int msecs)
m_sprite->setDurationForAllFrames(msecs);
}
void Undoable::moveFrameBefore(int frame, int before_frame)
void UndoTransaction::moveFrameBefore(int frame, int before_frame)
{
if (frame != before_frame &&
frame >= 0 &&
@ -839,7 +826,7 @@ void Undoable::moveFrameBefore(int frame, int before_frame)
}
}
void Undoable::moveFrameBeforeLayer(Layer* layer, int frame, int before_frame)
void UndoTransaction::moveFrameBeforeLayer(Layer* layer, int frame, int before_frame)
{
ASSERT(layer);
@ -892,7 +879,7 @@ void Undoable::moveFrameBeforeLayer(Layer* layer, int frame, int before_frame)
}
}
Cel* Undoable::getCurrentCel()
Cel* UndoTransaction::getCurrentCel()
{
if (m_sprite->getCurrentLayer() && m_sprite->getCurrentLayer()->is_image())
return static_cast<LayerImage*>(m_sprite->getCurrentLayer())->getCel(m_sprite->getCurrentFrame());
@ -900,7 +887,7 @@ Cel* Undoable::getCurrentCel()
return NULL;
}
void Undoable::cropCel(Cel* cel, int x, int y, int w, int h, int bgcolor)
void UndoTransaction::cropCel(Cel* cel, int x, int y, int w, int h, int bgcolor)
{
Image* cel_image = m_sprite->getStock()->getImage(cel->image);
ASSERT(cel_image);
@ -915,7 +902,7 @@ void Undoable::cropCel(Cel* cel, int x, int y, int w, int h, int bgcolor)
setCelPosition(cel, x, y);
}
Image* Undoable::getCelImage(Cel* cel)
Image* UndoTransaction::getCelImage(Cel* cel)
{
if (cel && cel->image >= 0 && cel->image < m_sprite->getStock()->size())
return m_sprite->getStock()->getImage(cel->image);
@ -924,7 +911,7 @@ Image* Undoable::getCelImage(Cel* cel)
}
// clears the mask region in the current sprite with the specified background color
void Undoable::clearMask(int bgcolor)
void UndoTransaction::clearMask(int bgcolor)
{
Cel* cel = getCurrentCel();
if (!cel)
@ -985,7 +972,7 @@ void Undoable::clearMask(int bgcolor)
}
}
void Undoable::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)
{
// insert the undo operation
@ -1011,7 +998,7 @@ void Undoable::flipImage(Image* image, int x1, int y1, int x2, int y2,
image_free(area);
}
void Undoable::pasteImage(const Image* src_image, int x, int y, int opacity)
void UndoTransaction::pasteImage(const Image* src_image, int x, int y, int opacity)
{
const Layer* layer = m_sprite->getCurrentLayer();
@ -1030,7 +1017,7 @@ void Undoable::pasteImage(const Image* src_image, int x, int y, int opacity)
replaceStockImage(cel->image, cel_image2); // TODO fix this, improve, avoid replacing the whole image
}
void Undoable::copyToCurrentMask(Mask* mask)
void UndoTransaction::copyToCurrentMask(Mask* mask)
{
ASSERT(m_sprite->getMask());
ASSERT(mask);
@ -1041,7 +1028,7 @@ void Undoable::copyToCurrentMask(Mask* mask)
mask_copy(m_sprite->getMask(), mask);
}
void Undoable::setMaskPosition(int x, int y)
void UndoTransaction::setMaskPosition(int x, int y)
{
ASSERT(m_sprite->getMask());
@ -1054,7 +1041,7 @@ void Undoable::setMaskPosition(int x, int y)
m_sprite->getMask()->y = y;
}
void Undoable::deselectMask()
void UndoTransaction::deselectMask()
{
// Destroy the *deselected* mask
Mask* mask = m_sprite->requestMask("*deselected*");

View File

@ -16,8 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UNDOABLE_H_INCLUDED
#define UNDOABLE_H_INCLUDED
#ifndef UNDO_TRANSACTION_H_INCLUDED
#define UNDO_TRANSACTION_H_INCLUDED
#include "raster/dithering_method.h"
@ -37,15 +37,25 @@ class UndoHistory;
* In this class, all modifications in the sprite have an undo
* counterpart (if the sprite's undo is enabled).
*/
class Undoable
class UndoTransaction
{
public:
Undoable(DocumentWriter& document, const char* label);
virtual ~Undoable();
// Starts a undoable sequence of operations in a transaction that
// can be committed or rollbacked. All the operations will be
// grouped in the sprite's undo as an atomic operation.
UndoTransaction(DocumentWriter& document, const char* label);
virtual ~UndoTransaction();
inline Sprite* getSprite() const { return m_sprite; }
inline bool isEnabled() const { return m_enabledFlag; }
// This must be called to commit all the changes, so the undo will
// be finally added in the sprite.
//
// If you don't use this routine, all the changes will be discarded
// (if the sprite's undo was enabled when the UndoTransaction was
// created).
void commit();
// for sprite

View File

@ -18,13 +18,10 @@
#include "config.h"
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include "gui/gui.h"
#include "app.h"
#include "console.h"
#include "document_wrappers.h"
#include "gui/gui.h"
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"
@ -41,14 +38,16 @@
#include "settings/settings.h"
#include "skin/skin_parts.h"
#include "skin/skin_theme.h"
#include "document_wrappers.h"
#include "ui_context.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "util/clipboard.h"
#include "util/misc.h"
#include "widgets/color_bar.h"
#include "widgets/statebar.h"
#include <allegro.h>
#include <allegro/internal/aintern.h>
#if defined ALLEGRO_WINDOWS
#include <winalleg.h>
#include "util/clipboard_win32.h"
@ -165,10 +164,10 @@ void clipboard::cut(DocumentWriter& document)
}
else {
{
Undoable undoable(document, "Cut");
undoable.clearMask(app_get_color_to_clear_layer(sprite->getCurrentLayer()));
undoable.deselectMask();
undoable.commit();
UndoTransaction undoTransaction(document, "Cut");
undoTransaction.clearMask(app_get_color_to_clear_layer(sprite->getCurrentLayer()));
undoTransaction.deselectMask();
undoTransaction.commit();
}
document->generateMaskBoundaries();
update_screen_for_document(document);
@ -193,7 +192,7 @@ void clipboard::copy_image(Image* image, Palette* pal)
void clipboard::paste(DocumentWriter& document)
{
Undoable undoable(document, "Paste");
UndoTransaction undoTransaction(document, "Paste");
UndoHistory* undo = document->getUndoHistory();
int xout[4], yout[4];
int dst_x, dst_y;
@ -241,7 +240,7 @@ void clipboard::paste(DocumentWriter& document)
Cel* cel = cel_new(sprite->getCurrentFrame(), dst_image_index);
// Add the cel to the layer
undoable.addCel(layer, cel);
undoTransaction.addCel(layer, cel);
// Default destination position
dst_x = dst_y = 0;
@ -302,7 +301,7 @@ void clipboard::paste(DocumentWriter& document)
}
// Commit the "paste" operation
undoable.commit();
undoTransaction.commit();
}
if (src_image != clipboard_image)

View File

@ -26,7 +26,7 @@
#include "raster/image.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "undoable.h"
#include "undo_transaction.h"
#include "widgets/editor/pixels_movement.h"
using namespace gfx;
@ -35,7 +35,7 @@ class PixelsMovementImpl
{
DocumentWriter m_documentWriter;
Sprite* m_sprite;
Undoable m_undoable;
UndoTransaction m_undoTransaction;
int m_initial_x, m_initial_y;
int m_catch_x, m_catch_y;
bool m_firstDrop;
@ -45,7 +45,7 @@ public:
PixelsMovementImpl(Document* document, Sprite* sprite, const Image* moveThis, int initial_x, int initial_y, int opacity)
: m_documentWriter(document)
, m_sprite(sprite)
, m_undoable(m_documentWriter, "Pixels Movement")
, m_undoTransaction(m_documentWriter, "Pixels Movement")
, m_initial_x(initial_x)
, m_initial_y(initial_y)
, m_firstDrop(true)
@ -63,14 +63,14 @@ public:
void cutMask()
{
m_undoable.clearMask(app_get_color_to_clear_layer(m_sprite->getCurrentLayer()));
m_undoTransaction.clearMask(app_get_color_to_clear_layer(m_sprite->getCurrentLayer()));
copyMask();
}
void copyMask()
{
// Hide the mask (do not deselect it, it will be moved them using m_undoable.setMaskPosition)
// Hide the mask (do not deselect it, it will be moved them using m_undoTransaction.setMaskPosition)
Mask* empty_mask = new Mask();
m_documentWriter->generateMaskBoundaries(empty_mask);
delete empty_mask;
@ -87,7 +87,7 @@ public:
void catchImageAgain(int x, int y)
{
// Create a new Undoable to move the pixels to other position
// Create a new UndoTransaction to move the pixels to other position
Cel* cel = m_documentWriter->getExtraCel();
m_initial_x = cel->x;
m_initial_y = cel->y;
@ -96,7 +96,7 @@ public:
m_catch_x = x;
m_catch_y = y;
// Hide the mask (do not deselect it, it will be moved them using m_undoable.setMaskPosition)
// Hide the mask (do not deselect it, it will be moved them using m_undoTransaction.setMaskPosition)
Mask* empty_mask = new Mask();
m_documentWriter->generateMaskBoundaries(empty_mask);
delete empty_mask;
@ -145,7 +145,7 @@ public:
// Show the mask again in the new position
if (m_firstDrop) {
m_firstDrop = false;
m_undoable.setMaskPosition(cel->x, cel->y);
m_undoTransaction.setMaskPosition(cel->x, cel->y);
}
else {
m_sprite->getMask()->x = cel->x;
@ -163,8 +163,8 @@ public:
Cel* cel = m_documentWriter->getExtraCel();
Image* image = m_documentWriter->getExtraCelImage();
m_undoable.pasteImage(image, cel->x, cel->y, cel->opacity);
m_undoable.commit();
m_undoTransaction.pasteImage(image, cel->x, cel->y, cel->opacity);
m_undoTransaction.commit();
}
bool isDragging()