Replace UndoHistory::undo_int/data/double methods with new safe-undoers.

+ Added SetCelFrame/Opacity/Position, SetMaskPosition, SetStockImgType,
  and SetLayerFlags undoers.
+ Finally removed the Layer::flags_addr() atrocity.
+ Removed RawData undoer.
+ Renamed SetImgType to SetSpriteImgType.
This commit is contained in:
David Capello 2011-03-27 18:15:00 -03:00
parent b40a20e8aa
commit 682e7152b7
27 changed files with 621 additions and 104 deletions

View File

@ -241,21 +241,26 @@ add_library(aseprite-library
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_cel_frame.cpp
undoers/set_cel_opacity.cpp
undoers/set_cel_position.cpp
undoers/set_current_frame.cpp
undoers/set_current_layer.cpp
undoers/set_frame_duration.cpp
undoers/set_imgtype.cpp
undoers/set_layer_flags.cpp
undoers/set_layer_name.cpp
undoers/set_mask.cpp
undoers/set_mask_position.cpp
undoers/set_palette_colors.cpp
undoers/set_sprite_imgtype.cpp
undoers/set_sprite_size.cpp
undoers/set_stock_imgtype.cpp
undoers/set_total_frames.cpp
util/autocrop.cpp
util/boundary.cpp

View File

@ -30,6 +30,7 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "undo/undo_history.h"
#include "undoers/set_cel_opacity.h"
#include <allegro/unicode.h>
@ -138,7 +139,8 @@ void CelPropertiesCommand::onExecute(Context* context)
if (undo->isEnabled()) {
undo->setLabel("Cel Opacity Change");
undo->setModification(undo::ModifyDocument);
undo->undo_int(cel_writer, &cel_writer->opacity);
undo->pushUndoer(new undoers::SetCelOpacity(undo->getObjects(), cel_writer));
}
/* change cel opacity */

View File

@ -29,6 +29,7 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "undo/undo_history.h"
#include "undoers/set_cel_position.h"
//////////////////////////////////////////////////////////////////////
// merge_down_layer
@ -162,10 +163,8 @@ void MergeDownLayerCommand::onExecute(Context* context)
src_cel->opacity,
static_cast<LayerImage*>(src_layer)->getBlendMode());
if (undo->isEnabled()) {
undo->undo_int(dst_cel, &dst_cel->x);
undo->undo_int(dst_cel, &dst_cel->y);
}
if (undo->isEnabled())
undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), dst_cel));
cel_set_position(dst_cel, x1, y1);

View File

@ -679,7 +679,7 @@ static Layer *ase_file_read_layer_chunk(FILE *f, Sprite *sprite, Layer **previou
if (layer) {
// flags
*layer->flags_addr() = flags;
layer->setFlags(flags);
// name
layer->setName(name.c_str());
@ -703,8 +703,8 @@ static void ase_file_write_layer_chunk(FILE *f, Layer *layer)
{
ase_file_write_start_chunk(f, ASE_FILE_CHUNK_LAYER);
/* flags */
fputw(*layer->flags_addr(), f);
// Flags
fputw(layer->getFlags(), f);
/* layer type */
fputw(layer->is_image() ? 0: (layer->is_folder() ? 1: -1), f);

View File

@ -208,7 +208,8 @@ void LayerImage::configureAsBackground()
ASSERT(getSprite() != NULL);
ASSERT(getSprite()->getBackgroundLayer() == NULL);
*flags_addr() |= LAYER_IS_LOCKMOVE | LAYER_IS_BACKGROUND;
set_moveable(false);
set_background(true);
setName("Background");
getSprite()->getFolder()->move_layer(this, NULL);

View File

@ -30,14 +30,16 @@ class Layer;
class LayerImage;
class LayerFolder;
#define LAYER_IS_READABLE 0x0001
#define LAYER_IS_WRITABLE 0x0002
#define LAYER_IS_LOCKMOVE 0x0004
#define LAYER_IS_BACKGROUND 0x0008
//////////////////////////////////////////////////////////////////////
// Layer class
enum {
LAYER_IS_READABLE = 0x0001,
LAYER_IS_WRITABLE = 0x0002,
LAYER_IS_LOCKMOVE = 0x0004,
LAYER_IS_BACKGROUND = 0x0008,
};
class Layer : public GfxObj
{
protected:
@ -69,10 +71,10 @@ public:
void set_readable(bool b) { if (b) m_flags |= LAYER_IS_READABLE; else m_flags &= ~LAYER_IS_READABLE; }
void set_writable(bool b) { if (b) m_flags |= LAYER_IS_WRITABLE; else m_flags &= ~LAYER_IS_WRITABLE; }
virtual void getCels(CelList& cels) = 0;
uint32_t getFlags() const { return m_flags; }
void setFlags(uint32_t flags) { m_flags = flags; }
// TODO remove these methods (from C backward-compatibility)
unsigned short* flags_addr() { return &m_flags; }
virtual void getCels(CelList& cels) = 0;
private:
std::string m_name; // layer name

View File

@ -45,7 +45,7 @@ void write_layer(std::ostream& os, LayerSubObjectsSerializer* subObjects, Layer*
if (!name.empty())
os.write(name.c_str(), name.size()); // Name
write8(os, *layer->flags_addr()); // Flags
write32(os, layer->getFlags()); // Flags
write16(os, layer->getType()); // Type
switch (layer->getType()) {
@ -86,9 +86,6 @@ void write_layer(std::ostream& os, LayerSubObjectsSerializer* subObjects, Layer*
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) {
@ -98,8 +95,10 @@ Layer* read_layer(std::istream& is, LayerSubObjectsSerializer* subObjects, Sprit
else
name[0] = 0;
flags = read8(is); // Flags
layer_type = read16(is); // Type
uint32_t flags = read32(is); // Flags
uint16_t layer_type = read16(is); // Type
UniquePtr<Layer> layer;
switch (layer_type) {
@ -147,7 +146,7 @@ Layer* read_layer(std::istream& is, LayerSubObjectsSerializer* subObjects, Sprit
if (layer != NULL) {
layer->setName(&name[0]);
*layer->flags_addr() = flags;
layer->setFlags(flags);
}
return layer.release();

View File

@ -70,7 +70,6 @@ public:
// Backward compatibility methods
void undo_open();
void undo_close();
void undo_data(void* object, void* fieldAddress, int fieldSize);
void undo_image(Image *image, int x, int y, int w, int h);
void undo_flip(Image *image, int x1, int y1, int x2, int y2, bool horz);
void undo_dirty(Image* image, Dirty *dirty);
@ -95,14 +94,6 @@ public:
void undo_set_frames(Sprite* sprite);
void undo_set_frlen(Sprite* sprite, int frame);
void undo_int(GfxObj* gfxobj, int* value_address) {
undo_data(gfxobj, (void*)(value_address), sizeof(int));
}
void undo_double(GfxObj* gfxobj, double* value_address) {
undo_data(gfxobj, (void*)(value_address), sizeof(double));
}
private:
enum Direction { UndoDirection, RedoDirection };

View File

@ -20,7 +20,6 @@
#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"
@ -30,10 +29,10 @@
#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_imgtype.h"
#include "undoers/set_sprite_size.h"
#include "undoers/set_total_frames.h"
@ -49,11 +48,6 @@ 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));
@ -148,7 +142,7 @@ void UndoHistory::undo_set_mask(Document* document)
void UndoHistory::undo_set_imgtype(Sprite* sprite)
{
pushUndoer(new undoers::SetImgType(getObjects(), sprite));
pushUndoer(new undoers::SetSpriteImgType(getObjects(), sprite));
}
void UndoHistory::undo_set_size(Sprite* sprite)

View File

@ -33,6 +33,11 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "undo/undo_history.h"
#include "undoers/set_cel_frame.h"
#include "undoers/set_cel_position.h"
#include "undoers/set_layer_flags.h"
#include "undoers/set_mask_position.h"
#include "undoers/set_stock_imgtype.h"
UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Modification modification)
{
@ -221,9 +226,9 @@ void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_meth
if (m_sprite->getImgType() == new_imgtype)
return;
/* change imgtype of the stock of images */
// Change imgtype of the stock of images.
if (isEnabled())
m_undoHistory->undo_int(m_sprite->getStock(), &m_sprite->getStock()->m_imgtype);
m_undoHistory->pushUndoer(new undoers::SetStockImgType(m_undoHistory->getObjects(), m_sprite->getStock()));
m_sprite->getStock()->setImgType(new_imgtype);
@ -508,10 +513,8 @@ void UndoTransaction::layerFromBackground()
ASSERT(m_sprite->getCurrentLayer()->is_background());
if (isEnabled()) {
m_undoHistory->undo_data(
m_sprite->getCurrentLayer(),
m_sprite->getCurrentLayer()->flags_addr(),
sizeof(*m_sprite->getCurrentLayer()->flags_addr()));
m_undoHistory->pushUndoer(new undoers::SetLayerFlags(m_undoHistory->getObjects(),
m_sprite->getCurrentLayer()));
m_undoHistory->undo_set_layer_name(m_sprite->getCurrentLayer());
}
@ -618,7 +621,7 @@ void UndoTransaction::flattenLayers(int bgcolor)
void UndoTransaction::configureLayerAsBackground(LayerImage* layer)
{
if (isEnabled()) {
m_undoHistory->undo_data(layer, layer->flags_addr(), sizeof(*layer->flags_addr()));
m_undoHistory->pushUndoer(new undoers::SetLayerFlags(m_undoHistory->getObjects(), layer));
m_undoHistory->undo_set_layer_name(layer);
m_undoHistory->undo_move_layer(layer);
}
@ -796,7 +799,7 @@ void UndoTransaction::setCelFramePosition(Cel* cel, int frame)
ASSERT(frame >= 0);
if (isEnabled())
m_undoHistory->undo_int(cel, &cel->frame);
m_undoHistory->pushUndoer(new undoers::SetCelFrame(m_undoHistory->getObjects(), cel));
cel->frame = frame;
}
@ -805,10 +808,8 @@ void UndoTransaction::setCelPosition(Cel* cel, int x, int y)
{
ASSERT(cel);
if (isEnabled()) {
m_undoHistory->undo_int(cel, &cel->x);
m_undoHistory->undo_int(cel, &cel->y);
}
if (isEnabled())
m_undoHistory->pushUndoer(new undoers::SetCelPosition(m_undoHistory->getObjects(), cel));
cel->x = x;
cel->y = y;
@ -1071,10 +1072,8 @@ void UndoTransaction::setMaskPosition(int x, int y)
{
ASSERT(m_document->getMask());
if (isEnabled()) {
m_undoHistory->undo_int(m_document->getMask(), &m_document->getMask()->x);
m_undoHistory->undo_int(m_document->getMask(), &m_document->getMask()->y);
}
if (isEnabled())
m_undoHistory->pushUndoer(new undoers::SetMaskPosition(m_undoHistory->getObjects(), m_document));
m_document->getMask()->x = x;
m_document->getMask()->y = y;

View 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_cel_frame.h"
#include "raster/cel.h"
#include "undo/objects_container.h"
#include "undo/undoers_collector.h"
using namespace undo;
using namespace undoers;
SetCelFrame::SetCelFrame(ObjectsContainer* objects, Cel* cel)
: m_celId(objects->addObject(cel))
, m_frame(cel->frame)
{
}
void SetCelFrame::dispose()
{
delete this;
}
void SetCelFrame::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Cel* cel = objects->getObjectT<Cel>(m_celId);
// Push another SetCelFrame as redoer
redoers->pushUndoer(new SetCelFrame(objects, cel));
cel->frame = m_frame;
}

View File

@ -16,31 +16,31 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UNDOERS_RAW_DATA_H_INCLUDED
#define UNDOERS_RAW_DATA_H_INCLUDED
#ifndef UNDOERS_SET_CEL_FRAME_H_INCLUDED
#define UNDOERS_SET_CEL_FRAME_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
#include <vector>
class Cel;
class Layer;
namespace undoers {
class RawData : public UndoerBase
class SetCelFrame : public UndoerBase
{
public:
RawData(undo::ObjectsContainer* objects, void* object, void* fieldAddress, int fieldSize);
SetCelFrame(undo::ObjectsContainer* objects, Cel* cel);
void dispose() OVERRIDE;
int getMemSize() const OVERRIDE { return sizeof(*this) + m_data.size(); }
int getMemSize() const OVERRIDE { return sizeof(*this); }
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
private:
undo::ObjectId m_objectId;
uint32_t m_offset;
std::vector<uint8_t> m_data;
undo::ObjectId m_celId;
int m_frame;
};
} // namespace undoers
#endif // UNDOERS_RAW_DATA_H_INCLUDED
#endif // UNDOERS_SET_CEL_FRAME_H_INCLUDED

View 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_cel_opacity.h"
#include "raster/cel.h"
#include "undo/objects_container.h"
#include "undo/undoers_collector.h"
using namespace undo;
using namespace undoers;
SetCelOpacity::SetCelOpacity(ObjectsContainer* objects, Cel* cel)
: m_celId(objects->addObject(cel))
, m_opacity(cel->opacity)
{
}
void SetCelOpacity::dispose()
{
delete this;
}
void SetCelOpacity::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Cel* cel = objects->getObjectT<Cel>(m_celId);
// Push another SetCelOpacity as redoer
redoers->pushUndoer(new SetCelOpacity(objects, cel));
cel->opacity = m_opacity;
}

View 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_CEL_OPACITY_H_INCLUDED
#define UNDOERS_SET_CEL_OPACITY_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
class Cel;
class Layer;
namespace undoers {
class SetCelOpacity : public UndoerBase
{
public:
SetCelOpacity(undo::ObjectsContainer* objects, 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_celId;
uint8_t m_opacity;
};
} // namespace undoers
#endif // UNDOERS_SET_CEL_OPACITY_H_INCLUDED

View 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/set_cel_position.h"
#include "raster/cel.h"
#include "undo/objects_container.h"
#include "undo/undoers_collector.h"
using namespace undo;
using namespace undoers;
SetCelPosition::SetCelPosition(ObjectsContainer* objects, Cel* cel)
: m_celId(objects->addObject(cel))
, m_x(cel->x)
, m_y(cel->y)
{
}
void SetCelPosition::dispose()
{
delete this;
}
void SetCelPosition::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Cel* cel = objects->getObjectT<Cel>(m_celId);
// Push another SetCelPosition as redoer
redoers->pushUndoer(new SetCelPosition(objects, cel));
cel->x = m_x;
cel->y = m_y;
}

View 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_CEL_POSITION_H_INCLUDED
#define UNDOERS_SET_CEL_POSITION_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
class Cel;
class Layer;
namespace undoers {
class SetCelPosition : public UndoerBase
{
public:
SetCelPosition(undo::ObjectsContainer* objects, 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_celId;
int m_x, m_y;
};
} // namespace undoers
#endif // UNDOERS_SET_CEL_POSITION_H_INCLUDED

View 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_flags.h"
#include "raster/layer.h"
#include "undo/objects_container.h"
#include "undo/undoers_collector.h"
using namespace undo;
using namespace undoers;
SetLayerFlags::SetLayerFlags(ObjectsContainer* objects, Layer* layer)
: m_layerId(objects->addObject(layer))
, m_flags(layer->getFlags())
{
}
void SetLayerFlags::dispose()
{
delete this;
}
void SetLayerFlags::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Layer* layer = objects->getObjectT<Layer>(m_layerId);
// Push another SetLayerFlags as redoer
redoers->pushUndoer(new SetLayerFlags(objects, layer));
layer->setFlags(m_flags);
}

View 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_FLAGS_H_INCLUDED
#define UNDOERS_SET_LAYER_FLAGS_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
#include <string>
class Layer;
namespace undoers {
class SetLayerFlags : public UndoerBase
{
public:
SetLayerFlags(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_layerId;
uint32_t m_flags;
};
} // namespace undoers
#endif // UNDOERS_SET_LAYER_FLAGS_H_INCLUDED

View File

@ -18,35 +18,35 @@
#include "config.h"
#include "undoers/raw_data.h"
#include "undoers/set_mask_position.h"
#include "document.h"
#include "raster/mask.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)
SetMaskPosition::SetMaskPosition(ObjectsContainer* objects, Document* document)
: m_documentId(objects->addObject(document))
, m_x(document->getMask()->x)
, m_y(document->getMask()->y)
{
memcpy(&m_data[0], fieldAddress, m_data.size());
}
void RawData::dispose()
void SetMaskPosition::dispose()
{
delete this;
}
void RawData::revert(ObjectsContainer* objects, UndoersCollector* redoers)
void SetMaskPosition::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
void* object = objects->getObject(m_objectId);
void* fieldAddress = (void*)(((uint8_t*)object) + m_offset);
Document* document = objects->getObjectT<Document>(m_documentId);
// Save the current data
redoers->pushUndoer(new RawData(objects, object, fieldAddress, m_data.size()));
// Push another SetMaskPosition as redoer
redoers->pushUndoer(new SetMaskPosition(objects, document));
// Copy back the old data
memcpy(fieldAddress, &m_data[0], m_data.size());
document->getMask()->x = m_x;
document->getMask()->y = m_y;
}

View 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_MASK_POSITION_H_INCLUDED
#define UNDOERS_SET_MASK_POSITION_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
#include <sstream>
class Document;
namespace undoers {
class SetMaskPosition : public UndoerBase
{
public:
SetMaskPosition(undo::ObjectsContainer* objects, Document* document);
void dispose() OVERRIDE;
int getMemSize() const OVERRIDE { return sizeof(*this); }
void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE;
private:
undo::ObjectId m_documentId;
int m_x, m_y;
};
} // namespace undoers
#endif // UNDOERS_SET_MASK_POSITION_H_INCLUDED

View File

@ -18,7 +18,7 @@
#include "config.h"
#include "undoers/set_imgtype.h"
#include "undoers/set_sprite_imgtype.h"
#include "raster/sprite.h"
#include "undo/objects_container.h"
@ -27,23 +27,23 @@
using namespace undo;
using namespace undoers;
SetImgType::SetImgType(ObjectsContainer* objects, Sprite* sprite)
SetSpriteImgType::SetSpriteImgType(ObjectsContainer* objects, Sprite* sprite)
: m_spriteId(objects->addObject(sprite))
, m_imgtype(sprite->getImgType())
{
}
void SetImgType::dispose()
void SetSpriteImgType::dispose()
{
delete this;
}
void SetImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers)
void SetSpriteImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
// Push another SetImgType as redoer
redoers->pushUndoer(new SetImgType(objects, sprite));
// Push another SetSpriteImgType as redoer
redoers->pushUndoer(new SetSpriteImgType(objects, sprite));
sprite->setImgType(m_imgtype);
}

View 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_SPRITE_IMGTYPE_H_INCLUDED
#define UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
class Sprite;
namespace undoers {
class SetSpriteImgType : public UndoerBase
{
public:
SetSpriteImgType(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_SPRITE_IMGTYPE_H_INCLUDED

View 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_stock_imgtype.h"
#include "raster/stock.h"
#include "undo/objects_container.h"
#include "undo/undoers_collector.h"
using namespace undo;
using namespace undoers;
SetStockImgType::SetStockImgType(ObjectsContainer* objects, Stock* stock)
: m_stockId(objects->addObject(stock))
, m_imgtype(stock->getImgType())
{
}
void SetStockImgType::dispose()
{
delete this;
}
void SetStockImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Stock* stock = objects->getObjectT<Stock>(m_stockId);
// Push another SetStockImgType as redoer
redoers->pushUndoer(new SetStockImgType(objects, stock));
stock->setImgType(m_imgtype);
}

View 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_STOCK_IMGTYPE_H_INCLUDED
#define UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED
#include "undo/object_id.h"
#include "undoers/undoer_base.h"
class Stock;
namespace undoers {
class SetStockImgType : public UndoerBase
{
public:
SetStockImgType(undo::ObjectsContainer* objects, Stock* stock);
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_imgtype;
};
} // namespace undoers
#endif // UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED

View File

@ -32,6 +32,9 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "undo/undo_history.h"
#include "undoers/set_cel_frame.h"
#include "undoers/set_cel_opacity.h"
#include "undoers/set_cel_position.h"
/* these variables indicate what cel to move (and the sprite's
frame indicates where to move it) */
@ -91,7 +94,7 @@ void move_cel(DocumentWriter& document)
if (src_cel != NULL) {
if (src_layer == dst_layer) {
if (undo->isEnabled())
undo->undo_int(src_cel, &src_cel->frame);
undo->pushUndoer(new undoers::SetCelFrame(undo->getObjects(), src_cel));
src_cel->frame = dst_frame;
}
@ -117,9 +120,8 @@ void move_cel(DocumentWriter& document)
if (undo->isEnabled()) {
undo->undo_replace_image(sprite->getStock(), src_cel->image);
undo->undo_int(src_cel, &src_cel->x);
undo->undo_int(src_cel, &src_cel->y);
undo->undo_int(src_cel, &src_cel->opacity);
undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), src_cel));
undo->pushUndoer(new undoers::SetCelOpacity(undo->getObjects(), src_cel));
}
image_clear(dst_image, app_get_color_to_clear_layer(dst_layer));

View File

@ -33,6 +33,7 @@
#include "modules/palettes.h"
#include "raster/raster.h"
#include "undo/undo_history.h"
#include "undoers/set_cel_position.h"
#include "util/misc.h"
#include "widgets/editor/editor.h"
#include "widgets/statebar.h"
@ -157,10 +158,8 @@ int interactive_move_layer(int mode, bool use_undo, int (*callback)())
if (use_undo && undo->isEnabled()) {
undo->setLabel("Cel Movement");
undo->setModification(undo::ModifyDocument);
undo->undo_open();
undo->undo_int(cel, &cel->x);
undo->undo_int(cel, &cel->y);
undo->undo_close();
undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), cel));
}
cel_set_position(cel, new_x, new_y);

View File

@ -41,6 +41,7 @@
#include "tools/tool.h"
#include "ui_context.h"
#include "undo/undo_history.h"
#include "undoers/set_cel_position.h"
#include "util/boundary.h"
#include "util/misc.h"
#include "util/render.h"
@ -1967,16 +1968,16 @@ public:
if (undo->isEnabled()) {
undo->undo_open();
if (m_cel->x != m_old_cel_x) {
if (m_cel->x != m_old_cel_x ||
m_cel->y != m_old_cel_y) {
int x = m_cel->x;
m_cel->x = m_old_cel_x;
undo->undo_int(m_cel, &m_cel->x);
m_cel->x = x;
}
if (m_cel->y != m_old_cel_y) {
int y = m_cel->y;
m_cel->y = m_old_cel_y;
undo->undo_int(m_cel, &m_cel->y);
m_cel->x = m_old_cel_x;
undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), m_cel));
m_cel->x = x;
m_cel->y = y;
}