mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-24 16:43:34 +00:00
Refactored the entire Undo system in several layers.
+ Added "undo" library (undo namespace). + Moved UndoHistory to undo namespace. + Added Undoer and UndoersCollector interfaces. + Converted old UndoStream to UndoersStack class. + Added new "undoers" namespace and moved each Undoer implementation (classes to undo different actions) to "undoers" directory. + Added IO operations to "raster" objects (image, cel, layer, palette, mask).
This commit is contained in:
parent
daf7abfa68
commit
8e5c950df8
@ -43,7 +43,8 @@ else()
|
||||
endif()
|
||||
|
||||
# All libraries for .exe files
|
||||
set(all_libs filters-lib aseprite-library gui-lib gfx-lib base-lib ${libs3rdparty} allegro ${sys_libs})
|
||||
set(all_libs aseprite-library undo-lib filters-lib gui-lib gfx-lib base-lib
|
||||
${libs3rdparty} allegro ${sys_libs})
|
||||
|
||||
# Directories where .h files can be found
|
||||
include_directories(
|
||||
@ -64,6 +65,7 @@ add_subdirectory(base)
|
||||
add_subdirectory(gfx)
|
||||
add_subdirectory(gui)
|
||||
add_subdirectory(filters)
|
||||
add_subdirectory(undo)
|
||||
|
||||
######################################################################
|
||||
# aseprite library
|
||||
@ -200,13 +202,19 @@ add_library(aseprite-library
|
||||
raster/algo_polygon.cpp
|
||||
raster/blend.cpp
|
||||
raster/cel.cpp
|
||||
raster/cel_io.cpp
|
||||
raster/dirty.cpp
|
||||
raster/dirty_io.cpp
|
||||
raster/gfxobj.cpp
|
||||
raster/image.cpp
|
||||
raster/image_io.cpp
|
||||
raster/images_collector.cpp
|
||||
raster/layer.cpp
|
||||
raster/layer_io.cpp
|
||||
raster/mask.cpp
|
||||
raster/mask_io.cpp
|
||||
raster/palette.cpp
|
||||
raster/palette_io.cpp
|
||||
raster/path.cpp
|
||||
raster/pen.cpp
|
||||
raster/quantization.cpp
|
||||
@ -221,7 +229,32 @@ add_library(aseprite-library
|
||||
skin/skin_slider_property.cpp
|
||||
tools/tool.cpp
|
||||
tools/toolbox.cpp
|
||||
undo/undo_history.cpp
|
||||
undoers/add_cel.cpp
|
||||
undoers/add_image.cpp
|
||||
undoers/add_layer.cpp
|
||||
undoers/add_palette.cpp
|
||||
undoers/close_group.cpp
|
||||
undoers/dirty_area.cpp
|
||||
undoers/flip_image.cpp
|
||||
undoers/image_area.cpp
|
||||
undoers/move_layer.cpp
|
||||
undoers/open_group.cpp
|
||||
undoers/raw_data.cpp
|
||||
undoers/remap_palette.cpp
|
||||
undoers/remove_cel.cpp
|
||||
undoers/remove_image.cpp
|
||||
undoers/remove_layer.cpp
|
||||
undoers/remove_palette.cpp
|
||||
undoers/replace_image.cpp
|
||||
undoers/set_current_frame.cpp
|
||||
undoers/set_current_layer.cpp
|
||||
undoers/set_frame_duration.cpp
|
||||
undoers/set_imgtype.cpp
|
||||
undoers/set_layer_name.cpp
|
||||
undoers/set_mask.cpp
|
||||
undoers/set_palette_colors.cpp
|
||||
undoers/set_sprite_size.cpp
|
||||
undoers/set_total_frames.cpp
|
||||
util/autocrop.cpp
|
||||
util/boundary.cpp
|
||||
util/celmove.cpp
|
||||
|
@ -132,7 +132,7 @@ void CelPropertiesCommand::onExecute(Context* context)
|
||||
Sprite* sprite_writer = document_writer->getSprite();
|
||||
Layer* layer_writer = sprite_writer->getCurrentLayer();
|
||||
Cel* cel_writer = static_cast<LayerImage*>(layer_writer)->getCel(sprite->getCurrentFrame());
|
||||
UndoHistory* undo = document_writer->getUndoHistory();
|
||||
undo::UndoHistory* undo = document_writer->getUndoHistory();
|
||||
|
||||
int new_opacity = slider_opacity->getValue();
|
||||
|
||||
|
@ -76,7 +76,7 @@ void InvertMaskCommand::onExecute(Context* context)
|
||||
else {
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite(document->getSprite());
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
|
||||
/* undo */
|
||||
if (undo->isEnabled()) {
|
||||
|
@ -68,7 +68,7 @@ void LoadMaskCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite(document->getSprite());
|
||||
UndoHistory* undo(document->getUndoHistory());
|
||||
undo::UndoHistory* undo(document->getUndoHistory());
|
||||
|
||||
base::string filename = m_filename;
|
||||
|
||||
|
@ -57,7 +57,7 @@ void MaskAllCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite(document->getSprite());
|
||||
UndoHistory* undo(document->getUndoHistory());
|
||||
undo::UndoHistory* undo(document->getUndoHistory());
|
||||
|
||||
// Undo
|
||||
if (undo->isEnabled()) {
|
||||
|
@ -73,7 +73,7 @@ void MergeDownLayerCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite(document->getSprite());
|
||||
UndoHistory* undo(document->getUndoHistory());
|
||||
undo::UndoHistory* undo(document->getUndoHistory());
|
||||
Layer *src_layer, *dst_layer;
|
||||
Cel *src_cel, *dst_cel;
|
||||
Image *src_image, *dst_image;
|
||||
|
@ -654,7 +654,7 @@ void PaletteEntryEditor::updateCurrentSpritePalette(const char* operationName)
|
||||
try {
|
||||
ActiveDocumentWriter document(UIContext::instance());
|
||||
Sprite* sprite(document->getSprite());
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
Palette* newPalette = get_current_palette(); // System current pal
|
||||
Palette* currentSpritePalette = sprite->getPalette(sprite->getCurrentFrame()); // Sprite current pal
|
||||
int from, to;
|
||||
|
@ -59,14 +59,12 @@ bool ReselectMaskCommand::onEnabled(Context* context)
|
||||
void ReselectMaskCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
|
||||
// TODO IMPLEMENT THIS Add an undo action in the history to reverse the change of a Document's int field
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
|
||||
// Undo
|
||||
if (undo->isEnabled()) {
|
||||
undo->setLabel("Mask Reselection");
|
||||
//undo->undo_set_mask(document);
|
||||
undo->undo_set_mask(document);
|
||||
}
|
||||
|
||||
// Make the mask visible again.
|
||||
|
@ -203,7 +203,7 @@ void FilterManagerImpl::apply()
|
||||
}
|
||||
|
||||
if (!cancelled) {
|
||||
UndoHistory* undo = m_document->getUndoHistory();
|
||||
undo::UndoHistory* undo = m_document->getUndoHistory();
|
||||
|
||||
// Undo stuff
|
||||
if (undo->isEnabled()) {
|
||||
@ -230,7 +230,7 @@ void FilterManagerImpl::applyToTarget()
|
||||
// Initialize writting operation
|
||||
DocumentReader doc_reader(m_document);
|
||||
DocumentWriter doc_writer(doc_reader);
|
||||
UndoHistory* undo = m_document->getUndoHistory();
|
||||
undo::UndoHistory* undo = m_document->getUndoHistory();
|
||||
|
||||
// Open group of undo operations
|
||||
if (images.size() > 1) {
|
||||
|
@ -715,11 +715,11 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
/* undo */
|
||||
if (command && strcmp(command->short_name(), CommandId::Undo) == 0) {
|
||||
const DocumentReader document(const_cast<Document*>(anieditor->document));
|
||||
const UndoHistory* undo = document->getUndoHistory();
|
||||
const undo::UndoHistory* undo = document->getUndoHistory();
|
||||
|
||||
if (undo->canUndo()) {
|
||||
DocumentWriter document_writer(document);
|
||||
UndoHistory* undo_writer = document_writer->getUndoHistory();
|
||||
undo::UndoHistory* undo_writer = document_writer->getUndoHistory();
|
||||
|
||||
undo_writer->doUndo();
|
||||
|
||||
@ -734,11 +734,11 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
/* redo */
|
||||
if (command && strcmp(command->short_name(), CommandId::Redo) == 0) {
|
||||
const DocumentReader document(const_cast<Document*>(anieditor->document));
|
||||
const UndoHistory* undo = document->getUndoHistory();
|
||||
const undo::UndoHistory* undo = document->getUndoHistory();
|
||||
|
||||
if (undo->canRedo()) {
|
||||
DocumentWriter document_writer(document);
|
||||
UndoHistory* undo_writer = document_writer->getUndoHistory();
|
||||
undo::UndoHistory* undo_writer = document_writer->getUndoHistory();
|
||||
|
||||
undo_writer->doRedo();
|
||||
|
||||
|
@ -128,7 +128,7 @@ void dialogs_mask_color(Document* document)
|
||||
|
||||
if (window->get_killer() == button_ok) {
|
||||
DocumentWriter documentWriter(documentReader);
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
Mask* mask;
|
||||
|
||||
/* undo */
|
||||
|
@ -35,6 +35,8 @@
|
||||
#include "undo/undo_history.h"
|
||||
#include "util/boundary.h"
|
||||
|
||||
using namespace undo;
|
||||
|
||||
Document::Document(Sprite* sprite)
|
||||
: m_id(WithoutDocumentId)
|
||||
, m_sprite(sprite)
|
||||
|
@ -31,11 +31,14 @@ class FormatOptions;
|
||||
class Image;
|
||||
class Mask;
|
||||
class Mutex;
|
||||
class ObjectsContainer;
|
||||
class Sprite;
|
||||
class UndoHistory;
|
||||
struct _BoundSeg;
|
||||
|
||||
namespace undo {
|
||||
class ObjectsContainer;
|
||||
class UndoHistory;
|
||||
}
|
||||
|
||||
struct PreferredEditorSettings
|
||||
{
|
||||
int scroll_x;
|
||||
@ -70,10 +73,10 @@ public:
|
||||
void setId(DocumentId id) { m_id = id; }
|
||||
|
||||
const Sprite* getSprite() const { return m_sprite; }
|
||||
const UndoHistory* getUndoHistory() const { return m_undoHistory; }
|
||||
const undo::UndoHistory* getUndoHistory() const { return m_undoHistory; }
|
||||
|
||||
Sprite* getSprite() { return m_sprite; }
|
||||
UndoHistory* getUndoHistory() { return m_undoHistory; }
|
||||
undo::UndoHistory* getUndoHistory() { return m_undoHistory; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// File related properties
|
||||
@ -160,9 +163,18 @@ private:
|
||||
// Unique identifier for this document (it is assigned by Documents class).
|
||||
DocumentId m_id;
|
||||
|
||||
// The main sprite.
|
||||
UniquePtr<Sprite> m_sprite;
|
||||
UniquePtr<ObjectsContainer> m_objects;
|
||||
UniquePtr<UndoHistory> m_undoHistory;
|
||||
|
||||
// Collection of objects used by UndoHistory to reference deleted
|
||||
// objects that are re-created by an Undoer. The container keeps an
|
||||
// ID that is saved in the serialization process, and loaded in the
|
||||
// deserialization process. The ID can be used by different undoers
|
||||
// to keep references to deleted objects.
|
||||
UniquePtr<undo::ObjectsContainer> m_objects;
|
||||
|
||||
// Stack of undoers to undo operations.
|
||||
UniquePtr<undo::UndoHistory> m_undoHistory;
|
||||
|
||||
// Document's file name (from where it was loaded, where it is saved).
|
||||
std::string m_filename;
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "objects_container_impl.h"
|
||||
|
||||
using namespace undo;
|
||||
|
||||
ObjectsContainerImpl::ObjectsContainerImpl()
|
||||
{
|
||||
m_idCounter = 0;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
class ObjectsContainerImpl : public ObjectsContainer
|
||||
class ObjectsContainerImpl : public undo::ObjectsContainer
|
||||
{
|
||||
public:
|
||||
ObjectsContainerImpl();
|
||||
@ -31,15 +31,15 @@ public:
|
||||
|
||||
// ObjectsContainer Implementation
|
||||
|
||||
ObjectId addObject(void* object);
|
||||
void insertObject(ObjectId id, void* object);
|
||||
void removeObject(ObjectId id);
|
||||
void* getObject(ObjectId id);
|
||||
undo::ObjectId addObject(void* object);
|
||||
void insertObject(undo::ObjectId id, void* object);
|
||||
void removeObject(undo::ObjectId id);
|
||||
void* getObject(undo::ObjectId id);
|
||||
|
||||
private:
|
||||
ObjectId m_idCounter;
|
||||
std::map<ObjectId, void*> m_idToPtr;
|
||||
std::map<void*, ObjectId> m_ptrToId;
|
||||
undo::ObjectId m_idCounter;
|
||||
std::map<undo::ObjectId, void*> m_idToPtr;
|
||||
std::map<void*, undo::ObjectId> m_ptrToId;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
74
src/raster/cel_io.cpp
Normal file
74
src/raster/cel_io.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "raster/cel_io.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/cel.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace raster {
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
// Serialized Cel data:
|
||||
//
|
||||
// WORD Frame
|
||||
// WORD Image index
|
||||
// WORD[2] X, Y
|
||||
// WORD Opacity
|
||||
|
||||
void write_cel(std::ostream& os, Cel* cel)
|
||||
{
|
||||
// ObjectId cel_id = objects->addObject(cel);
|
||||
// write_raw_uint32(cel_id);
|
||||
|
||||
write16(os, cel->frame);
|
||||
write16(os, cel->image);
|
||||
write16(os, (int16_t)cel->x);
|
||||
write16(os, (int16_t)cel->y);
|
||||
write16(os, cel->opacity);
|
||||
|
||||
// objects->removeObject(cel_id);
|
||||
}
|
||||
|
||||
Cel* read_cel(std::istream& is)
|
||||
{
|
||||
// ObjectId cel_id = read32();
|
||||
|
||||
int frame = read16(is);
|
||||
int imageIndex = read16(is);
|
||||
int x = (int16_t)read16(is);
|
||||
int y = (int16_t)read16(is);
|
||||
int opacity = read16(is);
|
||||
|
||||
UniquePtr<Cel> cel(cel_new(frame, imageIndex));
|
||||
|
||||
cel_set_position(cel, x, y);
|
||||
cel_set_opacity(cel, opacity);
|
||||
|
||||
// objects->insertObject(cel_id, cel);
|
||||
return cel.release();
|
||||
}
|
||||
|
||||
}
|
33
src/raster/cel_io.h
Normal file
33
src/raster/cel_io.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_CEL_IO_H_INCLUDED
|
||||
#define RASTER_CEL_IO_H_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Cel;
|
||||
|
||||
namespace raster {
|
||||
|
||||
void write_cel(std::ostream& os, Cel* cel);
|
||||
Cel* read_cel(std::istream& is);
|
||||
|
||||
} // namespace raster
|
||||
|
||||
#endif
|
117
src/raster/dirty_io.cpp
Normal file
117
src/raster/dirty_io.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "raster/dirty_io.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/dirty.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace raster {
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
// Serialized Dirty data:
|
||||
//
|
||||
// BYTE image type
|
||||
// WORD[4] x1, y1, x2, y2
|
||||
// WORD rows
|
||||
// for each row
|
||||
// WORD[2] y, columns
|
||||
// for each column
|
||||
// WORD[2] x, w
|
||||
// for each pixel ("w" times)
|
||||
// BYTE[4] for RGB images, or
|
||||
// BYTE[2] for Grayscale images, or
|
||||
// BYTE for Indexed images
|
||||
|
||||
void write_dirty(std::ostream& os, Dirty* dirty)
|
||||
{
|
||||
write8(os, dirty->getImgType());
|
||||
write16(os, dirty->x1());
|
||||
write16(os, dirty->y1());
|
||||
write16(os, dirty->x2());
|
||||
write16(os, dirty->y2());
|
||||
write16(os, dirty->getRowsCount());
|
||||
|
||||
for (int v=0; v<dirty->getRowsCount(); v++) {
|
||||
const Dirty::Row& row = dirty->getRow(v);
|
||||
|
||||
write16(os, row.y);
|
||||
write16(os, row.cols.size());
|
||||
|
||||
for (size_t u=0; u<row.cols.size(); u++) {
|
||||
write16(os, row.cols[u]->x);
|
||||
write16(os, row.cols[u]->w);
|
||||
|
||||
size_t size = dirty->getLineSize(row.cols[u]->w);
|
||||
os.write((char*)&row.cols[u]->data[0], size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dirty* read_dirty(std::istream& is)
|
||||
{
|
||||
int u, v, x, y, w;
|
||||
int imgtype = read8(is);
|
||||
int x1 = read16(is);
|
||||
int y1 = read16(is);
|
||||
int x2 = read16(is);
|
||||
int y2 = read16(is);
|
||||
UniquePtr<Dirty> dirty(new Dirty(imgtype, x1, y1, x2, y2));
|
||||
|
||||
int noRows = read16(is);
|
||||
if (noRows > 0) {
|
||||
dirty->m_rows.resize(noRows);
|
||||
|
||||
for (v=0; v<dirty->getRowsCount(); v++) {
|
||||
y = read16(is);
|
||||
|
||||
UniquePtr<Dirty::Row> row(new Dirty::Row(y));
|
||||
|
||||
int noCols = read16(is);
|
||||
row->cols.resize(noCols);
|
||||
|
||||
for (u=0; u<noCols; u++) {
|
||||
x = read16(is);
|
||||
w = read16(is);
|
||||
|
||||
UniquePtr<Dirty::Col> col(new Dirty::Col(x, w));
|
||||
|
||||
int size = dirty->getLineSize(col->w);
|
||||
ASSERT(size > 0);
|
||||
|
||||
col->data.resize(size);
|
||||
is.read((char*)&col->data[0], size);
|
||||
|
||||
row->cols[u] = col.release();
|
||||
}
|
||||
|
||||
dirty->m_rows[v] = row.release();
|
||||
}
|
||||
}
|
||||
|
||||
return dirty.release();
|
||||
}
|
||||
|
||||
}
|
33
src/raster/dirty_io.h
Normal file
33
src/raster/dirty_io.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_DIRTY_IO_H_INCLUDED
|
||||
#define RASTER_DIRTY_IO_H_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Dirty;
|
||||
|
||||
namespace raster {
|
||||
|
||||
void write_dirty(std::ostream& os, Dirty* dirty);
|
||||
Dirty* read_dirty(std::istream& is);
|
||||
|
||||
} // namespace raster
|
||||
|
||||
#endif
|
75
src/raster/image_io.cpp
Normal file
75
src/raster/image_io.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "raster/image_io.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/image.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace raster {
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
// Serialized Image data:
|
||||
//
|
||||
// DWORD image ID
|
||||
// BYTE image type
|
||||
// WORD[2] w, h
|
||||
// DWORD mask color
|
||||
// for each line ("h" times)
|
||||
// for each pixel ("w" times)
|
||||
// BYTE[4] for RGB images, or
|
||||
// BYTE[2] for Grayscale images, or
|
||||
// BYTE for Indexed images
|
||||
|
||||
void write_image(std::ostream& os, Image* image)
|
||||
{
|
||||
write8(os, image->imgtype); // Imgtype
|
||||
write16(os, image->w); // Width
|
||||
write16(os, image->h); // Height
|
||||
write32(os, image->mask_color); // Mask color
|
||||
|
||||
int size = image_line_size(image, image->w);
|
||||
for (int c=0; c<image->h; c++)
|
||||
os.write((char*)image->line[c], size);
|
||||
}
|
||||
|
||||
Image* read_image(std::istream& is)
|
||||
{
|
||||
int imgtype = read8(is); // Imgtype
|
||||
int width = read16(is); // Width
|
||||
int height = read16(is); // Height
|
||||
uint32_t maskColor = read32(is); // Mask color
|
||||
|
||||
UniquePtr<Image> image(image_new(imgtype, width, height));
|
||||
int size = image_line_size(image, image->w);
|
||||
|
||||
for (int c=0; c<image->h; c++)
|
||||
is.read((char*)image->line[c], size);
|
||||
|
||||
image->mask_color = maskColor;
|
||||
return image.release();
|
||||
}
|
||||
|
||||
}
|
33
src/raster/image_io.h
Normal file
33
src/raster/image_io.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_IMAGE_IO_H_INCLUDED
|
||||
#define RASTER_IMAGE_IO_H_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Image;
|
||||
|
||||
namespace raster {
|
||||
|
||||
void write_image(std::ostream& os, Image* image);
|
||||
Image* read_image(std::istream& is);
|
||||
|
||||
} // namespace raster
|
||||
|
||||
#endif
|
156
src/raster/layer_io.cpp
Normal file
156
src/raster/layer_io.cpp
Normal file
@ -0,0 +1,156 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "raster/layer_io.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace raster {
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
// Serialized Layer data:
|
||||
|
||||
void write_layer(std::ostream& os, LayerSubObjectsSerializer* subObjects, Layer* layer)
|
||||
{
|
||||
std::string name = layer->getName();
|
||||
|
||||
write16(os, name.size()); // Name length
|
||||
if (!name.empty())
|
||||
os.write(name.c_str(), name.size()); // Name
|
||||
|
||||
write8(os, *layer->flags_addr()); // Flags
|
||||
write16(os, layer->getType()); // Type
|
||||
|
||||
switch (layer->getType()) {
|
||||
|
||||
case GFXOBJ_LAYER_IMAGE: {
|
||||
// Number of cels
|
||||
write16(os, static_cast<LayerImage*>(layer)->getCelsCount());
|
||||
|
||||
CelIterator it = static_cast<LayerImage*>(layer)->getCelBegin();
|
||||
CelIterator end = static_cast<LayerImage*>(layer)->getCelEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
Cel* cel = *it;
|
||||
subObjects->write_cel(os, cel);
|
||||
|
||||
Image* image = layer->getSprite()->getStock()->getImage(cel->image);
|
||||
ASSERT(image != NULL);
|
||||
|
||||
subObjects->write_image(os, image);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GFXOBJ_LAYER_FOLDER: {
|
||||
LayerIterator it = static_cast<LayerFolder*>(layer)->get_layer_begin();
|
||||
LayerIterator end = static_cast<LayerFolder*>(layer)->get_layer_end();
|
||||
|
||||
// Number of sub-layers
|
||||
write16(os, static_cast<LayerFolder*>(layer)->get_layers_count());
|
||||
|
||||
for (; it != end; ++it)
|
||||
subObjects->write_layer(os, *it);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Layer* read_layer(std::istream& is, LayerSubObjectsSerializer* subObjects, Sprite* sprite)
|
||||
{
|
||||
int flags, layer_type;
|
||||
UniquePtr<Layer> layer;
|
||||
|
||||
uint16_t name_length = read16(is); // Name length
|
||||
std::vector<char> name(name_length+1);
|
||||
if (name_length > 0) {
|
||||
is.read(&name[0], name_length); // Name
|
||||
name[name_length] = 0;
|
||||
}
|
||||
else
|
||||
name[0] = 0;
|
||||
|
||||
flags = read8(is); // Flags
|
||||
layer_type = read16(is); // Type
|
||||
|
||||
switch (layer_type) {
|
||||
|
||||
case GFXOBJ_LAYER_IMAGE: {
|
||||
// Create layer
|
||||
layer.reset(new LayerImage(sprite));
|
||||
|
||||
// Read cels
|
||||
int cels = read16(is); // Number of cels
|
||||
for (int c=0; c<cels; ++c) {
|
||||
// Read the cel
|
||||
Cel* cel = subObjects->read_cel(is);
|
||||
|
||||
// Add the cel in the layer
|
||||
static_cast<LayerImage*>(layer.get())->addCel(cel);
|
||||
|
||||
// Read the cel's image
|
||||
Image* image = subObjects->read_image(is);
|
||||
|
||||
sprite->getStock()->replaceImage(cel->image, image);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GFXOBJ_LAYER_FOLDER: {
|
||||
// Create the layer set
|
||||
layer.reset(new LayerFolder(sprite));
|
||||
|
||||
// Number of sub-layers
|
||||
int layers = read16(is);
|
||||
for (int c=0; c<layers; c++) {
|
||||
Layer* child = subObjects->read_layer(is);
|
||||
if (child)
|
||||
static_cast<LayerFolder*>(layer.get())->add_layer(child);
|
||||
else
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw InvalidLayerType("Invalid layer type found in stream");
|
||||
|
||||
}
|
||||
|
||||
if (layer != NULL) {
|
||||
layer->setName(&name[0]);
|
||||
*layer->flags_addr() = flags;
|
||||
}
|
||||
|
||||
return layer.release();
|
||||
}
|
||||
|
||||
}
|
62
src/raster/layer_io.h
Normal file
62
src/raster/layer_io.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_LAYER_IO_H_INCLUDED
|
||||
#define RASTER_LAYER_IO_H_INCLUDED
|
||||
|
||||
#include "base/exception.h"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Cel;
|
||||
class Image;
|
||||
class Layer;
|
||||
class Sprite;
|
||||
|
||||
namespace raster {
|
||||
|
||||
// Thrown when a invalid layer type is read from the istream.
|
||||
class InvalidLayerType : public base::Exception
|
||||
{
|
||||
public:
|
||||
InvalidLayerType(const char* msg) throw() : base::Exception(msg) { }
|
||||
};
|
||||
|
||||
// Interface used to read sub-objects of a layer.
|
||||
class LayerSubObjectsSerializer
|
||||
{
|
||||
public:
|
||||
virtual ~LayerSubObjectsSerializer() { }
|
||||
|
||||
// How to write cels, images, and sub-layers
|
||||
virtual void write_cel(std::ostream& os, Cel* cel) = 0;
|
||||
virtual void write_image(std::ostream& os, Image* image) = 0;
|
||||
virtual void write_layer(std::ostream& os, Layer* layer) = 0;
|
||||
|
||||
// How to read cels, images, and sub-layers
|
||||
virtual Cel* read_cel(std::istream& is) = 0;
|
||||
virtual Image* read_image(std::istream& is) = 0;
|
||||
virtual Layer* read_layer(std::istream& is) = 0;
|
||||
};
|
||||
|
||||
void write_layer(std::ostream& os, LayerSubObjectsSerializer* subObjects, Layer* layer);
|
||||
Layer* read_layer(std::istream& is, LayerSubObjectsSerializer* subObjects, Sprite* sprite);
|
||||
|
||||
} // namespace raster
|
||||
|
||||
#endif
|
77
src/raster/mask_io.cpp
Normal file
77
src/raster/mask_io.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "raster/mask_io.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/mask.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace raster {
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
// Serialized Mask data:
|
||||
//
|
||||
// WORD[4] x, y, w, h
|
||||
// for each line ("h" times)
|
||||
// for each packet ("((w+7)/8)" times)
|
||||
// BYTE 8 pixels of the mask
|
||||
// BYTE for Indexed images
|
||||
|
||||
void write_mask(std::ostream& os, Mask* mask)
|
||||
{
|
||||
write16(os, mask->x); // Xpos
|
||||
write16(os, mask->y); // Ypos
|
||||
write16(os, mask->bitmap ? mask->w: 0); // Width
|
||||
write16(os, mask->bitmap ? mask->h: 0); // Height
|
||||
|
||||
if (mask->bitmap) {
|
||||
int size = (mask->w+7)/8;
|
||||
|
||||
for (int c=0; c<mask->h; c++)
|
||||
os.write((char*)mask->bitmap->line[c], size);
|
||||
}
|
||||
}
|
||||
|
||||
Mask* read_mask(std::istream& is)
|
||||
{
|
||||
int x = read16(is); // Xpos
|
||||
int y = read16(is); // Ypos
|
||||
int w = read16(is); // Width
|
||||
int h = read16(is); // Height
|
||||
|
||||
UniquePtr<Mask> mask(mask_new());
|
||||
|
||||
if (w > 0 && h > 0) {
|
||||
int size = (w+7)/8;
|
||||
|
||||
mask->add(x, y, w, h);
|
||||
for (int c=0; c<mask->h; c++)
|
||||
is.read((char*)mask->bitmap->line[c], size);
|
||||
}
|
||||
|
||||
return mask.release();
|
||||
}
|
||||
|
||||
}
|
33
src/raster/mask_io.h
Normal file
33
src/raster/mask_io.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_MASK_IO_H_INCLUDED
|
||||
#define RASTER_MASK_IO_H_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Mask;
|
||||
|
||||
namespace raster {
|
||||
|
||||
void write_mask(std::ostream& os, Mask* mask);
|
||||
Mask* read_mask(std::istream& is);
|
||||
|
||||
} // namespace raster
|
||||
|
||||
#endif
|
67
src/raster/palette_io.cpp
Normal file
67
src/raster/palette_io.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "raster/palette_io.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/palette.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace raster {
|
||||
|
||||
using namespace base::serialization;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
// Serialized Palette data:
|
||||
//
|
||||
// WORD Frame
|
||||
// WORD Number of colors
|
||||
// for each color ("ncolors" times)
|
||||
// DWORD _rgba color
|
||||
|
||||
void write_palette(std::ostream& os, Palette* palette)
|
||||
{
|
||||
write16(os, palette->getFrame()); // Frame
|
||||
write16(os, palette->size()); // Number of colors
|
||||
|
||||
for (int c=0; c<palette->size(); c++) {
|
||||
uint32_t color = palette->getEntry(c);
|
||||
write32(os, color);
|
||||
}
|
||||
}
|
||||
|
||||
Palette* read_palette(std::istream& is)
|
||||
{
|
||||
int frame = read16(is); // Frame
|
||||
int ncolors = read16(is); // Number of colors
|
||||
|
||||
UniquePtr<Palette> palette(new Palette(frame, ncolors));
|
||||
|
||||
for (int c=0; c<ncolors; ++c) {
|
||||
uint32_t color = read32(is);
|
||||
palette->setEntry(c, color);
|
||||
}
|
||||
|
||||
return palette.release();
|
||||
}
|
||||
|
||||
}
|
33
src/raster/palette_io.h
Normal file
33
src/raster/palette_io.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_PALETTE_IO_H_INCLUDED
|
||||
#define RASTER_PALETTE_IO_H_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Palette;
|
||||
|
||||
namespace raster {
|
||||
|
||||
void write_palette(std::ostream& os, Palette* palette);
|
||||
Palette* read_palette(std::istream& is);
|
||||
|
||||
} // namespace raster
|
||||
|
||||
#endif
|
@ -373,7 +373,7 @@ void Sprite::getCels(CelList& cels)
|
||||
getFolder()->getCels(cels);
|
||||
}
|
||||
|
||||
void Sprite::remapImages(int frame_from, int frame_to, const std::vector<int>& mapping)
|
||||
void Sprite::remapImages(int frame_from, int frame_to, const std::vector<uint8_t>& mapping)
|
||||
{
|
||||
ASSERT(m_imgtype == IMAGE_INDEXED);
|
||||
ASSERT(mapping.size() == 256);
|
||||
|
@ -125,7 +125,7 @@ public:
|
||||
|
||||
void getCels(CelList& cels);
|
||||
|
||||
void remapImages(int frame_from, int frame_to, const std::vector<int>& mapping);
|
||||
void remapImages(int frame_from, int frame_to, const std::vector<uint8_t>& mapping);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Drawing
|
||||
|
7
src/undo/CMakeLists.txt
Normal file
7
src/undo/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
# ASEPRITE Undo Library
|
||||
# Copyright (C) 2001-2011 David Capello
|
||||
|
||||
add_library(undo-lib
|
||||
undo_history.cpp
|
||||
undo_history_backward.cpp
|
||||
undoers_stack.cpp)
|
29
src/undo/LICENSE.txt
Normal file
29
src/undo/LICENSE.txt
Normal file
@ -0,0 +1,29 @@
|
||||
ASEPRITE Undo Library
|
||||
Copyright (c) 2001-2011 David Capello
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of the author nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16
src/undo/object_id.h
Normal file
16
src/undo/object_id.h
Normal file
@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_OBJECT_ID_H_INCLUDED
|
||||
#define UNDO_OBJECT_ID_H_INCLUDED
|
||||
|
||||
namespace undo {
|
||||
|
||||
typedef uint32_t ObjectId;
|
||||
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_OBJECT_ID_H_INCLUDED
|
@ -1,27 +1,16 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_OBJECTS_CONTAINER_H_INCLUDED
|
||||
#define UNDO_OBJECTS_CONTAINER_H_INCLUDED
|
||||
|
||||
#include "base/exception.h"
|
||||
#include "undo/object_id.h"
|
||||
|
||||
typedef uint32_t ObjectId;
|
||||
namespace undo {
|
||||
|
||||
// Thrown when you use ObjectsContainer::insertObject() with an
|
||||
// existent ID or pointer.
|
||||
@ -90,4 +79,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_OBJECTS_CONTAINER_H_INCLUDED
|
||||
|
22
src/undo/undo_exception.h
Normal file
22
src/undo/undo_exception.h
Normal file
@ -0,0 +1,22 @@
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_UNDO_EXCEPTION_H_INCLUDED
|
||||
#define UNDO_UNDO_EXCEPTION_H_INCLUDED
|
||||
|
||||
#include "base/exception.h"
|
||||
|
||||
namespace undo {
|
||||
|
||||
class UndoException : public base::Exception
|
||||
{
|
||||
public:
|
||||
UndoException(const char* msg) throw() : base::Exception(msg) { }
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_UNDO_EXCEPTION_H_INCLUDED
|
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,17 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_UNDO_HISTORY_H_INCLUDED
|
||||
#define UNDO_UNDO_HISTORY_H_INCLUDED
|
||||
|
||||
#include "base/exception.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
// TODO Remove this (it is here only for backward compatibility)
|
||||
class Cel;
|
||||
class Dirty;
|
||||
class Document;
|
||||
@ -30,19 +19,16 @@ class GfxObj;
|
||||
class Image;
|
||||
class Layer;
|
||||
class Mask;
|
||||
class ObjectsContainer;
|
||||
class Palette;
|
||||
class Sprite;
|
||||
class Stock;
|
||||
class UndoStream;
|
||||
|
||||
class UndoException : public base::Exception
|
||||
{
|
||||
public:
|
||||
UndoException(const char* msg) throw() : base::Exception(msg) { }
|
||||
};
|
||||
namespace undo {
|
||||
|
||||
class UndoHistory
|
||||
class ObjectsContainer;
|
||||
class UndoersStack;
|
||||
|
||||
class UndoHistory : public UndoersCollector
|
||||
{
|
||||
public:
|
||||
UndoHistory(ObjectsContainer* objects);
|
||||
@ -68,6 +54,12 @@ public:
|
||||
bool isSavedState() const;
|
||||
void markSavedState();
|
||||
|
||||
ObjectsContainer* getObjects() const { return m_objects; }
|
||||
|
||||
// UndoersCollector interface
|
||||
void pushUndoer(Undoer* undoer);
|
||||
|
||||
// Backward compatibility methods
|
||||
void undo_open();
|
||||
void undo_close();
|
||||
void undo_data(void* object, void* fieldAddress, int fieldSize);
|
||||
@ -87,8 +79,7 @@ public:
|
||||
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<int>& mapping);
|
||||
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);
|
||||
@ -104,20 +95,22 @@ public:
|
||||
undo_data(gfxobj, (void*)(value_address), sizeof(double));
|
||||
}
|
||||
|
||||
ObjectsContainer* getObjects() const { return m_objects; }
|
||||
|
||||
private:
|
||||
void runUndo(int state);
|
||||
enum Direction { UndoDirection, RedoDirection };
|
||||
|
||||
void runUndo(Direction direction);
|
||||
void discardTail();
|
||||
void updateUndo();
|
||||
|
||||
ObjectsContainer* m_objects; // Container of objects to insert & retrieve objects by ID
|
||||
UndoStream* m_undoStream;
|
||||
UndoStream* m_redoStream;
|
||||
UndoersStack* m_undoers;
|
||||
UndoersStack* m_redoers;
|
||||
int m_diffCount;
|
||||
int m_diffSaved;
|
||||
bool m_enabled; // Is undo enabled?
|
||||
const char* m_label; // Current label to be applied to all next undo operations.
|
||||
};
|
||||
|
||||
#endif
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_UNDO_HISTORY_H_INCLUDED
|
||||
|
171
src/undo/undo_history_backward.cpp
Normal file
171
src/undo/undo_history_backward.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
// 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 "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/raw_data.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_imgtype.h"
|
||||
#include "undoers/set_layer_name.h"
|
||||
#include "undoers/set_mask.h"
|
||||
#include "undoers/set_palette_colors.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_data(void* object, void* fieldAddress, int fieldSize)
|
||||
{
|
||||
pushUndoer(new undoers::RawData(getObjects(), object, fieldAddress, fieldSize));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void UndoHistory::undo_remove_palette(Sprite* sprite, Palette* palette)
|
||||
{
|
||||
pushUndoer(new undoers::RemovePalette(getObjects(), sprite, palette));
|
||||
}
|
||||
|
||||
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::SetImgType(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));
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDO_UNDO_STREAM_H_INCLUDED
|
||||
#define UNDO_UNDO_STREAM_H_INCLUDED
|
||||
|
||||
class UndoStream
|
||||
{
|
||||
public:
|
||||
typedef ChunksList::iterator iterator;
|
||||
|
||||
UndoStream(UndoHistory* undo)
|
||||
{
|
||||
m_undo = undo;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
~UndoStream()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
UndoHistory* getUndo() const
|
||||
{
|
||||
return m_undo;
|
||||
}
|
||||
|
||||
ObjectsContainer* getObjects() const
|
||||
{
|
||||
return m_undo->getObjects();
|
||||
}
|
||||
|
||||
iterator begin() { return m_chunks.begin(); }
|
||||
iterator end() { return m_chunks.end(); }
|
||||
bool empty() const { return m_chunks.empty(); }
|
||||
|
||||
void clear()
|
||||
{
|
||||
iterator it = begin();
|
||||
iterator end = this->end();
|
||||
for (; it != end; ++it)
|
||||
undo_chunk_free(*it);
|
||||
|
||||
m_size = 0;
|
||||
m_chunks.clear();
|
||||
}
|
||||
|
||||
int getMemSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
UndoChunk* popChunk(bool tail)
|
||||
{
|
||||
UndoChunk* chunk;
|
||||
iterator it;
|
||||
|
||||
if (!empty()) {
|
||||
if (!tail)
|
||||
it = begin();
|
||||
else
|
||||
it = --end();
|
||||
|
||||
chunk = *it;
|
||||
m_chunks.erase(it);
|
||||
m_size -= chunk->size;
|
||||
}
|
||||
else
|
||||
chunk = NULL;
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
void pushChunk(UndoChunk* chunk)
|
||||
{
|
||||
m_chunks.insert(begin(), chunk);
|
||||
m_size += chunk->size;
|
||||
}
|
||||
|
||||
private:
|
||||
UndoHistory* m_undo;
|
||||
ChunksList m_chunks;
|
||||
int m_size;
|
||||
};
|
||||
|
||||
#endif
|
47
src/undo/undoer.h
Normal file
47
src/undo/undoer.h
Normal file
@ -0,0 +1,47 @@
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_UNDOER_H_INCLUDED
|
||||
#define UNDO_UNDOER_H_INCLUDED
|
||||
|
||||
namespace undo {
|
||||
|
||||
class ObjectsContainer;
|
||||
class UndoersCollector;
|
||||
|
||||
// Generic interface to undo/revert an action.
|
||||
class Undoer
|
||||
{
|
||||
public:
|
||||
virtual ~Undoer() { }
|
||||
|
||||
// Used to destroy the undoer when it is not needed anymore. A
|
||||
// undoer is added in UndoersCollector, and then destroyed by
|
||||
// UndoHistory using this method.
|
||||
//
|
||||
// This method is available because the Undo library does not know
|
||||
// how this Undoer was created. So we cannot call just "delete undoer".
|
||||
virtual void dispose() = 0;
|
||||
|
||||
// Returns the amount of memory (in bytes) which this instance is
|
||||
// using to revert the action.
|
||||
virtual int getMemSize() const = 0;
|
||||
|
||||
// Returns true if this undoer is the first action of a group.
|
||||
virtual bool isOpenGroup() const = 0;
|
||||
|
||||
// Returns true if this undoer is the last action of a group.
|
||||
virtual bool isCloseGroup() const = 0;
|
||||
|
||||
// Reverts the action and adds to the "redoers" stack other set of
|
||||
// actions to redo the reverted action. It is the main method used
|
||||
// to undo any action.
|
||||
virtual void revert(ObjectsContainer* objects, UndoersCollector* redoers) = 0;
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_UNDOER_H_INCLUDED
|
33
src/undo/undoers_collector.h
Normal file
33
src/undo/undoers_collector.h
Normal file
@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_UNDOERS_COLLECTOR_H_INCLUDED
|
||||
#define UNDO_UNDOERS_COLLECTOR_H_INCLUDED
|
||||
|
||||
namespace undo {
|
||||
|
||||
class Undoer;
|
||||
class ObjectsContainer;
|
||||
|
||||
// Simple interface to collect undoers. It's implemented by
|
||||
// UndoHistory and UndoersStack.
|
||||
//
|
||||
// This class is passed to Undoer::revert() so the Undoer can add
|
||||
// operations (other Undoers) to redo the reverted operation.
|
||||
class UndoersCollector
|
||||
{
|
||||
public:
|
||||
virtual ~UndoersCollector() { }
|
||||
|
||||
// Adds a new undoer into the collection. The undoer will be owned
|
||||
// by the collector, so it will be deleted automatically (using
|
||||
// Undoer::dispose() method).
|
||||
virtual void pushUndoer(Undoer* undoer) = 0;
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_UNDOERS_COLLECTOR_H_INCLUDED
|
138
src/undo/undoers_stack.cpp
Normal file
138
src/undo/undoers_stack.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
// 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/undoers_stack.h"
|
||||
|
||||
#include "undo/undo_history.h"
|
||||
#include "undo/undoer.h"
|
||||
|
||||
using namespace undo;
|
||||
|
||||
UndoersStack::UndoersStack(UndoHistory* undoHistory)
|
||||
{
|
||||
m_undoHistory = undoHistory;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
UndoersStack::~UndoersStack()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void UndoersStack::clear()
|
||||
{
|
||||
for (iterator it = begin(), end = this->end(); it != end; ++it) {
|
||||
(*it)->getUndoer()->dispose(); // Delete the Undoer.
|
||||
delete *it; // Delete the UndoersStack::Item.
|
||||
}
|
||||
|
||||
m_size = 0;
|
||||
m_items.clear(); // Clear the list of items.
|
||||
}
|
||||
|
||||
int UndoersStack::getMemSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
ObjectsContainer* UndoersStack::getObjects() const
|
||||
{
|
||||
return m_undoHistory->getObjects();
|
||||
}
|
||||
|
||||
void UndoersStack::pushUndoer(Undoer* undoer)
|
||||
{
|
||||
ASSERT(undoer != NULL);
|
||||
|
||||
try {
|
||||
Item* item = new Item(m_undoHistory->getLabel(), undoer);
|
||||
try {
|
||||
m_items.insert(begin(), item);
|
||||
}
|
||||
catch (...) {
|
||||
delete item;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
undoer->dispose();
|
||||
throw;
|
||||
}
|
||||
|
||||
m_size += undoer->getMemSize();
|
||||
}
|
||||
|
||||
Undoer* UndoersStack::popUndoer(PopFrom popFrom)
|
||||
{
|
||||
Undoer* undoer;
|
||||
iterator it;
|
||||
|
||||
if (!empty()) {
|
||||
if (popFrom == PopFromHead)
|
||||
it = begin();
|
||||
else
|
||||
it = --end();
|
||||
|
||||
undoer = (*it)->getUndoer(); // Set the undoer to return.
|
||||
delete *it; // Delete the UndoersStack::Item.
|
||||
m_items.erase(it); // Erase the item from the stack.
|
||||
m_size -= undoer->getMemSize(); // Reduce the stack size.
|
||||
}
|
||||
else
|
||||
undoer = NULL;
|
||||
|
||||
return undoer;
|
||||
}
|
||||
|
||||
int UndoersStack::countUndoGroups() const
|
||||
{
|
||||
int groups = 0;
|
||||
int level;
|
||||
|
||||
const_iterator it = begin();
|
||||
while (it != end()) {
|
||||
level = 0;
|
||||
|
||||
do {
|
||||
const Undoer* undoer = (*it)->getUndoer();
|
||||
++it;
|
||||
|
||||
if (undoer->isOpenGroup())
|
||||
level++;
|
||||
else if (undoer->isCloseGroup())
|
||||
level--;
|
||||
} while (level && (it != end()));
|
||||
|
||||
if (level == 0)
|
||||
groups++;
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
bool UndoersStack::isOutOfGroup() const
|
||||
{
|
||||
int level = 0;
|
||||
|
||||
const_iterator it = begin();
|
||||
while (it != end()) {
|
||||
level = 0;
|
||||
|
||||
do {
|
||||
const Undoer* undoer = (*it)->getUndoer();
|
||||
++it;
|
||||
|
||||
if (undoer->isOpenGroup())
|
||||
level++;
|
||||
else if (undoer->isCloseGroup())
|
||||
level--;
|
||||
} while (level && (it != end()));
|
||||
}
|
||||
|
||||
return level == 0;
|
||||
}
|
87
src/undo/undoers_stack.h
Normal file
87
src/undo/undoers_stack.h
Normal file
@ -0,0 +1,87 @@
|
||||
// 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.
|
||||
|
||||
#ifndef UNDO_UNDOERS_STACK_H_INCLUDED
|
||||
#define UNDO_UNDOERS_STACK_H_INCLUDED
|
||||
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace undo {
|
||||
|
||||
class UndoHistory;
|
||||
class Undoer;
|
||||
|
||||
// A stack of undoable actions (Undoers). There exist two stacks (see
|
||||
// the UndoHistory class): One stack to hold actions to be undone (the
|
||||
// "undoers stack"), and another stack were actions are held to redo
|
||||
// reverted actions (the "redoers stack").
|
||||
class UndoersStack : public UndoersCollector
|
||||
{
|
||||
public:
|
||||
enum PopFrom {
|
||||
PopFromHead,
|
||||
PopFromTail
|
||||
};
|
||||
|
||||
// One item in the stack (label + Undoer)
|
||||
class Item
|
||||
{
|
||||
public:
|
||||
Item(const char* label, Undoer* undoer)
|
||||
: m_label(label)
|
||||
, m_undoer(undoer) { }
|
||||
const char* getLabel() const { return m_label; }
|
||||
Undoer* getUndoer() const { return m_undoer; }
|
||||
|
||||
private:
|
||||
const char* m_label;
|
||||
Undoer* m_undoer;
|
||||
};
|
||||
|
||||
typedef std::vector<Item*> Items;
|
||||
typedef Items::iterator iterator;
|
||||
typedef Items::const_iterator const_iterator;
|
||||
|
||||
// Ctor and dtor
|
||||
UndoersStack(UndoHistory* undoHistory);
|
||||
~UndoersStack();
|
||||
|
||||
UndoHistory* getUndoHistory() const { return m_undoHistory; }
|
||||
|
||||
// Returns the collection of well-known serialized objects.
|
||||
ObjectsContainer* getObjects() const;
|
||||
|
||||
iterator begin() { return m_items.begin(); }
|
||||
iterator end() { return m_items.end(); }
|
||||
const_iterator begin() const { return m_items.begin(); }
|
||||
const_iterator end() const { return m_items.end(); }
|
||||
bool empty() const { return m_items.empty(); }
|
||||
|
||||
void clear();
|
||||
|
||||
int getMemSize() const;
|
||||
|
||||
// UndoersCollector implementation
|
||||
void pushUndoer(Undoer* undoer);
|
||||
|
||||
// Removes a undoer from the stack, the returned undoer must be
|
||||
// deleted by the caller using Undoer::dispose().
|
||||
Undoer* popUndoer(PopFrom popFrom);
|
||||
|
||||
int countUndoGroups() const;
|
||||
bool isOutOfGroup() const;
|
||||
|
||||
private:
|
||||
UndoHistory* m_undoHistory;
|
||||
Items m_items;
|
||||
int m_size;
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_UNDOERS_STACK_H_INCLUDED
|
@ -1044,9 +1044,8 @@ void UndoTransaction::setMaskPosition(int x, int y)
|
||||
|
||||
void UndoTransaction::deselectMask()
|
||||
{
|
||||
// TODO IMPLEMENT THIS (add support to save values in UndoHistory from any object)
|
||||
// if (isEnabled())
|
||||
// m_undoHistory->undo_int(m_document);
|
||||
if (isEnabled())
|
||||
m_undoHistory->undo_set_mask(m_document);
|
||||
|
||||
m_document->setMaskVisible(false);
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ class Layer;
|
||||
class LayerImage;
|
||||
class Mask;
|
||||
class Sprite;
|
||||
class UndoHistory;
|
||||
|
||||
namespace undo {
|
||||
class UndoHistory;
|
||||
}
|
||||
|
||||
// High-level class to group a set of operations to modify the
|
||||
// document atomically, adding information in the undo history to
|
||||
@ -127,7 +130,7 @@ public:
|
||||
private:
|
||||
Document* m_document;
|
||||
Sprite* m_sprite;
|
||||
UndoHistory* m_undoHistory;
|
||||
undo::UndoHistory* m_undoHistory;
|
||||
bool m_committed;
|
||||
bool m_enabledFlag;
|
||||
};
|
||||
|
52
src/undoers/add_cel.cpp
Normal file
52
src/undoers/add_cel.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/add_cel.h"
|
||||
|
||||
#include "raster/cel.h"
|
||||
#include "raster/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/remove_cel.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
AddCel::AddCel(ObjectsContainer* objects, Layer* layer, Cel* cel)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
, m_celId(objects->addObject(cel))
|
||||
{
|
||||
}
|
||||
|
||||
void AddCel::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void AddCel::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
LayerImage* layer = objects->getObjectT<LayerImage>(m_layerId);
|
||||
Cel* cel = objects->getObjectT<Cel>(m_celId);
|
||||
|
||||
redoers->pushUndoer(new RemoveCel(objects, layer, cel));
|
||||
|
||||
layer->removeCel(cel);
|
||||
cel_free(cel);
|
||||
}
|
46
src/undoers/add_cel.h
Normal file
46
src/undoers/add_cel.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_ADD_CEL_H_INCLUDED
|
||||
#define UNDOERS_ADD_CEL_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Cel;
|
||||
class Layer;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class AddCel : public UndoerBase
|
||||
{
|
||||
public:
|
||||
AddCel(undo::ObjectsContainer* objects, Layer* layer, Cel* cel);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_layerId;
|
||||
undo::ObjectId m_celId;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_ADD_CEL_H_INCLUDED
|
56
src/undoers/add_image.cpp
Normal file
56
src/undoers/add_image.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/add_image.h"
|
||||
|
||||
#include "raster/image.h"
|
||||
#include "raster/stock.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undo_exception.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/remove_image.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
AddImage::AddImage(ObjectsContainer* objects, Stock* stock, int imageIndex)
|
||||
: m_stockId(objects->addObject(stock))
|
||||
, m_imageIndex(imageIndex)
|
||||
{
|
||||
}
|
||||
|
||||
void AddImage::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void AddImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Stock* stock = objects->getObjectT<Stock>(m_stockId);
|
||||
Image* image = stock->getImage(m_imageIndex);
|
||||
|
||||
if (image == NULL)
|
||||
throw UndoException("One image was not found in the stock");
|
||||
|
||||
redoers->pushUndoer(new RemoveImage(objects, stock, m_imageIndex));
|
||||
|
||||
stock->removeImage(image);
|
||||
delete image;
|
||||
}
|
45
src/undoers/add_image.h
Normal file
45
src/undoers/add_image.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_ADD_IMAGE_H_INCLUDED
|
||||
#define UNDOERS_ADD_IMAGE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Stock;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class AddImage : public UndoerBase
|
||||
{
|
||||
public:
|
||||
AddImage(undo::ObjectsContainer* objects, Stock* stock, int imageIndex);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_stockId;
|
||||
uint32_t m_imageIndex;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_ADD_IMAGE_H_INCLUDED
|
51
src/undoers/add_layer.cpp
Normal file
51
src/undoers/add_layer.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/add_layer.h"
|
||||
|
||||
#include "raster/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/remove_layer.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
AddLayer::AddLayer(ObjectsContainer* objects, Layer* folder, Layer* layer)
|
||||
: m_folderId(objects->addObject(folder))
|
||||
, m_layerId(objects->addObject(layer))
|
||||
{
|
||||
}
|
||||
|
||||
void AddLayer::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void AddLayer::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
LayerFolder* folder = objects->getObjectT<LayerFolder>(m_folderId);
|
||||
Layer* layer = objects->getObjectT<Layer>(m_layerId);
|
||||
|
||||
redoers->pushUndoer(new RemoveLayer(objects, layer));
|
||||
|
||||
folder->remove_layer(layer);
|
||||
delete layer;
|
||||
}
|
45
src/undoers/add_layer.h
Normal file
45
src/undoers/add_layer.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_ADD_LAYER_H_INCLUDED
|
||||
#define UNDOERS_ADD_LAYER_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Layer;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class AddLayer : public UndoerBase
|
||||
{
|
||||
public:
|
||||
AddLayer(undo::ObjectsContainer* objects, Layer* folder, Layer* layer);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_folderId;
|
||||
undo::ObjectId m_layerId;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_ADD_LAYER_H_INCLUDED
|
50
src/undoers/add_palette.cpp
Normal file
50
src/undoers/add_palette.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/add_palette.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/remove_palette.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
AddPalette::AddPalette(ObjectsContainer* objects, Sprite* sprite, Palette* palette)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_paletteId(objects->addObject(palette))
|
||||
{
|
||||
}
|
||||
|
||||
void AddPalette::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void AddPalette::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
Palette* palette = objects->getObjectT<Palette>(m_paletteId);
|
||||
|
||||
redoers->pushUndoer(new RemovePalette(objects, sprite, palette));
|
||||
|
||||
sprite->deletePalette(palette);
|
||||
}
|
46
src/undoers/add_palette.h
Normal file
46
src/undoers/add_palette.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
#define UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Palette;
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class AddPalette : public UndoerBase
|
||||
{
|
||||
public:
|
||||
AddPalette(undo::ObjectsContainer* objects, Sprite* sprite, Palette* palette);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
undo::ObjectId m_paletteId;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_ADD_PALETTE_H_INCLUDED
|
37
src/undoers/close_group.cpp
Normal file
37
src/undoers/close_group.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/close_group.h"
|
||||
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/open_group.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
void CloseGroup::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CloseGroup::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
redoers->pushUndoer(new OpenGroup());
|
||||
}
|
39
src/undoers/close_group.h
Normal file
39
src/undoers/close_group.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_CLOSE_GROUP_H_INCLUDED
|
||||
#define UNDOERS_CLOSE_GROUP_H_INCLUDED
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "undo/undoer.h"
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class CloseGroup : public undo::Undoer
|
||||
{
|
||||
public:
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
bool isOpenGroup() const OVERRIDE { return false; }
|
||||
bool isCloseGroup() const OVERRIDE { return true; }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_CLOSE_GROUP_H_INCLUDED
|
55
src/undoers/dirty_area.cpp
Normal file
55
src/undoers/dirty_area.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/dirty_area.h"
|
||||
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/dirty.h"
|
||||
#include "raster/dirty_io.h"
|
||||
#include "raster/image.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
DirtyArea::DirtyArea(ObjectsContainer* objects, Image* image, Dirty* dirty)
|
||||
: m_imageId(objects->addObject(image))
|
||||
{
|
||||
raster::write_dirty(m_stream, dirty);
|
||||
}
|
||||
|
||||
void DirtyArea::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void DirtyArea::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Image* image = objects->getObjectT<Image>(m_imageId);
|
||||
UniquePtr<Dirty> dirty(raster::read_dirty(m_stream));
|
||||
|
||||
// Swap the saved pixels in the dirty with the pixels in the image
|
||||
dirty->swapImagePixels(image);
|
||||
|
||||
// Save the dirty in the "redoers" (the dirty area now contains the
|
||||
// pixels before the undo)
|
||||
redoers->pushUndoer(new DirtyArea(objects, image, dirty));
|
||||
}
|
52
src/undoers/dirty_area.h
Normal file
52
src/undoers/dirty_area.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_DIRTY_AREA_H_INCLUDED
|
||||
#define UNDOERS_DIRTY_AREA_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Dirty;
|
||||
class Image;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class DirtyArea : public UndoerBase
|
||||
{
|
||||
public:
|
||||
DirtyArea(undo::ObjectsContainer* objects, Image* image, Dirty* dirty);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_imageId;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_DIRTY_AREA_H_INCLUDED
|
67
src/undoers/flip_image.cpp
Normal file
67
src/undoers/flip_image.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/flip_image.h"
|
||||
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/image.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undo_exception.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
FlipImage::FlipImage(ObjectsContainer* objects, Image* image, int x, int y, int w, int h, FlipType flipType)
|
||||
: m_imageId(objects->addObject(image))
|
||||
, m_imgtype(image->imgtype)
|
||||
, m_x(x), m_y(y), m_w(w), m_h(h)
|
||||
, m_flipType(flipType)
|
||||
{
|
||||
ASSERT(w >= 1 && h >= 1);
|
||||
ASSERT(x >= 0 && y >= 0 && x+w <= image->w && y+h <= image->h);
|
||||
}
|
||||
|
||||
void FlipImage::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void FlipImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Image* image = objects->getObjectT<Image>(m_imageId);
|
||||
|
||||
if (image->imgtype != m_imgtype)
|
||||
throw UndoException("Image type does not match");
|
||||
|
||||
redoers->pushUndoer(new FlipImage(objects, image, m_x, m_y, m_w, m_h, m_flipType));
|
||||
|
||||
UniquePtr<Image> area(image_crop(image, m_x, m_y, m_w, m_h, 0));
|
||||
int x, y;
|
||||
int x2 = m_x+m_w-1;
|
||||
int y2 = m_y+m_h-1;
|
||||
|
||||
for (y=0; y<m_h; ++y)
|
||||
for (x=0; x<m_w; ++x)
|
||||
image_putpixel(image,
|
||||
m_flipType == FlipHorizontal ? x2-x: m_x+x,
|
||||
m_flipType == FlipVertical ? y2-y: m_y+y,
|
||||
image_getpixel(area, x, y));
|
||||
}
|
49
src/undoers/flip_image.h
Normal file
49
src/undoers/flip_image.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_FLIP_IMAGE_H_INCLUDED
|
||||
#define UNDOERS_FLIP_IMAGE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Image;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class FlipImage : public UndoerBase
|
||||
{
|
||||
public:
|
||||
enum FlipType { FlipHorizontal, FlipVertical };
|
||||
|
||||
FlipImage(undo::ObjectsContainer* objects, Image* image, int x, int y, int w, int h, FlipType flipType);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_imageId;
|
||||
uint8_t m_imgtype;
|
||||
uint16_t m_x, m_y, m_w, m_h;
|
||||
FlipType m_flipType;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_FLIP_IMAGE_H_INCLUDED
|
63
src/undoers/image_area.cpp
Normal file
63
src/undoers/image_area.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/image_area.h"
|
||||
|
||||
#include "raster/image.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undo_exception.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
ImageArea::ImageArea(ObjectsContainer* objects, Image* image, int x, int y, int w, int h)
|
||||
: m_imageId(objects->addObject(image))
|
||||
, m_imgtype(image->imgtype)
|
||||
, m_x(x), m_y(y), m_w(w), m_h(h)
|
||||
, m_lineSize(image_line_size(image, w))
|
||||
, m_data(m_lineSize * h)
|
||||
{
|
||||
ASSERT(w >= 1 && h >= 1);
|
||||
ASSERT(x >= 0 && y >= 0 && x+w <= image->w && y+h <= image->h);
|
||||
|
||||
for (int v=0; v<h; ++v)
|
||||
memcpy(&m_data[m_lineSize*v], image_address(image, x, y+v), m_lineSize);
|
||||
}
|
||||
|
||||
void ImageArea::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void ImageArea::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Image* image = objects->getObjectT<Image>(m_imageId);
|
||||
|
||||
if (image->imgtype != m_imgtype)
|
||||
throw UndoException("Image type does not match");
|
||||
|
||||
// Backup the current image portion
|
||||
redoers->pushUndoer(new ImageArea(objects, image, m_x, m_y, m_w, m_h));
|
||||
|
||||
// Restore the old image portion
|
||||
for (int v=0; v<m_h; ++v)
|
||||
memcpy(image_address(image, m_x, m_y+v), &m_data[m_lineSize*v], m_lineSize);
|
||||
}
|
50
src/undoers/image_area.h
Normal file
50
src/undoers/image_area.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_IMAGE_AREA_H_INCLUDED
|
||||
#define UNDOERS_IMAGE_AREA_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Image;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class ImageArea : public UndoerBase
|
||||
{
|
||||
public:
|
||||
ImageArea(undo::ObjectsContainer* objects, Image* image, int x, int y, int w, int h);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + m_data.size(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_imageId;
|
||||
uint8_t m_imgtype;
|
||||
uint16_t m_x, m_y, m_w, m_h;
|
||||
uint32_t m_lineSize;
|
||||
std::vector<uint8_t> m_data;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_IMAGE_AREA_H_INCLUDED
|
55
src/undoers/move_layer.cpp
Normal file
55
src/undoers/move_layer.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/move_layer.h"
|
||||
|
||||
#include "raster/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
MoveLayer::MoveLayer(ObjectsContainer* objects, Layer* layer)
|
||||
: m_folderId(objects->addObject(layer->get_parent()))
|
||||
, m_layerId(objects->addObject(layer))
|
||||
{
|
||||
Layer* after = layer->get_prev();
|
||||
|
||||
m_afterId = (after ? objects->addObject(after): 0);
|
||||
}
|
||||
|
||||
void MoveLayer::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void MoveLayer::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
LayerFolder* folder = objects->getObjectT<LayerFolder>(m_folderId);
|
||||
Layer* layer = objects->getObjectT<Layer>(m_layerId);
|
||||
Layer* after = (m_afterId ? objects->getObjectT<Layer>(m_afterId): NULL);
|
||||
|
||||
// Backup the current layer position
|
||||
redoers->pushUndoer(new MoveLayer(objects, layer));
|
||||
|
||||
// Move the layer
|
||||
folder->move_layer(layer, after);
|
||||
}
|
46
src/undoers/move_layer.h
Normal file
46
src/undoers/move_layer.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_MOVE_LAYER_H_INCLUDED
|
||||
#define UNDOERS_MOVE_LAYER_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Layer;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class MoveLayer : public UndoerBase
|
||||
{
|
||||
public:
|
||||
MoveLayer(undo::ObjectsContainer* objects, Layer* layer);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_folderId;
|
||||
undo::ObjectId m_layerId;
|
||||
undo::ObjectId m_afterId;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_MOVE_LAYER_H_INCLUDED
|
71
src/undoers/object_io.h
Normal file
71
src/undoers/object_io.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_OBJECT_IO_H_INCLUDED
|
||||
#define UNDOERS_OBJECT_IO_H_INCLUDED
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
|
||||
namespace undo {
|
||||
class ObjectsContainer;
|
||||
}
|
||||
|
||||
namespace undoers {
|
||||
|
||||
// read_object and write_object functions can be used to serialize an
|
||||
// object into a stream, and restore it back into the memory with the
|
||||
// same ID which were assigned in the ObjectsContainer previously.
|
||||
|
||||
// Serializes the given object into the stream identifying it with an
|
||||
// ID from the ObjectsContainer. When the object is deserialized with
|
||||
// read_object, the object is added to the container with the same ID.
|
||||
template<class T, class Writer>
|
||||
void write_object(undo::ObjectsContainer* objects, std::ostream& os, T* object, Writer& writer)
|
||||
{
|
||||
using base::serialization::little_endian::write32;
|
||||
|
||||
// Get an ID for the image.
|
||||
undo::ObjectId objectId = objects->addObject(object);
|
||||
|
||||
write32(os, objectId); // Write the ID
|
||||
writer(os, object); // Write the object
|
||||
|
||||
// Remove the object from the container (it will be
|
||||
// re-added by a undoers::read_object call).
|
||||
objects->removeObject(objectId);
|
||||
}
|
||||
|
||||
// Deserializes the given object from the stream, adding the object
|
||||
// into the ObjectsContainer with the same ID saved with write_object().
|
||||
template<class T, class Reader>
|
||||
T* read_object(undo::ObjectsContainer* objects, std::istream& is, Reader& reader)
|
||||
{
|
||||
using base::serialization::little_endian::read32;
|
||||
|
||||
undo::ObjectId objectId = read32(is); // Read the ID
|
||||
UniquePtr<T> object(reader(is)); // Read the object
|
||||
|
||||
// Re-insert the object in the container with the read ID.
|
||||
objects->insertObject(objectId, object);
|
||||
return object.release();
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_OBJECT_IO_H_INCLUDED
|
37
src/undoers/open_group.cpp
Normal file
37
src/undoers/open_group.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/open_group.h"
|
||||
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/close_group.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
void OpenGroup::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void OpenGroup::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
redoers->pushUndoer(new CloseGroup());
|
||||
}
|
39
src/undoers/open_group.h
Normal file
39
src/undoers/open_group.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_OPEN_GROUP_H_INCLUDED
|
||||
#define UNDOERS_OPEN_GROUP_H_INCLUDED
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "undo/undoer.h"
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class OpenGroup : public undo::Undoer
|
||||
{
|
||||
public:
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
bool isOpenGroup() const OVERRIDE { return true; }
|
||||
bool isCloseGroup() const OVERRIDE { return false; }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_OPEN_GROUP_H_INCLUDED
|
52
src/undoers/raw_data.cpp
Normal file
52
src/undoers/raw_data.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/raw_data.h"
|
||||
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RawData::RawData(ObjectsContainer* objects, void* object, void* fieldAddress, int fieldSize)
|
||||
: m_objectId(objects->addObject(object))
|
||||
, m_offset((uint32_t)(((uint8_t*)fieldAddress) - ((uint8_t*)object)))
|
||||
, m_data(fieldSize)
|
||||
{
|
||||
memcpy(&m_data[0], fieldAddress, m_data.size());
|
||||
}
|
||||
|
||||
void RawData::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RawData::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
void* object = objects->getObject(m_objectId);
|
||||
void* fieldAddress = (void*)(((uint8_t*)object) + m_offset);
|
||||
|
||||
// Save the current data
|
||||
redoers->pushUndoer(new RawData(objects, object, fieldAddress, m_data.size()));
|
||||
|
||||
// Copy back the old data
|
||||
memcpy(fieldAddress, &m_data[0], m_data.size());
|
||||
}
|
46
src/undoers/raw_data.h
Normal file
46
src/undoers/raw_data.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_RAW_DATA_H_INCLUDED
|
||||
#define UNDOERS_RAW_DATA_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class RawData : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RawData(undo::ObjectsContainer* objects, void* object, void* fieldAddress, int fieldSize);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + m_data.size(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_objectId;
|
||||
uint32_t m_offset;
|
||||
std::vector<uint8_t> m_data;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_RAW_DATA_H_INCLUDED
|
60
src/undoers/remap_palette.cpp
Normal file
60
src/undoers/remap_palette.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/remap_palette.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/add_cel.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RemapPalette::RemapPalette(ObjectsContainer* objects, Sprite* sprite, int frameFrom, int frameTo, const std::vector<uint8_t>& mapping)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_frameFrom(frameFrom)
|
||||
, m_frameTo(frameTo)
|
||||
, m_mapping(mapping)
|
||||
{
|
||||
ASSERT(mapping.size() == 256 && "Mapping tables must have 256 entries");
|
||||
}
|
||||
|
||||
void RemapPalette::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RemapPalette::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Inverse mapping
|
||||
std::vector<uint8_t> inverse_mapping(m_mapping.size());
|
||||
for (size_t c=0; c<m_mapping.size(); ++c)
|
||||
inverse_mapping[m_mapping[c]] = c;
|
||||
|
||||
// Push an RemapPalette as redoer
|
||||
redoers->pushUndoer(new RemapPalette(objects, sprite, m_frameFrom, m_frameTo, inverse_mapping));
|
||||
|
||||
// Remap in inverse order
|
||||
sprite->remapImages(m_frameFrom, m_frameTo, inverse_mapping);
|
||||
}
|
49
src/undoers/remap_palette.h
Normal file
49
src/undoers/remap_palette.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_REMAP_PALETTE_H_INCLUDED
|
||||
#define UNDOERS_REMAP_PALETTE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class RemapPalette : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemapPalette(undo::ObjectsContainer* objects, Sprite* sprite, int frameFrom, int frameTo, const std::vector<uint8_t>& mapping);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frameFrom;
|
||||
uint32_t m_frameTo;
|
||||
std::vector<uint8_t> m_mapping;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_REMAP_PALETTE_H_INCLUDED
|
55
src/undoers/remove_cel.cpp
Normal file
55
src/undoers/remove_cel.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/remove_cel.h"
|
||||
|
||||
#include "raster/cel.h"
|
||||
#include "raster/cel_io.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/stock.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/add_cel.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RemoveCel::RemoveCel(ObjectsContainer* objects, Layer* layer, Cel* cel)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
{
|
||||
write_object(objects, m_stream, cel, raster::write_cel);
|
||||
}
|
||||
|
||||
void RemoveCel::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RemoveCel::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
LayerImage* layer = objects->getObjectT<LayerImage>(m_layerId);
|
||||
Cel* cel = read_object<Cel>(objects, m_stream, raster::read_cel);
|
||||
|
||||
// Push an AddCel as redoer
|
||||
redoers->pushUndoer(new AddCel(objects, layer, cel));
|
||||
|
||||
layer->addCel(cel);
|
||||
}
|
52
src/undoers/remove_cel.h
Normal file
52
src/undoers/remove_cel.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_REMOVE_CEL_H_INCLUDED
|
||||
#define UNDOERS_REMOVE_CEL_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Cel;
|
||||
class Layer;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class RemoveCel : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemoveCel(undo::ObjectsContainer* objects, Layer* layer, Cel* cel);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_layerId;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_REMOVE_CEL_H_INCLUDED
|
57
src/undoers/remove_image.cpp
Normal file
57
src/undoers/remove_image.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/remove_image.h"
|
||||
|
||||
#include "raster/image.h"
|
||||
#include "raster/image_io.h"
|
||||
#include "raster/stock.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/add_image.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RemoveImage::RemoveImage(ObjectsContainer* objects, Stock* stock, int imageIndex)
|
||||
: m_stockId(objects->addObject(stock))
|
||||
, m_imageIndex(imageIndex)
|
||||
{
|
||||
Image* image = stock->getImage(imageIndex);
|
||||
|
||||
write_object(objects, m_stream, image, raster::write_image);
|
||||
}
|
||||
|
||||
void RemoveImage::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RemoveImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Stock* stock = objects->getObjectT<Stock>(m_stockId);
|
||||
Image* image = read_object<Image>(objects, m_stream, raster::read_image);
|
||||
|
||||
// Push an AddImage as redoer
|
||||
redoers->pushUndoer(new AddImage(objects, stock, m_imageIndex));
|
||||
|
||||
stock->replaceImage(m_imageIndex, image);
|
||||
}
|
52
src/undoers/remove_image.h
Normal file
52
src/undoers/remove_image.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_REMOVE_IMAGE_H_INCLUDED
|
||||
#define UNDOERS_REMOVE_IMAGE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Stock;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class RemoveImage : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemoveImage(undo::ObjectsContainer* objects, Stock* stock, int imageIndex);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_stockId;
|
||||
uint32_t m_imageIndex;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_REMOVE_IMAGE_H_INCLUDED
|
120
src/undoers/remove_layer.cpp
Normal file
120
src/undoers/remove_layer.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/remove_layer.h"
|
||||
|
||||
#include "raster/cel.h"
|
||||
#include "raster/cel_io.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/image_io.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/layer_io.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/add_layer.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
class LayerSubObjectsSerializerImpl : public raster::LayerSubObjectsSerializer
|
||||
{
|
||||
public:
|
||||
LayerSubObjectsSerializerImpl(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_objects(objects)
|
||||
, m_sprite(sprite) {
|
||||
}
|
||||
|
||||
virtual ~LayerSubObjectsSerializerImpl() { }
|
||||
|
||||
// How to write cels, images, and sub-layers
|
||||
void write_cel(std::ostream& os, Cel* cel) OVERRIDE {
|
||||
write_object(m_objects, os, cel, raster::write_cel);
|
||||
}
|
||||
|
||||
void write_image(std::ostream& os, Image* image) OVERRIDE {
|
||||
write_object(m_objects, os, image, raster::write_image);
|
||||
}
|
||||
|
||||
void write_layer(std::ostream& os, Layer* layer) OVERRIDE {
|
||||
// To write a sub-layer we use the operator() of this instance (*this)
|
||||
write_object(m_objects, os, layer, *this);
|
||||
}
|
||||
|
||||
// How to read cels, images, and sub-layers
|
||||
Cel* read_cel(std::istream& is) OVERRIDE {
|
||||
return read_object<Cel>(m_objects, is, raster::read_cel);
|
||||
}
|
||||
|
||||
Image* read_image(std::istream& is) OVERRIDE {
|
||||
return read_object<Image>(m_objects, is, raster::read_image);
|
||||
}
|
||||
|
||||
Layer* read_layer(std::istream& is) OVERRIDE {
|
||||
// To read a sub-layer we use the operator() of this instance (*this)
|
||||
return read_object<Layer>(m_objects, is, *this);
|
||||
}
|
||||
|
||||
// The following operator() calls are used in write/read_object() functions.
|
||||
|
||||
void operator()(std::ostream& os, Layer* layer) {
|
||||
raster::write_layer(os, this, layer);
|
||||
}
|
||||
|
||||
Layer* operator()(std::istream& is) {
|
||||
return raster::read_layer(is, this, m_sprite);
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectsContainer* m_objects;
|
||||
Sprite* m_sprite;
|
||||
};
|
||||
|
||||
RemoveLayer::RemoveLayer(ObjectsContainer* objects, Layer* layer)
|
||||
: m_folderId(objects->addObject(layer->get_parent()))
|
||||
{
|
||||
Layer* after = layer->get_prev();
|
||||
|
||||
m_afterId = (after ? objects->addObject(after): 0);
|
||||
|
||||
LayerSubObjectsSerializerImpl serializer(objects, layer->getSprite());
|
||||
write_object(objects, m_stream, layer, serializer);
|
||||
}
|
||||
|
||||
void RemoveLayer::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RemoveLayer::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
LayerFolder* folder = objects->getObjectT<LayerFolder>(m_folderId);
|
||||
Layer* after = (m_afterId != 0 ? objects->getObjectT<Layer>(m_afterId): NULL);
|
||||
|
||||
// Read the layer from the stream
|
||||
LayerSubObjectsSerializerImpl serializer(objects, folder->getSprite());
|
||||
Layer* layer = read_object<Layer>(objects, m_stream, serializer);
|
||||
|
||||
// Push an AddLayer as redoer
|
||||
redoers->pushUndoer(new AddLayer(objects, folder, layer));
|
||||
|
||||
folder->add_layer(layer);
|
||||
folder->move_layer(layer, after);
|
||||
}
|
52
src/undoers/remove_layer.h
Normal file
52
src/undoers/remove_layer.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_REMOVE_LAYER_H_INCLUDED
|
||||
#define UNDOERS_REMOVE_LAYER_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Layer;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class RemoveLayer : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemoveLayer(undo::ObjectsContainer* objects, Layer* layer);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_folderId;
|
||||
undo::ObjectId m_afterId;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_REMOVE_LAYER_H_INCLUDED
|
57
src/undoers/remove_palette.cpp
Normal file
57
src/undoers/remove_palette.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/remove_palette.h"
|
||||
|
||||
#include "raster/palette.h"
|
||||
#include "raster/palette_io.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/add_palette.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RemovePalette::RemovePalette(ObjectsContainer* objects, Sprite* sprite, Palette* palette)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
{
|
||||
write_object(objects, m_stream, palette, raster::write_palette);
|
||||
}
|
||||
|
||||
void RemovePalette::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RemovePalette::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
UniquePtr<Palette> palette(read_object<Palette>(objects, m_stream, raster::read_palette));
|
||||
|
||||
// Push an AddPalette as redoer
|
||||
redoers->pushUndoer(new AddPalette(objects, sprite, palette));
|
||||
|
||||
sprite->setPalette(palette, true);
|
||||
|
||||
// Here the palette is deleted by UniquePtr<>, it is needed becase
|
||||
// Sprite::setPalette() makes a copy of the given palette.
|
||||
}
|
52
src/undoers/remove_palette.h
Normal file
52
src/undoers/remove_palette.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_REMOVE_PALETTE_H_INCLUDED
|
||||
#define UNDOERS_REMOVE_PALETTE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Palette;
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class RemovePalette : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemovePalette(undo::ObjectsContainer* objects, Sprite* sprite, Palette* palette);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_spriteId;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_REMOVE_PALETTE_H_INCLUDED
|
63
src/undoers/replace_image.cpp
Normal file
63
src/undoers/replace_image.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/replace_image.h"
|
||||
|
||||
#include "raster/image.h"
|
||||
#include "raster/image_io.h"
|
||||
#include "raster/stock.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
ReplaceImage::ReplaceImage(ObjectsContainer* objects, Stock* stock, int imageIndex)
|
||||
: m_stockId(objects->addObject(stock))
|
||||
, m_imageIndex(imageIndex)
|
||||
{
|
||||
Image* image = stock->getImage(imageIndex);
|
||||
|
||||
write_object(objects, m_stream, image, raster::write_image);
|
||||
}
|
||||
|
||||
void ReplaceImage::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void ReplaceImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Stock* stock = objects->getObjectT<Stock>(m_stockId);
|
||||
|
||||
// Read the image to be restored from the stream
|
||||
Image* image = read_object<Image>(objects, m_stream, raster::read_image);
|
||||
|
||||
// Save the current image in the redoers
|
||||
redoers->pushUndoer(new ReplaceImage(objects, stock, m_imageIndex));
|
||||
Image* oldImage = stock->getImage(m_imageIndex);
|
||||
|
||||
// Replace the image in the stock
|
||||
stock->replaceImage(m_imageIndex, image);
|
||||
|
||||
// destroy the old image
|
||||
image_free(oldImage);
|
||||
}
|
52
src/undoers/replace_image.h
Normal file
52
src/undoers/replace_image.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_REPLACE_IMAGE_H_INCLUDED
|
||||
#define UNDOERS_REPLACE_IMAGE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Stock;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class ReplaceImage : public UndoerBase
|
||||
{
|
||||
public:
|
||||
ReplaceImage(undo::ObjectsContainer* objects, Stock* stock, int imageIndex);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_stockId;
|
||||
uint32_t m_imageIndex;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_REPLACE_IMAGE_H_INCLUDED
|
49
src/undoers/set_current_frame.cpp
Normal file
49
src/undoers/set_current_frame.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_current_frame.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetCurrentFrame::SetCurrentFrame(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_frame(sprite->getCurrentFrame())
|
||||
{
|
||||
}
|
||||
|
||||
void SetCurrentFrame::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetCurrentFrame::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Push another SetCurrentFrame as redoer
|
||||
redoers->pushUndoer(new SetCurrentFrame(objects, sprite));
|
||||
|
||||
sprite->setCurrentFrame(m_frame);
|
||||
}
|
47
src/undoers/set_current_frame.h
Normal file
47
src/undoers/set_current_frame.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_CURRENT_FRAME_H_INCLUDED
|
||||
#define UNDOERS_SET_CURRENT_FRAME_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetCurrentFrame : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetCurrentFrame(undo::ObjectsContainer* objects, Sprite* sprite);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frame;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_CURRENT_FRAME_H_INCLUDED
|
50
src/undoers/set_current_layer.cpp
Normal file
50
src/undoers/set_current_layer.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_current_layer.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetCurrentLayer::SetCurrentLayer(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_layerId(sprite->getCurrentLayer() ? objects->addObject(sprite->getCurrentLayer()): 0)
|
||||
{
|
||||
}
|
||||
|
||||
void SetCurrentLayer::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetCurrentLayer::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
Layer* layer = (m_layerId ? objects->getObjectT<Layer>(m_layerId): NULL);
|
||||
|
||||
// Push another SetCurrentLayer as redoer
|
||||
redoers->pushUndoer(new SetCurrentLayer(objects, sprite));
|
||||
|
||||
sprite->setCurrentLayer(layer);
|
||||
}
|
47
src/undoers/set_current_layer.h
Normal file
47
src/undoers/set_current_layer.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_CURRENT_LAYER_H_INCLUDED
|
||||
#define UNDOERS_SET_CURRENT_LAYER_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetCurrentLayer : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetCurrentLayer(undo::ObjectsContainer* objects, Sprite* sprite);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
undo::ObjectId m_layerId;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_CURRENT_LAYER_H_INCLUDED
|
52
src/undoers/set_frame_duration.cpp
Normal file
52
src/undoers/set_frame_duration.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_frame_duration.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetFrameDuration::SetFrameDuration(ObjectsContainer* objects, Sprite* sprite, int frame)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_frame(frame)
|
||||
{
|
||||
ASSERT(frame >= 0 && frame < sprite->getTotalFrames());
|
||||
|
||||
m_duration = sprite->getFrameDuration(frame);
|
||||
}
|
||||
|
||||
void SetFrameDuration::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetFrameDuration::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Push another SetFrameDuration as redoer
|
||||
redoers->pushUndoer(new SetFrameDuration(objects, sprite, m_frame));
|
||||
|
||||
sprite->setFrameDuration(m_frame, m_duration);
|
||||
}
|
46
src/undoers/set_frame_duration.h
Normal file
46
src/undoers/set_frame_duration.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_FRAME_DURATION_H_INCLUDED
|
||||
#define UNDOERS_SET_FRAME_DURATION_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetFrameDuration : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetFrameDuration(undo::ObjectsContainer* objects, Sprite* sprite, int frame);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frame;
|
||||
uint32_t m_duration;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_FRAME_DURATION_H_INCLUDED
|
49
src/undoers/set_imgtype.cpp
Normal file
49
src/undoers/set_imgtype.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_imgtype.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetImgType::SetImgType(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_imgtype(sprite->getImgType())
|
||||
{
|
||||
}
|
||||
|
||||
void SetImgType::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Push another SetImgType as redoer
|
||||
redoers->pushUndoer(new SetImgType(objects, sprite));
|
||||
|
||||
sprite->setImgType(m_imgtype);
|
||||
}
|
45
src/undoers/set_imgtype.h
Normal file
45
src/undoers/set_imgtype.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_IMGTYPE_H_INCLUDED
|
||||
#define UNDOERS_SET_IMGTYPE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetImgType : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetImgType(undo::ObjectsContainer* objects, Sprite* sprite);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_imgtype;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_IMGTYPE_H_INCLUDED
|
49
src/undoers/set_layer_name.cpp
Normal file
49
src/undoers/set_layer_name.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_layer_name.h"
|
||||
|
||||
#include "raster/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetLayerName::SetLayerName(ObjectsContainer* objects, Layer* layer)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
, m_name(layer->getName())
|
||||
{
|
||||
}
|
||||
|
||||
void SetLayerName::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetLayerName::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Layer* layer = objects->getObjectT<Layer>(m_layerId);
|
||||
|
||||
// Push another SetLayerName as redoer
|
||||
redoers->pushUndoer(new SetLayerName(objects, layer));
|
||||
|
||||
layer->setName(m_name.c_str());
|
||||
}
|
47
src/undoers/set_layer_name.h
Normal file
47
src/undoers/set_layer_name.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_LAYER_NAME_H_INCLUDED
|
||||
#define UNDOERS_SET_LAYER_NAME_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Layer;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetLayerName : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetLayerName(undo::ObjectsContainer* objects, Layer* layer);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + m_name.size(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_layerId;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_LAYER_NAME_H_INCLUDED
|
64
src/undoers/set_mask.cpp
Normal file
64
src/undoers/set_mask.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_mask.h"
|
||||
|
||||
#include "base/unique_ptr.h"
|
||||
#include "document.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/mask_io.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "undoers/object_io.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetMask::SetMask(ObjectsContainer* objects, Document* document)
|
||||
: m_documentId(objects->addObject(document))
|
||||
, m_isMaskVisible(document->isMaskVisible())
|
||||
{
|
||||
if (m_isMaskVisible)
|
||||
write_object(objects, m_stream, document->getMask(), raster::write_mask);
|
||||
}
|
||||
|
||||
void SetMask::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetMask::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Document* document = objects->getObjectT<Document>(m_documentId);
|
||||
|
||||
// Push another SetMask as redoer
|
||||
redoers->pushUndoer(new SetMask(objects, document));
|
||||
|
||||
if (m_isMaskVisible) {
|
||||
UniquePtr<Mask> mask(read_object<Mask>(objects, m_stream, raster::read_mask));
|
||||
|
||||
document->setMask(mask);
|
||||
|
||||
// Document::setMask() makes a copy of the mask, so here the mask
|
||||
// is deleted with the UniquePtr.
|
||||
}
|
||||
else
|
||||
document->setMaskVisible(false);
|
||||
}
|
52
src/undoers/set_mask.h
Normal file
52
src/undoers/set_mask.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_MASK_H_INCLUDED
|
||||
#define UNDOERS_SET_MASK_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Document;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetMask : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetMask(undo::ObjectsContainer* objects, Document* document);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_documentId;
|
||||
bool m_isMaskVisible;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_MASK_H_INCLUDED
|
66
src/undoers/set_palette_colors.cpp
Normal file
66
src/undoers/set_palette_colors.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_palette_colors.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "raster/palette.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undo_exception.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
using namespace base::serialization::little_endian;
|
||||
|
||||
SetPaletteColors::SetPaletteColors(ObjectsContainer* objects, Sprite* sprite, Palette* palette, int from, int to)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_frame(sprite->getCurrentFrame())
|
||||
, m_from(from)
|
||||
, m_to(to)
|
||||
{
|
||||
// Write (to-from+1) palette color entries
|
||||
for (int i=from; i<=to; ++i)
|
||||
write32(m_stream, palette->getEntry(i));
|
||||
}
|
||||
|
||||
void SetPaletteColors::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetPaletteColors::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
Palette* palette = sprite->getPalette(m_frame);
|
||||
|
||||
if (palette == NULL)
|
||||
throw UndoException("Palette not found when restoring colors");
|
||||
|
||||
// Push another SetPaletteColors as redoer
|
||||
redoers->pushUndoer(new SetPaletteColors(objects, sprite, palette, m_from, m_to));
|
||||
|
||||
// Read palette color entries
|
||||
for (int i=m_from; i<=m_to; ++i) {
|
||||
uint32_t color = read32(m_stream);
|
||||
palette->setEntry(i, color);
|
||||
}
|
||||
}
|
55
src/undoers/set_palette_colors.h
Normal file
55
src/undoers/set_palette_colors.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_PALETTE_COLORS_H_INCLUDED
|
||||
#define UNDOERS_SET_PALETTE_COLORS_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Palette;
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetPaletteColors : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetPaletteColors(undo::ObjectsContainer* objects, Sprite* sprite, Palette* palette, int from, int to);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
size_t getStreamSize() const {
|
||||
return const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frame;
|
||||
uint8_t m_from;
|
||||
uint8_t m_to;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_PALETTE_COLORS_H_INCLUDED
|
50
src/undoers/set_sprite_size.cpp
Normal file
50
src/undoers/set_sprite_size.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_sprite_size.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetSpriteSize::SetSpriteSize(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_width(sprite->getWidth())
|
||||
, m_height(sprite->getHeight())
|
||||
{
|
||||
}
|
||||
|
||||
void SetSpriteSize::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetSpriteSize::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Push another SetSpriteSize as redoer
|
||||
redoers->pushUndoer(new SetSpriteSize(objects, sprite));
|
||||
|
||||
sprite->setSize(m_width, m_height);
|
||||
}
|
46
src/undoers/set_sprite_size.h
Normal file
46
src/undoers/set_sprite_size.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_SPRITE_SIZE_H_INCLUDED
|
||||
#define UNDOERS_SET_SPRITE_SIZE_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetSpriteSize : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetSpriteSize(undo::ObjectsContainer* objects, Sprite* sprite);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_SPRITE_SIZE_H_INCLUDED
|
49
src/undoers/set_total_frames.cpp
Normal file
49
src/undoers/set_total_frames.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "undoers/set_total_frames.h"
|
||||
|
||||
#include "raster/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetTotalFrames::SetTotalFrames(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_totalFrames(sprite->getTotalFrames())
|
||||
{
|
||||
}
|
||||
|
||||
void SetTotalFrames::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void SetTotalFrames::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Push another SetTotalFrames as redoer
|
||||
redoers->pushUndoer(new SetTotalFrames(objects, sprite));
|
||||
|
||||
sprite->setTotalFrames(m_totalFrames);
|
||||
}
|
47
src/undoers/set_total_frames.h
Normal file
47
src/undoers/set_total_frames.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#define UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class Sprite;
|
||||
|
||||
namespace undoers {
|
||||
|
||||
class SetTotalFrames : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetTotalFrames(undo::ObjectsContainer* objects, Sprite* sprite);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
int getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_totalFrames;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
26
src/undoers/undoer_base.h
Normal file
26
src/undoers/undoer_base.h
Normal file
@ -0,0 +1,26 @@
|
||||
// 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.
|
||||
|
||||
#ifndef UNDOERS_UNDOER_BASE_H_INCLUDED
|
||||
#define UNDOERS_UNDOER_BASE_H_INCLUDED
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "undo/undoer.h"
|
||||
|
||||
namespace undoers {
|
||||
|
||||
// Helper class to make new Undoers, derive from here and implement
|
||||
// revert(), getMemSize(), and dispose() methods only.
|
||||
class UndoerBase : public undo::Undoer
|
||||
{
|
||||
public:
|
||||
bool isOpenGroup() const OVERRIDE { return false; }
|
||||
bool isCloseGroup() const OVERRIDE { return false; }
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
||||
#endif // UNDOERS_UNDOER_BASE_H_INCLUDED
|
@ -40,7 +40,7 @@ static Layer* dst_layer = NULL;
|
||||
static int src_frame = 0;
|
||||
static int dst_frame = 0;
|
||||
|
||||
static void remove_cel(Sprite* sprite, UndoHistory* undo, LayerImage *layer, Cel *cel);
|
||||
static void remove_cel(Sprite* sprite, undo::UndoHistory* undo, LayerImage *layer, Cel *cel);
|
||||
|
||||
void set_frame_to_handle(Layer *_src_layer, int _src_frame,
|
||||
Layer *_dst_layer, int _dst_frame)
|
||||
@ -54,7 +54,7 @@ void set_frame_to_handle(Layer *_src_layer, int _src_frame,
|
||||
void move_cel(DocumentWriter& document)
|
||||
{
|
||||
Sprite* sprite = document->getSprite();
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
Cel *src_cel, *dst_cel;
|
||||
|
||||
ASSERT(src_layer != NULL);
|
||||
@ -148,7 +148,7 @@ void move_cel(DocumentWriter& document)
|
||||
void copy_cel(DocumentWriter& document)
|
||||
{
|
||||
Sprite* sprite = document->getSprite();
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
Cel *src_cel, *dst_cel;
|
||||
|
||||
ASSERT(src_layer != NULL);
|
||||
@ -231,7 +231,7 @@ void copy_cel(DocumentWriter& document)
|
||||
set_frame_to_handle(NULL, 0, NULL, 0);
|
||||
}
|
||||
|
||||
static void remove_cel(Sprite* sprite, UndoHistory* undo, LayerImage *layer, Cel *cel)
|
||||
static void remove_cel(Sprite* sprite, undo::UndoHistory* undo, LayerImage *layer, Cel *cel)
|
||||
{
|
||||
Image *image;
|
||||
Cel *it;
|
||||
|
@ -196,7 +196,7 @@ void clipboard::copy_image(Image* image, Palette* pal)
|
||||
void clipboard::paste(DocumentWriter& document)
|
||||
{
|
||||
UndoTransaction undoTransaction(document, "Paste");
|
||||
UndoHistory* undo = document->getUndoHistory();
|
||||
undo::UndoHistory* undo = document->getUndoHistory();
|
||||
int xout[4], yout[4];
|
||||
int dst_x, dst_y;
|
||||
Image *src_image;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user