mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 04:59:24 +00:00
Replace undo impl: replace undoers with cmds
Undoers were little objects to swap/revert an action. They didn't execute the action itself, they just revert its previous state. Now undoers were replaced with cmds: A cmd is an object that executes/undoes/redoes just one action. Changes: * Remove old undo library and app/objects_container_impl.cpp (now we use the doc::ObjectId directly to store undo info) * Remove all Undoers from app/undoers/ * Replace DocumentApi impl with little Cmds in app/cmd/, these cmds handle execute/undo/redo of each action at the logic layer * Remove doc::Dirty object * Remove doc::Settings: all undo configuration is in the app side * Move undo options from app:ISettings to app::Preferences * Rename UndoTransaction to Transaction * Create a CmdSequence to store a sequence of Cmds (as now the new undo library doesn't support open/close groups) * Add doc::get<T>(ObjectId) function to get any kind of object from the doc library by its ID * Add Cel::document() and Sprite::document() members * Add Sprite::cels(frame_t) to get all cels in the given frame * Add Layer::displaceFrames() member function * Move the "allow non-linear history" flag from undo2::UndoHistory to app::DocumentUndo
This commit is contained in:
parent
9efd84153b
commit
e55865843e
3
TODO.md
3
TODO.md
@ -43,6 +43,9 @@
|
||||
|
||||
# Refactoring
|
||||
|
||||
* Remove unused skin parts
|
||||
* Make one level of layers (folders should modify only timeline/UI)
|
||||
* rename undo2 to undo
|
||||
* Convert doc::PixelFormat to a enum class
|
||||
* Add doc::Spec with width/height/channels/ColorMode/ncolors
|
||||
* Convert doc::LayerIndex -> typedef int doc::layer_t;
|
||||
|
@ -624,7 +624,7 @@
|
||||
<item command="BackgroundFromLayer" text="&Background from Layer" />
|
||||
<item command="LayerFromBackground" text="&Layer from Background" />
|
||||
<separator />
|
||||
<item command="DuplicateLayer" text="&Duplicate..." />
|
||||
<item command="DuplicateLayer" text="&Duplicate" />
|
||||
<item command="MergeDownLayer" text="&Merge Down" />
|
||||
<item command="FlattenLayers" text="&Flatten" />
|
||||
</menu>
|
||||
|
@ -1,3 +1,5 @@
|
||||
<!-- Aseprite -->
|
||||
<!-- Copyright (C) 2014-2015 by David Capello -->
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<preferences>
|
||||
|
||||
@ -60,8 +62,9 @@
|
||||
<option id="expand_menubar_on_mouseover" type="bool" default="false" migrate="Options.ExpandMenuBarOnMouseover" />
|
||||
</section>
|
||||
<section id="undo" text="Undo">
|
||||
<option id="size_limit" type="int" default="0" />
|
||||
<option id="goto_modified" type="bool" default="false" />
|
||||
<option id="size_limit" type="int" default="64" />
|
||||
<option id="goto_modified" type="bool" default="true" />
|
||||
<option id="allow_nonlinear_history" type="bool" default="false" />
|
||||
</section>
|
||||
<section id="editor" text="Editor">
|
||||
<option id="zoom_with_scroll_wheel" type="bool" default="false" form="" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!-- Aseprite -->
|
||||
<!-- Copyright (C) 2001-2014 by David Capello -->
|
||||
<!-- Copyright (C) 2001-2015 by David Capello -->
|
||||
<gui>
|
||||
<window id="options" text="Preferences">
|
||||
<vbox>
|
||||
@ -86,15 +86,16 @@
|
||||
<!-- Undo -->
|
||||
<vbox id="section_undo">
|
||||
<separator text="Undo" horizontal="true" />
|
||||
<box horizontal="true">
|
||||
<hbox>
|
||||
<label text="Undo Limit:" />
|
||||
<entry id="undo_size_limit" maxsize="4" tooltip="Limit of memory to be used for undo information per sprite. Specified in megabytes." />
|
||||
<label text="MB" />
|
||||
</box>
|
||||
</hbox>
|
||||
|
||||
<box horizontal="true">
|
||||
<vbox>
|
||||
<check id="undo_goto_modified" text="Go to modified frame/layer" tooltip="When it's enabled each time you undo/redo the current frame & layer will be modified to focus the undid/redid change." />
|
||||
</box>
|
||||
<check id="undo_allow_nonlinear_history" text="Allow non-linear history." />
|
||||
</vbox>
|
||||
</vbox>
|
||||
|
||||
<!-- Experimental -->
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Aseprite
|
||||
# Copyright (C) 2001-2014 David Capello
|
||||
# Copyright (C) 2001-2015 David Capello
|
||||
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
@ -30,7 +30,6 @@ set(aseprite_libraries
|
||||
doc-lib
|
||||
render-lib
|
||||
scripting-lib
|
||||
undo-lib
|
||||
undo2-lib
|
||||
filters-lib
|
||||
ui-lib
|
||||
@ -220,7 +219,6 @@ add_subdirectory(gfx)
|
||||
add_subdirectory(scripting)
|
||||
add_subdirectory(she)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(undo)
|
||||
add_subdirectory(undo2)
|
||||
|
||||
add_subdirectory(app)
|
||||
|
@ -18,8 +18,7 @@ because they don't depend on any other component.
|
||||
* [css](css/): Pseudo-style sheet library.
|
||||
* [gfx](gfx/): Abstract graphics structures like point, size, rectangle, region, color, etc.
|
||||
* [scripting](scripting/): JavaScript engine ([V8](https://code.google.com/p/v8/)).
|
||||
* [undo](undo/): Generic library to manage undo history of undoable actions.
|
||||
* [undo2](undo2/): New library to replace the old undo system.
|
||||
* [undo2](undo2/): Generic library to manage a history of undoable commands.
|
||||
|
||||
## Level 1
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Aseprite
|
||||
# Copyright (C) 2001-2014 David Capello
|
||||
# Copyright (C) 2001-2015 David Capello
|
||||
|
||||
######################################################################
|
||||
# Generate source files from widget XML files
|
||||
@ -53,6 +53,56 @@ add_library(app-lib
|
||||
app_render.cpp
|
||||
backup.cpp
|
||||
check_update.cpp
|
||||
cmd.cpp
|
||||
cmd/add_cel.cpp
|
||||
cmd/add_frame.cpp
|
||||
cmd/add_layer.cpp
|
||||
cmd/add_palette.cpp
|
||||
cmd/background_from_layer.cpp
|
||||
cmd/clear_cel.cpp
|
||||
cmd/clear_image.cpp
|
||||
cmd/clear_mask.cpp
|
||||
cmd/configure_background.cpp
|
||||
cmd/copy_cel.cpp
|
||||
cmd/copy_frame.cpp
|
||||
cmd/copy_rect.cpp
|
||||
cmd/copy_region.cpp
|
||||
cmd/deselect_mask.cpp
|
||||
cmd/flatten_layers.cpp
|
||||
cmd/flip_image.cpp
|
||||
cmd/flip_mask.cpp
|
||||
cmd/flip_masked_cel.cpp
|
||||
cmd/layer_from_background.cpp
|
||||
cmd/move_cel.cpp
|
||||
cmd/move_layer.cpp
|
||||
cmd/object_io.cpp
|
||||
cmd/remove_cel.cpp
|
||||
cmd/remove_frame.cpp
|
||||
cmd/remove_layer.cpp
|
||||
cmd/remove_palette.cpp
|
||||
cmd/replace_image.cpp
|
||||
cmd/reselect_mask.cpp
|
||||
cmd/set_cel_frame.cpp
|
||||
cmd/set_cel_opacity.cpp
|
||||
cmd/set_cel_position.cpp
|
||||
cmd/set_frame_duration.cpp
|
||||
cmd/set_layer_flags.cpp
|
||||
cmd/set_layer_name.cpp
|
||||
cmd/set_mask.cpp
|
||||
cmd/set_mask_position.cpp
|
||||
cmd/set_palette.cpp
|
||||
cmd/set_pixel_format.cpp
|
||||
cmd/set_sprite_size.cpp
|
||||
cmd/set_total_frames.cpp
|
||||
cmd/set_transparent_color.cpp
|
||||
cmd/with_cel.cpp
|
||||
cmd/with_document.cpp
|
||||
cmd/with_image.cpp
|
||||
cmd/with_layer.cpp
|
||||
cmd/with_palette.cpp
|
||||
cmd/with_sprite.cpp
|
||||
cmd_sequence.cpp
|
||||
cmd_transaction.cpp
|
||||
color.cpp
|
||||
color_picker.cpp
|
||||
color_swatches.cpp
|
||||
@ -189,7 +239,6 @@ add_library(app-lib
|
||||
modules/gfx.cpp
|
||||
modules/gui.cpp
|
||||
modules/palettes.cpp
|
||||
objects_container_impl.cpp
|
||||
pref/preferences.cpp
|
||||
project.cpp
|
||||
recent_files.cpp
|
||||
@ -206,6 +255,7 @@ add_library(app-lib
|
||||
tools/shade_table.cpp
|
||||
tools/tool_box.cpp
|
||||
tools/tool_loop_manager.cpp
|
||||
transaction.cpp
|
||||
ui/app_menuitem.cpp
|
||||
ui/button_set.cpp
|
||||
ui/color_bar.cpp
|
||||
@ -262,38 +312,6 @@ add_library(app-lib
|
||||
ui/workspace.cpp
|
||||
ui/workspace_part.cpp
|
||||
ui_context.cpp
|
||||
undo_transaction.cpp
|
||||
undoers/add_cel.cpp
|
||||
undoers/add_frame.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/modified_region.cpp
|
||||
undoers/move_layer.cpp
|
||||
undoers/object_io.cpp
|
||||
undoers/open_group.cpp
|
||||
undoers/remap_palette.cpp
|
||||
undoers/remove_cel.cpp
|
||||
undoers/remove_frame.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_frame_duration.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_pixel_format.cpp
|
||||
undoers/set_sprite_size.cpp
|
||||
undoers/set_sprite_transparent_color.cpp
|
||||
undoers/set_total_frames.cpp
|
||||
util/autocrop.cpp
|
||||
util/boundary.cpp
|
||||
util/clipboard.cpp
|
||||
|
116
src/app/cmd.cpp
Normal file
116
src/app/cmd.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
Cmd::Cmd()
|
||||
#if _DEBUG
|
||||
: m_state(State::NotExecuted)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
Cmd::~Cmd()
|
||||
{
|
||||
}
|
||||
|
||||
void Cmd::execute(Context* ctx)
|
||||
{
|
||||
ASSERT(m_state == State::NotExecuted);
|
||||
|
||||
m_ctx = ctx;
|
||||
|
||||
onExecute();
|
||||
onFireNotifications();
|
||||
|
||||
#if _DEBUG
|
||||
m_state = State::Executed;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Cmd::undo()
|
||||
{
|
||||
ASSERT(m_state == State::Executed || m_state == State::Redone);
|
||||
|
||||
onUndo();
|
||||
onFireNotifications();
|
||||
|
||||
#if _DEBUG
|
||||
m_state = State::Undone;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Cmd::redo()
|
||||
{
|
||||
ASSERT(m_state == State::Undone);
|
||||
|
||||
onRedo();
|
||||
onFireNotifications();
|
||||
|
||||
#if _DEBUG
|
||||
m_state = State::Redone;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string Cmd::label() const
|
||||
{
|
||||
return onLabel();
|
||||
}
|
||||
|
||||
size_t Cmd::memSize() const
|
||||
{
|
||||
return onMemSize();
|
||||
}
|
||||
|
||||
void Cmd::onExecute()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void Cmd::onUndo()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void Cmd::onRedo()
|
||||
{
|
||||
// By default onRedo() uses onExecute() implementation
|
||||
onExecute();
|
||||
}
|
||||
|
||||
void Cmd::onFireNotifications()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
std::string Cmd::onLabel() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t Cmd::onMemSize() const {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
} // namespace app
|
62
src/app/cmd.h
Normal file
62
src/app/cmd.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_H_INCLUDED
|
||||
#define APP_CMD_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/sprite_position.h"
|
||||
#include "undo2/undo_command.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace app {
|
||||
class Context;
|
||||
|
||||
class Cmd : public undo2::UndoCommand {
|
||||
public:
|
||||
Cmd();
|
||||
virtual ~Cmd();
|
||||
|
||||
void execute(Context* ctx);
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
std::string label() const;
|
||||
size_t memSize() const;
|
||||
|
||||
Context* context() const { return m_ctx; }
|
||||
|
||||
protected:
|
||||
virtual void onExecute();
|
||||
virtual void onUndo();
|
||||
virtual void onRedo();
|
||||
virtual void onFireNotifications();
|
||||
virtual std::string onLabel() const;
|
||||
virtual size_t onMemSize() const;
|
||||
|
||||
private:
|
||||
Context* m_ctx;
|
||||
#if _DEBUG
|
||||
enum class State { NotExecuted, Executed, Undone, Redone };
|
||||
State m_state;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
||||
#endif
|
11
src/app/cmd/README.md
Normal file
11
src/app/cmd/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
## Shared pointers
|
||||
|
||||
Do not keep `ImageRef` or any kind of smart pointer to `doc::`
|
||||
entities. As several `cmd` can persist in parallel with other `cmd`
|
||||
(due the tree structure of the [undo history](../../undo2/undo_history.h))
|
||||
these smart pointers can generate conflicts in the logic layer.
|
||||
E.g. If we keep an `ImageRef` inside a `cmd`, the image is
|
||||
not removed from the [objects hash table](../../doc/object.cpp),
|
||||
so two or more `cmd` could will try to add/remove the same object
|
||||
in the hash table (there are asserts to check this state, were
|
||||
someone is trying to add the same `ObjectId` in the hash table).
|
97
src/app/cmd/add_cel.cpp
Normal file
97
src/app/cmd/add_cel.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/add_cel.h"
|
||||
|
||||
#include "app/cmd/object_io.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
AddCel::AddCel(Layer* layer, Cel* cel)
|
||||
: WithLayer(layer)
|
||||
, WithCel(cel)
|
||||
{
|
||||
}
|
||||
|
||||
void AddCel::onExecute()
|
||||
{
|
||||
Layer* layer = this->layer();
|
||||
Cel* cel = this->cel();
|
||||
|
||||
addCel(layer, cel);
|
||||
}
|
||||
|
||||
void AddCel::onUndo()
|
||||
{
|
||||
Layer* layer = this->layer();
|
||||
Cel* cel = this->cel();
|
||||
|
||||
ObjectIO(layer->sprite()).write_cel(m_stream, cel);
|
||||
|
||||
removeCel(layer, cel);
|
||||
}
|
||||
|
||||
void AddCel::onRedo()
|
||||
{
|
||||
Layer* layer = this->layer();
|
||||
Cel* cel = ObjectIO(layer->sprite()).read_cel(m_stream);
|
||||
|
||||
addCel(layer, cel);
|
||||
|
||||
m_stream.str(std::string());
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
void AddCel::addCel(Layer* layer, Cel* cel)
|
||||
{
|
||||
static_cast<LayerImage*>(layer)->addCel(cel);
|
||||
|
||||
Document* doc = cel->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(layer->sprite());
|
||||
ev.layer(layer);
|
||||
ev.cel(cel);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onAddCel, ev);
|
||||
}
|
||||
|
||||
void AddCel::removeCel(Layer* layer, Cel* cel)
|
||||
{
|
||||
Document* doc = cel->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(layer->sprite());
|
||||
ev.layer(layer);
|
||||
ev.cel(cel);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onRemoveCel, ev);
|
||||
|
||||
static_cast<LayerImage*>(layer)->removeCel(cel);
|
||||
delete cel;
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,38 +16,48 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_ADD_LAYER_H_INCLUDED
|
||||
#define APP_UNDOERS_ADD_LAYER_H_INCLUDED
|
||||
#ifndef APP_CMD_ADD_CEL_H_INCLUDED
|
||||
#define APP_CMD_ADD_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class Document;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
class AddCel : public Cmd
|
||||
, public WithLayer
|
||||
, public WithCel {
|
||||
public:
|
||||
AddCel(Layer* layer, Cel* cel);
|
||||
|
||||
class AddLayer : public UndoerBase {
|
||||
public:
|
||||
AddLayer(ObjectsContainer* objects, Document* document, Layer* layer);
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
private:
|
||||
void addCel(Layer* layer, Cel* cel);
|
||||
void removeCel(Layer* layer, Cel* cel);
|
||||
|
||||
private:
|
||||
undo::ObjectId m_documentId;
|
||||
undo::ObjectId m_layerId;
|
||||
};
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_ADD_LAYER_H_INCLUDED
|
||||
#endif
|
91
src/app/cmd/add_frame.cpp
Normal file
91
src/app/cmd/add_frame.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/add_frame.h"
|
||||
|
||||
#include "app/cmd/add_cel.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/primitives.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
AddFrame::AddFrame(Sprite* sprite, frame_t newFrame)
|
||||
: WithSprite(sprite)
|
||||
, m_newFrame(newFrame)
|
||||
, m_addCel(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void AddFrame::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
app::Document* doc = static_cast<app::Document*>(sprite->document());
|
||||
|
||||
sprite->addFrame(m_newFrame);
|
||||
|
||||
if (m_addCel) {
|
||||
m_addCel->redo();
|
||||
}
|
||||
else {
|
||||
LayerImage* bglayer = sprite->backgroundLayer();
|
||||
if (bglayer) {
|
||||
ImageRef bgimage(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height()));
|
||||
clear_image(bgimage, doc->bgColor(bglayer));
|
||||
Cel* cel = new Cel(m_newFrame, bgimage);
|
||||
m_addCel.reset(new cmd::AddCel(bglayer, cel));
|
||||
m_addCel->execute(context());
|
||||
}
|
||||
}
|
||||
|
||||
// Notify observers about the new frame.
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(m_newFrame);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onAddFrame, ev);
|
||||
}
|
||||
|
||||
void AddFrame::onUndo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
app::Document* doc = static_cast<app::Document*>(sprite->document());
|
||||
|
||||
if (m_addCel)
|
||||
m_addCel->undo();
|
||||
|
||||
sprite->removeFrame(m_newFrame);
|
||||
|
||||
// Notify observers about the new frame.
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(m_newFrame);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onRemoveFrame, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,37 +16,44 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
#define APP_UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
#ifndef APP_CMD_ADD_FRAME_H_INCLUDED
|
||||
#define APP_CMD_ADD_FRAME_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/add_cel.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/frame.h"
|
||||
#include "undo/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class Sprite;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class AddPalette : public UndoerBase {
|
||||
public:
|
||||
AddPalette(ObjectsContainer* objects, Sprite* sprite, frame_t palette_frame);
|
||||
class AddFrame : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
AddFrame(Sprite* sprite, frame_t frame);
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
frame_t m_paletteFrame;
|
||||
};
|
||||
private:
|
||||
void moveFrames(Layer* layer, frame_t fromThis, frame_t delta);
|
||||
|
||||
} // namespace undoers
|
||||
frame_t m_newFrame;
|
||||
base::UniquePtr<AddCel> m_addCel;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
#endif
|
102
src/app/cmd/add_layer.cpp
Normal file
102
src/app/cmd/add_layer.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/add_layer.h"
|
||||
|
||||
#include "app/cmd/object_io.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
AddLayer::AddLayer(Layer* folder, Layer* newLayer, Layer* afterThis)
|
||||
: m_folder(folder)
|
||||
, m_newLayer(newLayer)
|
||||
, m_afterThis(afterThis)
|
||||
{
|
||||
}
|
||||
|
||||
void AddLayer::onExecute()
|
||||
{
|
||||
Layer* folder = m_folder.layer();
|
||||
Layer* newLayer = m_newLayer.layer();
|
||||
Layer* afterThis = m_afterThis.layer();
|
||||
|
||||
addLayer(folder, newLayer, afterThis);
|
||||
}
|
||||
|
||||
void AddLayer::onUndo()
|
||||
{
|
||||
Layer* folder = m_folder.layer();
|
||||
Layer* layer = m_newLayer.layer();
|
||||
|
||||
ObjectIO(folder->sprite()).write_layer(m_stream, layer);
|
||||
|
||||
removeLayer(folder, layer);
|
||||
}
|
||||
|
||||
void AddLayer::onRedo()
|
||||
{
|
||||
Layer* folder = m_folder.layer();
|
||||
Layer* newLayer = ObjectIO(folder->sprite()).read_layer(m_stream);
|
||||
Layer* afterThis = m_afterThis.layer();
|
||||
|
||||
addLayer(folder, newLayer, afterThis);
|
||||
|
||||
m_stream.str(std::string());
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
void AddLayer::addLayer(Layer* folder, Layer* newLayer, Layer* afterThis)
|
||||
{
|
||||
static_cast<LayerFolder*>(folder)->addLayer(newLayer);
|
||||
static_cast<LayerFolder*>(folder)->stackLayer(newLayer, afterThis);
|
||||
|
||||
Document* doc = folder->sprite()->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(folder->sprite());
|
||||
ev.layer(newLayer);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onAddLayer, ev);
|
||||
}
|
||||
|
||||
void AddLayer::removeLayer(Layer* folder, Layer* layer)
|
||||
{
|
||||
Document* doc = folder->sprite()->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(layer->sprite());
|
||||
ev.layer(layer);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onBeforeRemoveLayer, ev);
|
||||
|
||||
static_cast<LayerFolder*>(folder)->removeLayer(layer);
|
||||
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onAfterRemoveLayer, ev);
|
||||
|
||||
delete layer;
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
62
src/app/cmd/add_layer.h
Normal file
62
src/app/cmd/add_layer.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_ADD_LAYER_H_INCLUDED
|
||||
#define APP_CMD_ADD_LAYER_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace doc {
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class AddLayer : public Cmd {
|
||||
public:
|
||||
AddLayer(Layer* folder, Layer* newLayer, Layer* afterThis);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
private:
|
||||
void addLayer(Layer* folder, Layer* newLayer, Layer* afterThis);
|
||||
void removeLayer(Layer* folder, Layer* layer);
|
||||
|
||||
WithLayer m_folder;
|
||||
WithLayer m_newLayer;
|
||||
WithLayer m_afterThis;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,38 +20,52 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/add_palette.h"
|
||||
#include "app/cmd/add_palette.h"
|
||||
|
||||
#include "app/undoers/remove_palette.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "doc/palette.h"
|
||||
#include "doc/palette_io.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
using namespace doc;
|
||||
|
||||
AddPalette::AddPalette(ObjectsContainer* objects, Sprite* sprite, frame_t paletteFrame)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_paletteFrame(paletteFrame)
|
||||
AddPalette::AddPalette(Sprite* sprite, Palette* pal)
|
||||
: WithSprite(sprite)
|
||||
, WithPalette(pal)
|
||||
{
|
||||
}
|
||||
|
||||
void AddPalette::dispose()
|
||||
void AddPalette::onExecute()
|
||||
{
|
||||
delete this;
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* palette = this->palette();
|
||||
|
||||
sprite->setPalette(palette, true);
|
||||
}
|
||||
|
||||
void AddPalette::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void AddPalette::onUndo()
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
Palette* palette = sprite->palette(frame_t(m_paletteFrame));
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* pal = this->palette();
|
||||
|
||||
redoers->pushUndoer(new RemovePalette(objects, sprite, frame_t(m_paletteFrame)));
|
||||
write_palette(m_stream, pal);
|
||||
|
||||
sprite->deletePalette(palette);
|
||||
sprite->deletePalette(pal);
|
||||
delete pal;
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void AddPalette::onRedo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* pal = read_palette(m_stream);
|
||||
|
||||
sprite->setPalette(pal, true);
|
||||
|
||||
m_stream.str(std::string());
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,13 +16,14 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#define APP_UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#ifndef APP_CMD_ADD_PALETTE_H_INCLUDED
|
||||
#define APP_CMD_ADD_PALETTE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_palette.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/frame.h"
|
||||
#include "undo/object_id.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -31,27 +32,30 @@ namespace doc {
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class Document;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
class AddPalette : public Cmd
|
||||
, public WithSprite
|
||||
, public WithPalette {
|
||||
public:
|
||||
AddPalette(Sprite* sprite, Palette* pal);
|
||||
|
||||
class SetTotalFrames : public UndoerBase {
|
||||
public:
|
||||
SetTotalFrames(ObjectsContainer* objects, Document* document, Sprite* sprite);
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
private:
|
||||
frame_t m_frame;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
private:
|
||||
undo::ObjectId m_documentId;
|
||||
undo::ObjectId m_spriteId;
|
||||
frame_t m_totalFrames;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#endif // CMD_ADD_PALETTE_H_INCLUDED
|
110
src/app/cmd/background_from_layer.cpp
Normal file
110
src/app/cmd/background_from_layer.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/background_from_layer.h"
|
||||
|
||||
#include "app/cmd/add_cel.h"
|
||||
#include "app/cmd/configure_background.h"
|
||||
#include "app/cmd/copy_rect.h"
|
||||
#include "app/cmd/replace_image.h"
|
||||
#include "app/cmd/set_cel_position.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/primitives.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "render/render.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
BackgroundFromLayer::BackgroundFromLayer(Layer* layer)
|
||||
: WithLayer(layer)
|
||||
{
|
||||
ASSERT(layer);
|
||||
ASSERT(layer->isVisible());
|
||||
ASSERT(layer->isEditable());
|
||||
ASSERT(layer->sprite() != NULL);
|
||||
ASSERT(layer->sprite()->backgroundLayer() == NULL);
|
||||
}
|
||||
|
||||
void BackgroundFromLayer::onExecute()
|
||||
{
|
||||
Layer* layer = this->layer();
|
||||
Sprite* sprite = layer->sprite();
|
||||
app::Document* doc = static_cast<app::Document*>(sprite->document());
|
||||
color_t bgcolor = doc->bgColor();
|
||||
|
||||
// create a temporary image to draw each frame of the new
|
||||
// `Background' layer
|
||||
ImageRef bg_image(Image::create(sprite->pixelFormat(),
|
||||
sprite->width(),
|
||||
sprite->height()));
|
||||
|
||||
CelList cels;
|
||||
layer->getCels(cels);
|
||||
for (Cel* cel : cels) {
|
||||
// get the image from the sprite's stock of images
|
||||
Image* cel_image = cel->image();
|
||||
ASSERT(cel_image);
|
||||
|
||||
clear_image(bg_image, bgcolor);
|
||||
render::composite_image(bg_image, cel_image,
|
||||
cel->x(), cel->y(),
|
||||
MID(0, cel->opacity(), 255),
|
||||
static_cast<LayerImage*>(layer)->getBlendMode());
|
||||
|
||||
// now we have to copy the new image (bg_image) to the cel...
|
||||
executeAndAdd(new cmd::SetCelPosition(cel, 0, 0));
|
||||
|
||||
// same size of cel-image and bg-image
|
||||
if (bg_image->width() == cel_image->width() &&
|
||||
bg_image->height() == cel_image->height()) {
|
||||
executeAndAdd(new CopyRect(cel_image, bg_image,
|
||||
gfx::Clip(0, 0, cel_image->bounds())));
|
||||
}
|
||||
else {
|
||||
ImageRef bg_image2(Image::createCopy(bg_image));
|
||||
executeAndAdd(new cmd::ReplaceImage(sprite, cel->imageRef(), bg_image2));
|
||||
}
|
||||
}
|
||||
|
||||
// Fill all empty cels with a flat-image filled with bgcolor
|
||||
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
|
||||
Cel* cel = layer->cel(frame);
|
||||
if (!cel) {
|
||||
ImageRef cel_image(Image::create(sprite->pixelFormat(),
|
||||
sprite->width(), sprite->height()));
|
||||
clear_image(cel_image, bgcolor);
|
||||
|
||||
// Create the new cel and add it to the new background layer
|
||||
cel = new Cel(frame, cel_image);
|
||||
executeAndAdd(new cmd::AddCel(layer, cel));
|
||||
}
|
||||
}
|
||||
|
||||
executeAndAdd(new cmd::ConfigureBackground(layer));
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,25 +16,27 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_UNDOER_BASE_H_INCLUDED
|
||||
#define APP_UNDOERS_UNDOER_BASE_H_INCLUDED
|
||||
#ifndef APP_CMD_BACKGROUND_FROM_LAYER_H_INCLUDED
|
||||
#define APP_CMD_BACKGROUND_FROM_LAYER_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "undo/undoer.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
// Helper class to make new Undoers, derive from here and implement
|
||||
// revert(), getMemSize(), and dispose() methods only.
|
||||
class UndoerBase : public undo::Undoer {
|
||||
public:
|
||||
undo::Modification getModification() const override { return undo::DoesntModifyDocument; }
|
||||
bool isOpenGroup() const override { return false; }
|
||||
bool isCloseGroup() const override { return false; }
|
||||
};
|
||||
class BackgroundFromLayer : public CmdSequence
|
||||
, public WithLayer {
|
||||
public:
|
||||
BackgroundFromLayer(Layer* layer);
|
||||
|
||||
} // namespace undoers
|
||||
protected:
|
||||
void onExecute() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_UNDOER_BASE_H_INCLUDED
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,41 +20,50 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/add_cel.h"
|
||||
#include "app/cmd/clear_cel.h"
|
||||
|
||||
#include "app/undoers/remove_cel.h"
|
||||
#include "app/cmd/clear_image.h"
|
||||
#include "app/cmd/remove_cel.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
|
||||
AddCel::AddCel(ObjectsContainer* objects, Layer* layer, Cel* cel)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
, m_celId(objects->addObject(cel))
|
||||
ClearCel::ClearCel(Cel* cel)
|
||||
: WithCel(cel)
|
||||
{
|
||||
app::Document* doc = static_cast<app::Document*>(cel->document());
|
||||
|
||||
if (cel->layer()->isBackground()) {
|
||||
Image* image = cel->image();
|
||||
ASSERT(image);
|
||||
if (image)
|
||||
m_seq.add(new cmd::ClearImage(image,
|
||||
doc->bgColor(cel->layer())));
|
||||
}
|
||||
else {
|
||||
m_seq.add(new cmd::RemoveCel(cel));
|
||||
}
|
||||
}
|
||||
|
||||
void AddCel::dispose()
|
||||
void ClearCel::onExecute()
|
||||
{
|
||||
delete this;
|
||||
m_seq.execute(context());
|
||||
}
|
||||
|
||||
void AddCel::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void ClearCel::onUndo()
|
||||
{
|
||||
LayerImage* layer = objects->getObjectT<LayerImage>(m_layerId);
|
||||
Cel* cel = objects->getObjectT<Cel>(m_celId);
|
||||
|
||||
redoers->pushUndoer(new RemoveCel(objects, layer, cel));
|
||||
|
||||
layer->removeCel(cel);
|
||||
delete cel;
|
||||
m_seq.undo();
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void ClearCel::onRedo()
|
||||
{
|
||||
m_seq.redo();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
51
src/app/cmd/clear_cel.h
Normal file
51
src/app/cmd/clear_cel.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_CLEAR_CEL_H_INCLUDED
|
||||
#define APP_CMD_CLEAR_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class ClearCel : public Cmd
|
||||
, public WithCel {
|
||||
public:
|
||||
ClearCel(Cel* cel);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) + m_seq.memSize();
|
||||
}
|
||||
|
||||
private:
|
||||
CmdSequence m_seq;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
54
src/app/cmd/clear_image.cpp
Normal file
54
src/app/cmd/clear_image.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/clear_image.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/primitives.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
ClearImage::ClearImage(Image* image, color_t color)
|
||||
: WithImage(image)
|
||||
, m_color(color)
|
||||
{
|
||||
}
|
||||
|
||||
void ClearImage::onExecute()
|
||||
{
|
||||
ASSERT(!m_copy);
|
||||
m_copy.reset(Image::createCopy(image()));
|
||||
clear_image(image(), m_color);
|
||||
}
|
||||
|
||||
void ClearImage::onUndo()
|
||||
{
|
||||
copy_image(image(), m_copy);
|
||||
m_copy.reset(nullptr);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/clear_image.h
Normal file
52
src/app/cmd/clear_image.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_CLEAR_IMAGE_H_INCLUDED
|
||||
#define APP_CMD_CLEAR_IMAGE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_image.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/image_ref.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class ClearImage : public Cmd
|
||||
, public WithImage {
|
||||
public:
|
||||
ClearImage(Image* image, color_t color);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) + (m_copy ? m_copy->getMemSize(): 0);
|
||||
}
|
||||
|
||||
private:
|
||||
ImageRef m_copy;
|
||||
color_t m_color;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
131
src/app/cmd/clear_mask.cpp
Normal file
131
src/app/cmd/clear_mask.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/clear_mask.h"
|
||||
|
||||
#include "app/cmd/clear_cel.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/image_bits.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/mask.h"
|
||||
#include "doc/primitives.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
ClearMask::ClearMask(Cel* cel)
|
||||
: WithCel(cel)
|
||||
{
|
||||
app::Document* doc = static_cast<app::Document*>(cel->document());
|
||||
|
||||
// If the mask is empty or is not visible then we have to clear the
|
||||
// entire image in the cel.
|
||||
if (!doc->isMaskVisible()) {
|
||||
m_seq.add(new cmd::ClearCel(cel));
|
||||
return;
|
||||
}
|
||||
|
||||
Image* image = (cel ? cel->image(): NULL);
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
Mask* mask = doc->mask();
|
||||
m_offsetX = mask->bounds().x - cel->x();
|
||||
m_offsetY = mask->bounds().y - cel->y();
|
||||
|
||||
gfx::Rect bounds =
|
||||
image->bounds().createIntersect(
|
||||
gfx::Rect(
|
||||
m_offsetX, m_offsetY,
|
||||
mask->bounds().w, mask->bounds().h));
|
||||
if (bounds.isEmpty())
|
||||
return;
|
||||
|
||||
m_dstImage.reset(new WithImage(image));
|
||||
m_bgcolor = doc->bgColor(cel->layer());
|
||||
|
||||
m_copy.reset(crop_image(image,
|
||||
bounds.x, bounds.y, bounds.w, bounds.h, m_bgcolor));
|
||||
}
|
||||
|
||||
void ClearMask::onExecute()
|
||||
{
|
||||
m_seq.execute(context());
|
||||
if (m_dstImage)
|
||||
clear();
|
||||
}
|
||||
|
||||
void ClearMask::onUndo()
|
||||
{
|
||||
if (m_dstImage)
|
||||
restore();
|
||||
m_seq.undo();
|
||||
}
|
||||
|
||||
void ClearMask::onRedo()
|
||||
{
|
||||
m_seq.redo();
|
||||
if (m_dstImage)
|
||||
clear();
|
||||
}
|
||||
|
||||
void ClearMask::clear()
|
||||
{
|
||||
Cel* cel = this->cel();
|
||||
Image* image = m_dstImage->image();
|
||||
app::Document* doc = static_cast<app::Document*>(cel->document());
|
||||
Mask* mask = doc->mask();
|
||||
|
||||
ASSERT(mask->bitmap());
|
||||
if (!mask->bitmap())
|
||||
return;
|
||||
|
||||
const LockImageBits<BitmapTraits> maskBits(mask->bitmap());
|
||||
LockImageBits<BitmapTraits>::const_iterator it = maskBits.begin();
|
||||
|
||||
// Clear the masked zones
|
||||
int u, v;
|
||||
for (v=0; v<mask->bounds().h; ++v) {
|
||||
for (u=0; u<mask->bounds().w; ++u, ++it) {
|
||||
ASSERT(it != maskBits.end());
|
||||
if (*it) {
|
||||
put_pixel(image,
|
||||
u + m_offsetX,
|
||||
v + m_offsetY, m_bgcolor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(it == maskBits.end());
|
||||
}
|
||||
|
||||
void ClearMask::restore()
|
||||
{
|
||||
copy_image(m_dstImage->image(), m_copy, m_offsetX, m_offsetY);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
62
src/app/cmd/clear_mask.h
Normal file
62
src/app/cmd/clear_mask.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_CLEAR_MASK_H_INCLUDED
|
||||
#define APP_CMD_CLEAR_MASK_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
#include "app/cmd/with_image.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/image_ref.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class ClearMask : public Cmd
|
||||
, public WithCel {
|
||||
public:
|
||||
ClearMask(Cel* cel);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) + m_seq.memSize() +
|
||||
(m_copy ? m_copy->getMemSize(): 0);
|
||||
}
|
||||
|
||||
private:
|
||||
void clear();
|
||||
void restore();
|
||||
|
||||
CmdSequence m_seq;
|
||||
base::UniquePtr<WithImage> m_dstImage;
|
||||
ImageRef m_copy;
|
||||
int m_offsetX, m_offsetY;
|
||||
color_t m_bgcolor;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
44
src/app/cmd/configure_background.cpp
Normal file
44
src/app/cmd/configure_background.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/configure_background.h"
|
||||
|
||||
#include "app/cmd/move_layer.h"
|
||||
#include "app/cmd/set_layer_flags.h"
|
||||
#include "app/cmd/set_layer_name.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
ConfigureBackground::ConfigureBackground(Layer* layer)
|
||||
{
|
||||
// Add "Background" and "LockMove" flags
|
||||
LayerFlags newFlags = LayerFlags(int(layer->flags())
|
||||
| int(LayerFlags::BackgroundLayerFlags));
|
||||
|
||||
add(new cmd::SetLayerFlags(layer, newFlags));
|
||||
add(new cmd::SetLayerName(layer, "Background"));
|
||||
add(new cmd::MoveLayer(layer, nullptr));
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,37 +16,26 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_SET_CEL_POSITION_H_INCLUDED
|
||||
#define APP_UNDOERS_SET_CEL_POSITION_H_INCLUDED
|
||||
#ifndef APP_CMD_CONFIGURE_BACKGROUND_H_INCLUDED
|
||||
#define APP_CMD_CONFIGURE_BACKGROUND_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetCelPosition : public UndoerBase {
|
||||
public:
|
||||
SetCelPosition(ObjectsContainer* objects, Cel* cel);
|
||||
class ConfigureBackground : public CmdSequence {
|
||||
public:
|
||||
ConfigureBackground(Layer* layer);
|
||||
};
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_celId;
|
||||
int m_x, m_y;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_SET_CEL_POSITION_H_INCLUDED
|
||||
#endif
|
131
src/app/cmd/copy_cel.cpp
Normal file
131
src/app/cmd/copy_cel.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/copy_cel.h"
|
||||
|
||||
#include "app/cmd/add_cel.h"
|
||||
#include "app/cmd/add_frame.h"
|
||||
#include "app/cmd/clear_cel.h"
|
||||
#include "app/cmd/copy_rect.h"
|
||||
#include "app/cmd/remove_cel.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/primitives.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "render/render.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
CopyCel::CopyCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame)
|
||||
: m_srcLayer(srcLayer)
|
||||
, m_dstLayer(dstLayer)
|
||||
, m_srcFrame(srcFrame)
|
||||
, m_dstFrame(dstFrame)
|
||||
{
|
||||
}
|
||||
|
||||
void CopyCel::onExecute()
|
||||
{
|
||||
LayerImage* srcLayer = static_cast<LayerImage*>(m_srcLayer.layer());
|
||||
LayerImage* dstLayer = static_cast<LayerImage*>(m_dstLayer.layer());
|
||||
|
||||
ASSERT(srcLayer);
|
||||
ASSERT(dstLayer);
|
||||
|
||||
Sprite* srcSprite = srcLayer->sprite();
|
||||
Sprite* dstSprite = dstLayer->sprite();
|
||||
ASSERT(srcSprite);
|
||||
ASSERT(dstSprite);
|
||||
ASSERT(m_srcFrame >= 0 && m_srcFrame < srcSprite->totalFrames());
|
||||
ASSERT(m_dstFrame >= 0);
|
||||
(void)srcSprite; // To avoid unused variable warning on Release mode
|
||||
|
||||
Cel* srcCel = srcLayer->cel(m_srcFrame);
|
||||
Cel* dstCel = dstLayer->cel(m_dstFrame);
|
||||
|
||||
// Clear destination cel if it does exist. It'll be overriden by the
|
||||
// copy of srcCel.
|
||||
if (dstCel)
|
||||
executeAndAdd(new cmd::ClearCel(dstCel));
|
||||
|
||||
// Add empty frames until newFrame
|
||||
while (dstSprite->totalFrames() <= m_dstFrame)
|
||||
executeAndAdd(new cmd::AddFrame(dstSprite, dstSprite->totalFrames()));
|
||||
|
||||
Image* srcImage = (srcCel ? srcCel->image(): NULL);
|
||||
ImageRef dstImage;
|
||||
dstCel = dstLayer->cel(m_dstFrame);
|
||||
if (dstCel)
|
||||
dstImage = dstCel->imageRef();
|
||||
|
||||
if (dstLayer->isBackground()) {
|
||||
if (srcCel) {
|
||||
ASSERT(dstImage);
|
||||
if (dstImage) {
|
||||
int blend = (srcLayer->isBackground() ?
|
||||
BLEND_MODE_COPY: BLEND_MODE_NORMAL);
|
||||
|
||||
ImageRef tmp(Image::createCopy(dstImage));
|
||||
render::composite_image(tmp, srcImage,
|
||||
srcCel->x(), srcCel->y(), 255, blend);
|
||||
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ASSERT(dstCel);
|
||||
if (dstCel)
|
||||
executeAndAdd(new cmd::ClearCel(dstCel));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dstCel)
|
||||
executeAndAdd(new cmd::RemoveCel(dstCel));
|
||||
|
||||
if (srcCel) {
|
||||
dstImage.reset(Image::createCopy(srcImage));
|
||||
|
||||
dstCel = new Cel(*srcCel);
|
||||
dstCel->setFrame(m_dstFrame);
|
||||
dstCel->setImage(dstImage);
|
||||
|
||||
executeAndAdd(new cmd::AddCel(dstLayer, dstCel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CopyCel::onFireNotifications()
|
||||
{
|
||||
CmdSequence::onFireNotifications();
|
||||
static_cast<app::Document*>(m_dstLayer.layer()->sprite()->document())
|
||||
->notifyCelCopied(
|
||||
m_srcLayer.layer(), m_srcFrame,
|
||||
m_dstLayer.layer(), m_dstFrame);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,39 +16,39 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_SET_CEL_FRAME_H_INCLUDED
|
||||
#define APP_UNDOERS_SET_CEL_FRAME_H_INCLUDED
|
||||
#ifndef APP_CMD_COPY_CEL_H_INCLUDED
|
||||
#define APP_CMD_COPY_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/frame.h"
|
||||
#include "undo/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
class LayerImage;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetCelFrame : public UndoerBase {
|
||||
public:
|
||||
SetCelFrame(ObjectsContainer* objects, LayerImage* layer, Cel* cel);
|
||||
class CopyCel : public CmdSequence {
|
||||
public:
|
||||
CopyCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame);
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onFireNotifications() override;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_layerId;
|
||||
undo::ObjectId m_celId;
|
||||
frame_t m_frame;
|
||||
};
|
||||
private:
|
||||
WithLayer m_srcLayer, m_dstLayer;
|
||||
frame_t m_srcFrame, m_dstFrame;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_SET_CEL_FRAME_H_INCLUDED
|
||||
#endif
|
66
src/app/cmd/copy_frame.cpp
Normal file
66
src/app/cmd/copy_frame.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/copy_frame.h"
|
||||
|
||||
#include "app/cmd/add_frame.h"
|
||||
#include "app/cmd/copy_cel.h"
|
||||
#include "app/cmd/set_frame_duration.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
CopyFrame::CopyFrame(Sprite* sprite, frame_t fromFrame, frame_t newFrame)
|
||||
: WithSprite(sprite)
|
||||
, m_fromFrame(fromFrame)
|
||||
, m_newFrame(newFrame)
|
||||
{
|
||||
}
|
||||
|
||||
void CopyFrame::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
frame_t fromFrame = m_fromFrame;
|
||||
int msecs = sprite->frameDuration(fromFrame);
|
||||
|
||||
executeAndAdd(new cmd::AddFrame(sprite, m_newFrame));
|
||||
executeAndAdd(new cmd::SetFrameDuration(sprite, m_newFrame, msecs));
|
||||
|
||||
if (fromFrame >= m_newFrame)
|
||||
++fromFrame;
|
||||
|
||||
for (int i=0; i<sprite->countLayers(); ++i) {
|
||||
Layer* layer = sprite->layer(i);
|
||||
if (layer->isImage()) {
|
||||
executeAndAdd(new cmd::CopyCel(
|
||||
static_cast<LayerImage*>(layer), fromFrame,
|
||||
static_cast<LayerImage*>(layer), m_newFrame));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/copy_frame.h
Normal file
52
src/app/cmd/copy_frame.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_COPY_FRAME_H_INCLUDED
|
||||
#define APP_CMD_COPY_FRAME_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class CopyFrame : public CmdSequence
|
||||
, public WithSprite {
|
||||
public:
|
||||
CopyFrame(Sprite* sprite, frame_t fromFrame, frame_t newFrame);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
CmdSequence::onMemSize() - sizeof(CmdSequence);
|
||||
}
|
||||
|
||||
private:
|
||||
frame_t m_fromFrame;
|
||||
frame_t m_newFrame;
|
||||
bool m_firstTime;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
99
src/app/cmd/copy_rect.cpp
Normal file
99
src/app/cmd/copy_rect.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/copy_rect.h"
|
||||
|
||||
#include "doc/image.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
CopyRect::CopyRect(Image* dst, const Image* src, const gfx::Clip& clip)
|
||||
: WithImage(dst)
|
||||
, m_clip(clip)
|
||||
{
|
||||
if (!m_clip.clip(
|
||||
dst->width(), dst->height(),
|
||||
src->width(), src->height()))
|
||||
return;
|
||||
|
||||
// Fill m_data with "src" data
|
||||
|
||||
int lineSize = src->getRowStrideSize(m_clip.size.w);
|
||||
m_data.resize(lineSize * m_clip.size.h);
|
||||
|
||||
auto it = m_data.begin();
|
||||
for (int v=0; v<m_clip.size.h; ++v) {
|
||||
uint8_t* addr = src->getPixelAddress(
|
||||
m_clip.dst.x, m_clip.dst.y+v);
|
||||
|
||||
std::copy(addr, addr+lineSize, it);
|
||||
it += lineSize;
|
||||
}
|
||||
}
|
||||
|
||||
void CopyRect::onExecute()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void CopyRect::onUndo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void CopyRect::onRedo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void CopyRect::swap()
|
||||
{
|
||||
if (m_clip.size.w < 1 || m_clip.size.h < 1)
|
||||
return;
|
||||
|
||||
Image* image = this->image();
|
||||
int lineSize = this->lineSize();
|
||||
std::vector<uint8_t> tmp(lineSize);
|
||||
|
||||
auto it = m_data.begin();
|
||||
for (int v=0; v<m_clip.size.h; ++v) {
|
||||
uint8_t* addr = image->getPixelAddress(
|
||||
m_clip.dst.x, m_clip.dst.y+v);
|
||||
|
||||
std::copy(addr, addr+lineSize, tmp.begin());
|
||||
std::copy(it, it+lineSize, addr);
|
||||
std::copy(tmp.begin(), tmp.end(), it);
|
||||
|
||||
it += lineSize;
|
||||
}
|
||||
}
|
||||
|
||||
int CopyRect::lineSize()
|
||||
{
|
||||
return image()->getRowStrideSize(m_clip.size.w);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
61
src/app/cmd/copy_rect.h
Normal file
61
src/app/cmd/copy_rect.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_COPY_RECT_H_INCLUDED
|
||||
#define APP_CMD_COPY_RECT_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_image.h"
|
||||
#include "gfx/clip.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace doc {
|
||||
class Image;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class CopyRect : public Cmd
|
||||
, public WithImage {
|
||||
public:
|
||||
CopyRect(Image* dst, const Image* src, const gfx::Clip& clip);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) + m_data.size();
|
||||
}
|
||||
|
||||
private:
|
||||
void swap();
|
||||
int lineSize();
|
||||
|
||||
gfx::Clip m_clip;
|
||||
std::vector<uint8_t> m_data;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
96
src/app/cmd/copy_region.cpp
Normal file
96
src/app/cmd/copy_region.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/copy_region.h"
|
||||
|
||||
#include "doc/image.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
CopyRegion::CopyRegion(Image* dst, Image* src,
|
||||
const gfx::Region& region, int dst_dx, int dst_dy)
|
||||
: WithImage(dst)
|
||||
{
|
||||
// Save region pixels
|
||||
for (const auto& rc : region) {
|
||||
gfx::Clip clip(
|
||||
rc.x+dst_dx, rc.y+dst_dy,
|
||||
rc.x, rc.y, rc.w, rc.h);
|
||||
if (!clip.clip(
|
||||
dst->width(), dst->height(),
|
||||
src->width(), src->height()))
|
||||
continue;
|
||||
|
||||
m_region.createUnion(m_region, gfx::Region(clip.dstBounds()));
|
||||
|
||||
for (int y=0; y<clip.size.h; ++y) {
|
||||
m_stream.write(
|
||||
(const char*)src->getPixelAddress(clip.src.x, clip.src.y+y),
|
||||
src->getRowStrideSize(clip.size.w));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CopyRegion::onExecute()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void CopyRegion::onUndo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void CopyRegion::onRedo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void CopyRegion::swap()
|
||||
{
|
||||
Image* image = this->image();
|
||||
|
||||
// Save current image region in "tmp" stream
|
||||
std::stringstream tmp;
|
||||
for (const auto& rc : m_region)
|
||||
for (int y=0; y<rc.h; ++y)
|
||||
tmp.write(
|
||||
(const char*)image->getPixelAddress(rc.x, rc.y+y),
|
||||
image->getRowStrideSize(rc.w));
|
||||
|
||||
// Restore m_stream into the image
|
||||
for (const auto& rc : m_region) {
|
||||
for (int y=0; y<rc.h; ++y) {
|
||||
m_stream.read(
|
||||
(char*)image->getPixelAddress(rc.x, rc.y+y),
|
||||
image->getRowStrideSize(rc.w));
|
||||
}
|
||||
}
|
||||
|
||||
std::swap(m_stream, tmp);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
58
src/app/cmd/copy_region.h
Normal file
58
src/app/cmd/copy_region.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_COPY_REGION_H_INCLUDED
|
||||
#define APP_CMD_COPY_REGION_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_image.h"
|
||||
#include "gfx/region.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class CopyRegion : public Cmd
|
||||
, public WithImage {
|
||||
public:
|
||||
CopyRegion(Image* dst, Image* src,
|
||||
const gfx::Region& region, int src_dx, int src_dy);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
private:
|
||||
void swap();
|
||||
|
||||
gfx::Region m_region;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
60
src/app/cmd/deselect_mask.cpp
Normal file
60
src/app/cmd/deselect_mask.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/deselect_mask.h"
|
||||
|
||||
#include "app/cmd/set_mask.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/mask.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
DeselectMask::DeselectMask(Document* doc)
|
||||
: WithDocument(doc)
|
||||
{
|
||||
}
|
||||
|
||||
void DeselectMask::onExecute()
|
||||
{
|
||||
app::Document* doc = document();
|
||||
m_oldMask.reset(doc->isMaskVisible() ? new Mask(*doc->mask()): nullptr);
|
||||
doc->setMaskVisible(false);
|
||||
}
|
||||
|
||||
void DeselectMask::onUndo()
|
||||
{
|
||||
app::Document* doc = document();
|
||||
|
||||
doc->setMask(m_oldMask);
|
||||
doc->setMaskVisible(true);
|
||||
|
||||
m_oldMask.reset(nullptr);
|
||||
}
|
||||
|
||||
size_t DeselectMask::onMemSize() const
|
||||
{
|
||||
return sizeof(*this) + (m_oldMask ? m_oldMask->getMemSize(): 0);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/deselect_mask.h
Normal file
52
src/app/cmd/deselect_mask.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_DESELECT_MASK_H_INCLUDED
|
||||
#define APP_CMD_DESELECT_MASK_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_document.h"
|
||||
#include "base/unique_ptr.h"
|
||||
|
||||
namespace doc {
|
||||
class Mask;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class DeselectMask : public Cmd
|
||||
, public WithDocument {
|
||||
public:
|
||||
DeselectMask(Document* doc);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override;
|
||||
|
||||
private:
|
||||
base::UniquePtr<Mask> m_oldMask;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
97
src/app/cmd/flatten_layers.cpp
Normal file
97
src/app/cmd/flatten_layers.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/flatten_layers.h"
|
||||
|
||||
#include "app/cmd/add_layer.h"
|
||||
#include "app/cmd/configure_background.h"
|
||||
#include "app/cmd/copy_rect.h"
|
||||
#include "app/cmd/remove_layer.h"
|
||||
#include "app/cmd/remove_layer.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/primitives.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "render/render.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
FlattenLayers::FlattenLayers(Sprite* sprite)
|
||||
: WithSprite(sprite)
|
||||
{
|
||||
}
|
||||
|
||||
void FlattenLayers::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
app::Document* doc = static_cast<app::Document*>(sprite->document());
|
||||
|
||||
// Create a temporary image.
|
||||
ImageRef image(Image::create(sprite->pixelFormat(),
|
||||
sprite->width(),
|
||||
sprite->height()));
|
||||
|
||||
// If there aren't a background layer we must to create the background.
|
||||
LayerImage* background = sprite->backgroundLayer();
|
||||
if (!background) {
|
||||
background = new LayerImage(sprite);
|
||||
executeAndAdd(new cmd::AddLayer(sprite->folder(), background, nullptr));
|
||||
executeAndAdd(new cmd::ConfigureBackground(background));
|
||||
}
|
||||
|
||||
render::Render render;
|
||||
render.setBgType(render::BgType::NONE);
|
||||
color_t bgcolor = doc->bgColor(background);
|
||||
|
||||
// Copy all frames to the background.
|
||||
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
|
||||
// Clear the image and render this frame.
|
||||
clear_image(image, bgcolor);
|
||||
render.renderSprite(image, sprite, frame);
|
||||
|
||||
ImageRef cel_image;
|
||||
Cel* cel = background->cel(frame);
|
||||
if (cel) {
|
||||
cel_image = cel->imageRef();
|
||||
ASSERT(cel_image);
|
||||
|
||||
executeAndAdd(new cmd::CopyRect(cel_image, image,
|
||||
gfx::Clip(0, 0, image->bounds())));
|
||||
}
|
||||
else {
|
||||
cel_image.reset(Image::createCopy(image));
|
||||
cel = new Cel(frame, cel_image);
|
||||
background->addCel(cel);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete old layers.
|
||||
LayerList layers = sprite->folder()->getLayersList();
|
||||
for (Layer* layer : layers)
|
||||
if (layer != background)
|
||||
executeAndAdd(new cmd::RemoveLayer(layer));
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
42
src/app/cmd/flatten_layers.h
Normal file
42
src/app/cmd/flatten_layers.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_FLATTEN_LAYERS_H_INCLUDED
|
||||
#define APP_CMD_FLATTEN_LAYERS_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class FlattenLayers : public CmdSequence
|
||||
, public WithSprite {
|
||||
public:
|
||||
FlattenLayers(Sprite* sprite);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
57
src/app/cmd/flip_image.cpp
Normal file
57
src/app/cmd/flip_image.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/flip_image.h"
|
||||
|
||||
#include "doc/image.h"
|
||||
#include "doc/algorithm/flip_image.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
FlipImage::FlipImage(Image* image, const gfx::Rect& bounds, doc::algorithm::FlipType flipType)
|
||||
: WithImage(image)
|
||||
, m_bounds(bounds)
|
||||
, m_flipType(flipType)
|
||||
{
|
||||
}
|
||||
|
||||
void FlipImage::onExecute()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipImage::onUndo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipImage::swap()
|
||||
{
|
||||
Image* image = this->image();
|
||||
|
||||
// Flip the portion of the bitmap.
|
||||
doc::algorithm::flip_image(image, m_bounds, m_flipType);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
61
src/app/cmd/flip_image.h
Normal file
61
src/app/cmd/flip_image.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_FLIP_IMAGE_H_INCLUDED
|
||||
#define APP_CMD_FLIP_IMAGE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_image.h"
|
||||
#include "doc/algorithm/flip_type.h"
|
||||
#include "gfx/rect.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace doc {
|
||||
class Image;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class FlipImage : public Cmd
|
||||
, public WithImage {
|
||||
public:
|
||||
FlipImage(Image* image, const gfx::Rect& bounds,
|
||||
doc::algorithm::FlipType flipType);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
void swap();
|
||||
|
||||
gfx::Rect m_bounds;
|
||||
doc::algorithm::FlipType m_flipType;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
66
src/app/cmd/flip_mask.cpp
Normal file
66
src/app/cmd/flip_mask.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/flip_mask.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/algorithm/flip_image.h"
|
||||
#include "doc/mask.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
FlipMask::FlipMask(Document* doc, doc::algorithm::FlipType flipType)
|
||||
: WithDocument(doc)
|
||||
, m_flipType(flipType)
|
||||
{
|
||||
}
|
||||
|
||||
void FlipMask::onExecute()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipMask::onUndo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipMask::swap()
|
||||
{
|
||||
Document* document = this->document();
|
||||
Mask* mask = document->mask();
|
||||
|
||||
ASSERT(mask->bitmap());
|
||||
if (!mask->bitmap())
|
||||
return;
|
||||
|
||||
mask->freeze();
|
||||
doc::algorithm::flip_image(mask->bitmap(),
|
||||
mask->bitmap()->bounds(), m_flipType);
|
||||
mask->unfreeze();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/flip_mask.h
Normal file
52
src/app/cmd/flip_mask.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_FLIP_MASK_H_INCLUDED
|
||||
#define APP_CMD_FLIP_MASK_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_document.h"
|
||||
#include "doc/algorithm/flip_type.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class FlipMask : public Cmd
|
||||
, public WithDocument {
|
||||
public:
|
||||
FlipMask(Document* doc, doc::algorithm::FlipType flipType);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
void swap();
|
||||
|
||||
doc::algorithm::FlipType m_flipType;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
70
src/app/cmd/flip_masked_cel.cpp
Normal file
70
src/app/cmd/flip_masked_cel.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/flip_masked_cel.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/algorithm/flip_image.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/mask.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
FlipMaskedCel::FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType)
|
||||
: WithCel(cel)
|
||||
, m_flipType(flipType)
|
||||
, m_bgcolor(static_cast<app::Document*>(cel->document())->bgColor(cel->layer()))
|
||||
{
|
||||
}
|
||||
|
||||
void FlipMaskedCel::onExecute()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipMaskedCel::onUndo()
|
||||
{
|
||||
swap();
|
||||
}
|
||||
|
||||
void FlipMaskedCel::swap()
|
||||
{
|
||||
Cel* cel = this->cel();
|
||||
Image* image = cel->image();
|
||||
Mask* mask = static_cast<app::Document*>(cel->document())->mask();
|
||||
ASSERT(mask->bitmap());
|
||||
if (!mask->bitmap())
|
||||
return;
|
||||
|
||||
int x = cel->x();
|
||||
int y = cel->y();
|
||||
|
||||
mask->offsetOrigin(-x, -y);
|
||||
doc::algorithm::flip_image_with_mask(image, mask, m_flipType, m_bgcolor);
|
||||
mask->offsetOrigin(x, y);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
54
src/app/cmd/flip_masked_cel.h
Normal file
54
src/app/cmd/flip_masked_cel.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_FLIP_MASKED_CEL_H_INCLUDED
|
||||
#define APP_CMD_FLIP_MASKED_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
#include "doc/algorithm/flip_type.h"
|
||||
#include "doc/color.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class FlipMaskedCel : public Cmd
|
||||
, public WithCel {
|
||||
public:
|
||||
FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
void swap();
|
||||
|
||||
doc::algorithm::FlipType m_flipType;
|
||||
color_t m_bgcolor;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
51
src/app/cmd/layer_from_background.cpp
Normal file
51
src/app/cmd/layer_from_background.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/layer_from_background.h"
|
||||
|
||||
#include "app/cmd/set_layer_flags.h"
|
||||
#include "app/cmd/set_layer_name.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
LayerFromBackground::LayerFromBackground(Layer* layer)
|
||||
{
|
||||
ASSERT(layer != NULL);
|
||||
ASSERT(layer->isVisible());
|
||||
ASSERT(layer->isEditable());
|
||||
ASSERT(layer->isBackground());
|
||||
ASSERT(layer->sprite() != NULL);
|
||||
ASSERT(layer->sprite()->backgroundLayer() != NULL);
|
||||
|
||||
// Remove "Background" and "LockMove" flags
|
||||
LayerFlags newFlags = LayerFlags(int(layer->flags())
|
||||
& ~int(LayerFlags::BackgroundLayerFlags));
|
||||
|
||||
add(new cmd::SetLayerFlags(layer, newFlags));
|
||||
add(new cmd::SetLayerName(layer, "Layer 0"));
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
41
src/app/cmd/layer_from_background.h
Normal file
41
src/app/cmd/layer_from_background.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_LAYER_FROM_BACKGROUND_H_INCLUDED
|
||||
#define APP_CMD_LAYER_FROM_BACKGROUND_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd_sequence.h"
|
||||
|
||||
namespace doc {
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class LayerFromBackground : public CmdSequence {
|
||||
public:
|
||||
LayerFromBackground(Layer* layer);
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
146
src/app/cmd/move_cel.cpp
Normal file
146
src/app/cmd/move_cel.cpp
Normal file
@ -0,0 +1,146 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/move_cel.h"
|
||||
|
||||
#include "app/cmd/add_cel.h"
|
||||
#include "app/cmd/add_frame.h"
|
||||
#include "app/cmd/clear_cel.h"
|
||||
#include "app/cmd/clear_image.h"
|
||||
#include "app/cmd/copy_rect.h"
|
||||
#include "app/cmd/remove_cel.h"
|
||||
#include "app/cmd/set_cel_frame.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/primitives.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "render/render.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
MoveCel::MoveCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame)
|
||||
: m_srcLayer(srcLayer)
|
||||
, m_dstLayer(dstLayer)
|
||||
, m_srcFrame(srcFrame)
|
||||
, m_dstFrame(dstFrame)
|
||||
{
|
||||
}
|
||||
|
||||
void MoveCel::onExecute()
|
||||
{
|
||||
LayerImage* srcLayer = static_cast<LayerImage*>(m_srcLayer.layer());
|
||||
LayerImage* dstLayer = static_cast<LayerImage*>(m_dstLayer.layer());
|
||||
|
||||
ASSERT(srcLayer);
|
||||
ASSERT(dstLayer);
|
||||
|
||||
Sprite* srcSprite = srcLayer->sprite();
|
||||
Sprite* dstSprite = dstLayer->sprite();
|
||||
ASSERT(srcSprite);
|
||||
ASSERT(dstSprite);
|
||||
ASSERT(m_srcFrame >= 0 && m_srcFrame < srcSprite->totalFrames());
|
||||
ASSERT(m_dstFrame >= 0);
|
||||
(void)srcSprite; // To avoid unused variable warning on Release mode
|
||||
|
||||
Cel* srcCel = srcLayer->cel(m_srcFrame);
|
||||
Cel* dstCel = dstLayer->cel(m_dstFrame);
|
||||
|
||||
// Clear destination cel if it does exist. It'll be overriden by the
|
||||
// copy of srcCel.
|
||||
if (dstCel)
|
||||
executeAndAdd(new cmd::ClearCel(dstCel));
|
||||
|
||||
// Add empty frames until newFrame
|
||||
while (dstSprite->totalFrames() <= m_dstFrame)
|
||||
executeAndAdd(new cmd::AddFrame(dstSprite, dstSprite->totalFrames()));
|
||||
|
||||
Image* srcImage = (srcCel ? srcCel->image(): NULL);
|
||||
ImageRef dstImage;
|
||||
dstCel = dstLayer->cel(m_dstFrame);
|
||||
if (dstCel)
|
||||
dstImage = dstCel->imageRef();
|
||||
|
||||
if (srcCel) {
|
||||
if (srcLayer == dstLayer) {
|
||||
if (dstLayer->isBackground()) {
|
||||
ASSERT(dstImage);
|
||||
if (dstImage) {
|
||||
int blend = (srcLayer->isBackground() ?
|
||||
BLEND_MODE_COPY: BLEND_MODE_NORMAL);
|
||||
|
||||
ImageRef tmp(Image::createCopy(dstImage));
|
||||
render::composite_image(tmp, srcImage,
|
||||
srcCel->x(), srcCel->y(), 255, blend);
|
||||
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
|
||||
}
|
||||
|
||||
executeAndAdd(new cmd::ClearImage(srcImage,
|
||||
static_cast<app::Document*>(srcSprite->document())
|
||||
->bgColor(srcLayer)));
|
||||
}
|
||||
// Move the cel in the same layer.
|
||||
else {
|
||||
executeAndAdd(new cmd::SetCelFrame(srcCel, m_dstFrame));
|
||||
}
|
||||
}
|
||||
// Move the cel between different layers.
|
||||
else {
|
||||
if (!dstCel) {
|
||||
dstImage.reset(Image::createCopy(srcImage));
|
||||
|
||||
dstCel = new Cel(*srcCel);
|
||||
dstCel->setFrame(m_dstFrame);
|
||||
dstCel->setImage(dstImage);
|
||||
}
|
||||
|
||||
if (dstLayer->isBackground()) {
|
||||
ImageRef tmp(Image::createCopy(dstImage));
|
||||
render::composite_image(tmp, srcImage,
|
||||
srcCel->x(), srcCel->y(), 255, BLEND_MODE_NORMAL);
|
||||
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
|
||||
}
|
||||
else {
|
||||
executeAndAdd(new cmd::AddCel(dstLayer, dstCel));
|
||||
}
|
||||
|
||||
executeAndAdd(new cmd::ClearCel(srcCel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MoveCel::onFireNotifications()
|
||||
{
|
||||
CmdSequence::onFireNotifications();
|
||||
static_cast<app::Document*>(m_dstLayer.layer()->sprite()->document())
|
||||
->notifyCelMoved(
|
||||
m_srcLayer.layer(), m_srcFrame,
|
||||
m_dstLayer.layer(), m_dstFrame);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
54
src/app/cmd/move_cel.h
Normal file
54
src/app/cmd/move_cel.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_MOVE_CEL_H_INCLUDED
|
||||
#define APP_CMD_MOVE_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd/with_layer.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
namespace doc {
|
||||
class LayerImage;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class MoveCel : public CmdSequence {
|
||||
public:
|
||||
MoveCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onFireNotifications() override;
|
||||
|
||||
private:
|
||||
WithLayer m_srcLayer, m_dstLayer;
|
||||
frame_t m_srcFrame, m_dstFrame;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
67
src/app/cmd/move_layer.cpp
Normal file
67
src/app/cmd/move_layer.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/move_layer.h"
|
||||
|
||||
#include "doc/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
MoveLayer::MoveLayer(Layer* layer, Layer* afterThis)
|
||||
: m_layer(layer)
|
||||
, m_oldAfterThis(layer->getPrevious())
|
||||
, m_newAfterThis(afterThis)
|
||||
{
|
||||
}
|
||||
|
||||
void MoveLayer::onExecute()
|
||||
{
|
||||
m_layer.layer()->parent()->stackLayer(
|
||||
m_layer.layer(),
|
||||
m_newAfterThis.layer());
|
||||
}
|
||||
|
||||
void MoveLayer::onUndo()
|
||||
{
|
||||
m_layer.layer()->parent()->stackLayer(
|
||||
m_layer.layer(),
|
||||
m_oldAfterThis.layer());
|
||||
}
|
||||
|
||||
void MoveLayer::onFireNotifications()
|
||||
{
|
||||
Layer* layer = m_layer.layer();
|
||||
doc::Document* doc = layer->sprite()->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(layer->sprite());
|
||||
ev.layer(layer);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onLayerRestacked, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
51
src/app/cmd/move_layer.h
Normal file
51
src/app/cmd/move_layer.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_MOVE_LAYER_H_INCLUDED
|
||||
#define APP_CMD_MOVE_LAYER_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class MoveLayer : public Cmd {
|
||||
public:
|
||||
MoveLayer(Layer* layer, Layer* afterThis);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
WithLayer m_layer;
|
||||
WithLayer m_oldAfterThis;
|
||||
WithLayer m_newAfterThis;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,7 +20,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/object_io.h"
|
||||
#include "app/cmd/object_io.h"
|
||||
|
||||
#include "doc/cel.h"
|
||||
#include "doc/cel_io.h"
|
||||
@ -30,13 +30,12 @@
|
||||
#include "doc/layer_io.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
using namespace doc;
|
||||
|
||||
ObjectIO::ObjectIO(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_objects(objects)
|
||||
, m_sprite(sprite)
|
||||
ObjectIO::ObjectIO(Sprite* sprite)
|
||||
: m_sprite(sprite)
|
||||
{
|
||||
}
|
||||
|
||||
@ -82,5 +81,5 @@ Layer* ObjectIO::read_layer(std::istream& is)
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,14 +16,13 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_OBJECT_IO_H_INCLUDED
|
||||
#define APP_UNDOERS_OBJECT_IO_H_INCLUDED
|
||||
#ifndef APP_CMD_OBJECT_IO_H_INCLUDED
|
||||
#define APP_CMD_OBJECT_IO_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/subobjects_io.h"
|
||||
#include "undo/objects_container.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
@ -33,13 +32,12 @@ namespace doc {
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
|
||||
class ObjectIO : public SubObjectsIO {
|
||||
public:
|
||||
ObjectIO(ObjectsContainer* objects, Sprite* sprite);
|
||||
ObjectIO(Sprite* sprite);
|
||||
virtual ~ObjectIO();
|
||||
|
||||
// How to write cels, images, and sub-layers
|
||||
@ -66,15 +64,8 @@ namespace undoers {
|
||||
{
|
||||
using base::serialization::little_endian::write32;
|
||||
|
||||
// Get an ID for the image.
|
||||
undo::ObjectId objectId = m_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).
|
||||
m_objects->removeObject(objectId);
|
||||
write32(os, object->id()); // Write the ID
|
||||
writer(os, object); // Write the object
|
||||
}
|
||||
|
||||
// Deserializes the given object from the stream, adding the object
|
||||
@ -84,19 +75,17 @@ namespace undoers {
|
||||
{
|
||||
using base::serialization::little_endian::read32;
|
||||
|
||||
undo::ObjectId objectId = read32(is); // Read the ID
|
||||
base::UniquePtr<T> object(reader(is)); // Read the object
|
||||
doc::ObjectId objectId = read32(is); // Read the ID
|
||||
base::UniquePtr<T> object(reader(is)); // Read the object
|
||||
|
||||
// Re-insert the object in the container with the read ID.
|
||||
m_objects->insertObject(objectId, object);
|
||||
object->setId(objectId);
|
||||
return object.release();
|
||||
}
|
||||
|
||||
ObjectsContainer* m_objects;
|
||||
Sprite* m_sprite;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_OBJECT_IO_H_INCLUDED
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,37 +20,35 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_cel_opacity.h"
|
||||
#include "app/cmd/remove_cel.h"
|
||||
|
||||
#include "doc/cel.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
using namespace doc;
|
||||
|
||||
SetCelOpacity::SetCelOpacity(ObjectsContainer* objects, Cel* cel)
|
||||
: m_celId(objects->addObject(cel))
|
||||
, m_opacity(cel->opacity())
|
||||
RemoveCel::RemoveCel(Cel* cel)
|
||||
: AddCel(cel->layer(), cel)
|
||||
{
|
||||
}
|
||||
|
||||
void SetCelOpacity::dispose()
|
||||
void RemoveCel::onExecute()
|
||||
{
|
||||
delete this;
|
||||
AddCel::onUndo();
|
||||
}
|
||||
|
||||
void SetCelOpacity::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void RemoveCel::onUndo()
|
||||
{
|
||||
Cel* cel = objects->getObjectT<Cel>(m_celId);
|
||||
|
||||
// Push another SetCelOpacity as redoer
|
||||
redoers->pushUndoer(new SetCelOpacity(objects, cel));
|
||||
|
||||
cel->setOpacity(m_opacity);
|
||||
AddCel::onRedo();
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void RemoveCel::onRedo()
|
||||
{
|
||||
AddCel::onUndo();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
42
src/app/cmd/remove_cel.h
Normal file
42
src/app/cmd/remove_cel.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_REMOVE_CEL_H_INCLUDED
|
||||
#define APP_CMD_REMOVE_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd/add_cel.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class RemoveCel : public AddCel {
|
||||
public:
|
||||
RemoveCel(Cel* cel);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
81
src/app/cmd/remove_frame.cpp
Normal file
81
src/app/cmd/remove_frame.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/remove_frame.h"
|
||||
|
||||
#include "app/cmd/remove_cel.h"
|
||||
#include "doc/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
RemoveFrame::RemoveFrame(Sprite* sprite, frame_t frame)
|
||||
: WithSprite(sprite)
|
||||
, m_frame(frame)
|
||||
, m_firstTime(true)
|
||||
{
|
||||
for (Cel* cel : sprite->cels(m_frame))
|
||||
m_seq.add(new cmd::RemoveCel(cel));
|
||||
}
|
||||
|
||||
void RemoveFrame::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Document* doc = sprite->document();
|
||||
|
||||
if (m_firstTime) {
|
||||
m_firstTime = false;
|
||||
m_seq.execute(context());
|
||||
}
|
||||
else
|
||||
m_seq.redo();
|
||||
|
||||
sprite->removeFrame(m_frame);
|
||||
|
||||
// Notify observers.
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(m_frame);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onRemoveFrame, ev);
|
||||
}
|
||||
|
||||
void RemoveFrame::onUndo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Document* doc = sprite->document();
|
||||
|
||||
sprite->addFrame(m_frame);
|
||||
m_seq.undo();
|
||||
|
||||
// Notify observers about the new frame.
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(m_frame);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onAddFrame, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
53
src/app/cmd/remove_frame.h
Normal file
53
src/app/cmd/remove_frame.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_REMOVE_FRAME_H_INCLUDED
|
||||
#define APP_CMD_REMOVE_FRAME_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class RemoveFrame : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
RemoveFrame(Sprite* sprite, frame_t frame);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) + m_seq.memSize();
|
||||
}
|
||||
|
||||
private:
|
||||
frame_t m_frame;
|
||||
CmdSequence m_seq;
|
||||
bool m_firstTime;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,37 +20,35 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_layer_name.h"
|
||||
#include "app/cmd/remove_layer.h"
|
||||
|
||||
#include "doc/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
using namespace doc;
|
||||
|
||||
SetLayerName::SetLayerName(ObjectsContainer* objects, Layer* layer)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
, m_name(layer->name())
|
||||
RemoveLayer::RemoveLayer(Layer* layer)
|
||||
: AddLayer(layer->parent(), layer, layer->getPrevious())
|
||||
{
|
||||
}
|
||||
|
||||
void SetLayerName::dispose()
|
||||
void RemoveLayer::onExecute()
|
||||
{
|
||||
delete this;
|
||||
AddLayer::onUndo();
|
||||
}
|
||||
|
||||
void SetLayerName::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void RemoveLayer::onUndo()
|
||||
{
|
||||
Layer* layer = objects->getObjectT<Layer>(m_layerId);
|
||||
|
||||
// Push another SetLayerName as redoer
|
||||
redoers->pushUndoer(new SetLayerName(objects, layer));
|
||||
|
||||
layer->setName(m_name.c_str());
|
||||
AddLayer::onRedo();
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void RemoveLayer::onRedo()
|
||||
{
|
||||
AddLayer::onUndo();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
42
src/app/cmd/remove_layer.h
Normal file
42
src/app/cmd/remove_layer.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_REMOVE_LAYER_H_INCLUDED
|
||||
#define APP_CMD_REMOVE_LAYER_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd/add_layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class RemoveLayer : public AddLayer {
|
||||
public:
|
||||
RemoveLayer(Layer* layer);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
51
src/app/cmd/remove_palette.cpp
Normal file
51
src/app/cmd/remove_palette.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/remove_palette.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
RemovePalette::RemovePalette(Sprite* sprite, Palette* pal)
|
||||
: AddPalette(sprite, pal)
|
||||
{
|
||||
}
|
||||
|
||||
void RemovePalette::onExecute()
|
||||
{
|
||||
AddPalette::onUndo();
|
||||
}
|
||||
|
||||
void RemovePalette::onUndo()
|
||||
{
|
||||
AddPalette::onRedo();
|
||||
}
|
||||
|
||||
void RemovePalette::onRedo()
|
||||
{
|
||||
AddPalette::onUndo();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
42
src/app/cmd/remove_palette.h
Normal file
42
src/app/cmd/remove_palette.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_REMOVE_PALETTE_H_INCLUDED
|
||||
#define APP_CMD_REMOVE_PALETTE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd/add_palette.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class RemovePalette : public AddPalette {
|
||||
public:
|
||||
RemovePalette(Sprite* sprite, Palette* pal);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
80
src/app/cmd/replace_image.cpp
Normal file
80
src/app/cmd/replace_image.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/replace_image.h"
|
||||
|
||||
#include "app/cmd/object_io.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/image_io.h"
|
||||
#include "doc/image_ref.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
ReplaceImage::ReplaceImage(Sprite* sprite, const ImageRef& oldImage, const ImageRef& newImage)
|
||||
: WithSprite(sprite)
|
||||
, m_oldImageId(oldImage->id())
|
||||
, m_newImageId(newImage->id())
|
||||
, m_newImage(newImage)
|
||||
{
|
||||
}
|
||||
|
||||
void ReplaceImage::onExecute()
|
||||
{
|
||||
// Save old image in m_copy. We cannot keep an ImageRef to this
|
||||
// image, because there are other undo branches that could try to
|
||||
// modify/re-add this same image ID
|
||||
ImageRef oldImage = sprite()->getImage(m_oldImageId);
|
||||
ASSERT(oldImage);
|
||||
m_copy.reset(Image::createCopy(oldImage));
|
||||
|
||||
sprite()->replaceImage(m_oldImageId, m_newImage);
|
||||
m_newImage.reset(nullptr);
|
||||
}
|
||||
|
||||
void ReplaceImage::onUndo()
|
||||
{
|
||||
ImageRef newImage = sprite()->getImage(m_newImageId);
|
||||
ASSERT(newImage);
|
||||
ASSERT(!sprite()->getImage(m_oldImageId));
|
||||
m_copy->setId(m_oldImageId);
|
||||
|
||||
sprite()->replaceImage(m_newImageId, m_copy);
|
||||
m_copy.reset(Image::createCopy(newImage));
|
||||
}
|
||||
|
||||
void ReplaceImage::onRedo()
|
||||
{
|
||||
ImageRef oldImage = sprite()->getImage(m_oldImageId);
|
||||
ASSERT(oldImage);
|
||||
ASSERT(!sprite()->getImage(m_newImageId));
|
||||
m_copy->setId(m_newImageId);
|
||||
|
||||
sprite()->replaceImage(m_oldImageId, m_copy);
|
||||
m_copy.reset(Image::createCopy(oldImage));
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
62
src/app/cmd/replace_image.h
Normal file
62
src/app/cmd/replace_image.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 3 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 APP_CMD_REPLACE_IMAGE_H_INCLUDED
|
||||
#define APP_CMD_REPLACE_IMAGE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
// #include "app/cmd/with_image.h"
|
||||
#include "doc/image_ref.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class ReplaceImage : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
ReplaceImage(Sprite* sprite, const ImageRef& oldImage, const ImageRef& newImage);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
(m_copy ? m_copy->getMemSize(): 0);
|
||||
}
|
||||
|
||||
private:
|
||||
// Reference used only to keep the copy of the new image from the
|
||||
// ReplaceImage() ctor until the ReplaceImage::onExecute() call.
|
||||
// Then the reference is not used anymore.
|
||||
ImageRef m_newImage;
|
||||
|
||||
ObjectId m_oldImageId;
|
||||
ObjectId m_newImageId;
|
||||
ImageRef m_copy;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
64
src/app/cmd/reselect_mask.cpp
Normal file
64
src/app/cmd/reselect_mask.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/reselect_mask.h"
|
||||
|
||||
#include "app/cmd/set_mask.h"
|
||||
#include "app/document.h"
|
||||
#include "doc/mask.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
ReselectMask::ReselectMask(Document* doc)
|
||||
: WithDocument(doc)
|
||||
{
|
||||
}
|
||||
|
||||
void ReselectMask::onExecute()
|
||||
{
|
||||
app::Document* doc = document();
|
||||
|
||||
if (m_oldMask) {
|
||||
doc->setMask(m_oldMask);
|
||||
m_oldMask.reset(nullptr);
|
||||
}
|
||||
|
||||
doc->setMaskVisible(true);
|
||||
}
|
||||
|
||||
void ReselectMask::onUndo()
|
||||
{
|
||||
app::Document* doc = document();
|
||||
|
||||
m_oldMask.reset(doc->isMaskVisible() ? new Mask(*doc->mask()): nullptr);
|
||||
|
||||
doc->setMaskVisible(false);
|
||||
}
|
||||
|
||||
size_t ReselectMask::onMemSize() const
|
||||
{
|
||||
return sizeof(*this) + (m_oldMask ? m_oldMask->getMemSize(): 0);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/reselect_mask.h
Normal file
52
src/app/cmd/reselect_mask.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_RESELECT_MASK_H_INCLUDED
|
||||
#define APP_CMD_RESELECT_MASK_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_document.h"
|
||||
#include "base/unique_ptr.h"
|
||||
|
||||
namespace doc {
|
||||
class Mask;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class ReselectMask : public Cmd
|
||||
, public WithDocument {
|
||||
public:
|
||||
ReselectMask(Document* doc);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override;
|
||||
|
||||
private:
|
||||
base::UniquePtr<Mask> m_oldMask;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,41 +20,49 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/remove_cel.h"
|
||||
#include "app/cmd/set_cel_frame.h"
|
||||
|
||||
#include "app/undoers/add_cel.h"
|
||||
#include "app/undoers/object_io.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
|
||||
RemoveCel::RemoveCel(ObjectsContainer* objects, Layer* layer, Cel* cel)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
SetCelFrame::SetCelFrame(Cel* cel, frame_t frame)
|
||||
: WithCel(cel)
|
||||
, m_oldFrame(cel->frame())
|
||||
, m_newFrame(frame)
|
||||
{
|
||||
ObjectIO(objects, layer->sprite()).write_cel(m_stream, cel);
|
||||
}
|
||||
|
||||
void RemoveCel::dispose()
|
||||
void SetCelFrame::onExecute()
|
||||
{
|
||||
delete this;
|
||||
Cel* cel = this->cel();
|
||||
cel->layer()->moveCel(cel, m_newFrame);
|
||||
}
|
||||
|
||||
void RemoveCel::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetCelFrame::onUndo()
|
||||
{
|
||||
LayerImage* layer = objects->getObjectT<LayerImage>(m_layerId);
|
||||
Cel* cel = ObjectIO(objects, layer->sprite()).read_cel(m_stream);
|
||||
|
||||
redoers->pushUndoer(new AddCel(objects, layer, cel));
|
||||
|
||||
layer->addCel(cel);
|
||||
Cel* cel = this->cel();
|
||||
cel->layer()->moveCel(cel, m_oldFrame);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void SetCelFrame::onFireNotifications()
|
||||
{
|
||||
Cel* cel = this->cel();
|
||||
doc::Document* doc = cel->sprite()->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(cel->layer()->sprite());
|
||||
ev.layer(cel->layer());
|
||||
ev.cel(cel);
|
||||
ev.frame(cel->frame());
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onCelFrameChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
51
src/app/cmd/set_cel_frame.h
Normal file
51
src/app/cmd/set_cel_frame.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_CEL_FRAME_H_INCLUDED
|
||||
#define APP_CMD_SET_CEL_FRAME_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetCelFrame : public Cmd
|
||||
, public WithCel {
|
||||
public:
|
||||
SetCelFrame(Cel* cel, frame_t frame);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
frame_t m_oldFrame;
|
||||
frame_t m_newFrame;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
61
src/app/cmd/set_cel_opacity.cpp
Normal file
61
src/app/cmd/set_cel_opacity.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_cel_opacity.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document_event.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
SetCelOpacity::SetCelOpacity(Cel* cel, int opacity)
|
||||
: WithCel(cel)
|
||||
, m_oldOpacity(cel->opacity())
|
||||
, m_newOpacity(opacity)
|
||||
{
|
||||
}
|
||||
|
||||
void SetCelOpacity::onExecute()
|
||||
{
|
||||
cel()->setOpacity(m_newOpacity);
|
||||
}
|
||||
|
||||
void SetCelOpacity::onUndo()
|
||||
{
|
||||
cel()->setOpacity(m_oldOpacity);
|
||||
}
|
||||
|
||||
void SetCelOpacity::onFireNotifications()
|
||||
{
|
||||
Cel* cel = this->cel();
|
||||
DocumentEvent ev(cel->document());
|
||||
ev.sprite(cel->sprite());
|
||||
ev.cel(cel);
|
||||
cel->document()->notifyObservers<DocumentEvent&>(&DocumentObserver::onCelOpacityChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
51
src/app/cmd/set_cel_opacity.h
Normal file
51
src/app/cmd/set_cel_opacity.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_CEL_OPACITY_H_INCLUDED
|
||||
#define APP_CMD_SET_CEL_OPACITY_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetCelOpacity : public Cmd
|
||||
, public WithCel {
|
||||
public:
|
||||
SetCelOpacity(Cel* cel, int opacity);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_oldOpacity;
|
||||
int m_newOpacity;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,38 +20,44 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/add_layer.h"
|
||||
#include "app/cmd/set_cel_position.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "app/document_api.h"
|
||||
#include "app/undoers/remove_layer.h"
|
||||
#include "doc/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document_event.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
using namespace doc;
|
||||
|
||||
AddLayer::AddLayer(ObjectsContainer* objects, Document* document, Layer* layer)
|
||||
: m_documentId(objects->addObject(document))
|
||||
, m_layerId(objects->addObject(layer))
|
||||
SetCelPosition::SetCelPosition(Cel* cel, int x, int y)
|
||||
: WithCel(cel)
|
||||
, m_oldX(cel->x())
|
||||
, m_oldY(cel->y())
|
||||
, m_newX(x)
|
||||
, m_newY(y)
|
||||
{
|
||||
}
|
||||
|
||||
void AddLayer::dispose()
|
||||
void SetCelPosition::onExecute()
|
||||
{
|
||||
delete this;
|
||||
cel()->setPosition(m_newX, m_newY);
|
||||
}
|
||||
|
||||
void AddLayer::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetCelPosition::onUndo()
|
||||
{
|
||||
Document* document = objects->getObjectT<Document>(m_documentId);
|
||||
Layer* layer = objects->getObjectT<Layer>(m_layerId);
|
||||
|
||||
document->getApi(redoers).removeLayer(layer);
|
||||
cel()->setPosition(m_oldX, m_oldY);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void SetCelPosition::onFireNotifications()
|
||||
{
|
||||
Cel* cel = this->cel();
|
||||
DocumentEvent ev(cel->document());
|
||||
ev.sprite(cel->sprite());
|
||||
ev.cel(cel);
|
||||
cel->document()->notifyObservers<DocumentEvent&>(&DocumentObserver::onCelPositionChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
51
src/app/cmd/set_cel_position.h
Normal file
51
src/app/cmd/set_cel_position.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_CEL_POSITION_H_INCLUDED
|
||||
#define APP_CMD_SET_CEL_POSITION_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetCelPosition : public Cmd
|
||||
, public WithCel {
|
||||
public:
|
||||
SetCelPosition(Cel* cel, int x, int y);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_oldX, m_oldY;
|
||||
int m_newX, m_newY;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,40 +20,42 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_frame_duration.h"
|
||||
#include "app/cmd/set_frame_duration.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
|
||||
SetFrameDuration::SetFrameDuration(ObjectsContainer* objects, Sprite* sprite, frame_t frame)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
SetFrameDuration::SetFrameDuration(Sprite* sprite, frame_t frame, int duration)
|
||||
: WithSprite(sprite)
|
||||
, m_frame(frame)
|
||||
, m_oldDuration(sprite->frameDuration(frame))
|
||||
, m_newDuration(duration)
|
||||
{
|
||||
ASSERT(frame >= 0 && frame < sprite->totalFrames());
|
||||
|
||||
m_duration = sprite->frameDuration(frame);
|
||||
}
|
||||
|
||||
void SetFrameDuration::dispose()
|
||||
void SetFrameDuration::onExecute()
|
||||
{
|
||||
delete this;
|
||||
sprite()->setFrameDuration(m_frame, m_newDuration);
|
||||
}
|
||||
|
||||
void SetFrameDuration::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetFrameDuration::onUndo()
|
||||
{
|
||||
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);
|
||||
sprite()->setFrameDuration(m_frame, m_oldDuration);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void SetFrameDuration::onFireNotifications()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
doc::Document* doc = sprite->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(m_frame);
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onFrameDurationChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
53
src/app/cmd/set_frame_duration.h
Normal file
53
src/app/cmd/set_frame_duration.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_FRAME_DURATION_H_INCLUDED
|
||||
#define APP_CMD_SET_FRAME_DURATION_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetFrameDuration : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
SetFrameDuration(Sprite* sprite, frame_t frame, int duration);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
frame_t m_frame;
|
||||
int m_oldDuration;
|
||||
int m_newDuration;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
46
src/app/cmd/set_layer_flags.cpp
Normal file
46
src/app/cmd/set_layer_flags.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_layer_flags.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
SetLayerFlags::SetLayerFlags(Layer* layer, LayerFlags flags)
|
||||
: WithLayer(layer)
|
||||
, m_oldFlags(layer->flags())
|
||||
, m_newFlags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
void SetLayerFlags::onExecute()
|
||||
{
|
||||
layer()->setFlags(m_newFlags);
|
||||
}
|
||||
|
||||
void SetLayerFlags::onUndo()
|
||||
{
|
||||
layer()->setFlags(m_oldFlags);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
51
src/app/cmd/set_layer_flags.h
Normal file
51
src/app/cmd/set_layer_flags.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_LAYER_FLAGS_H_INCLUDED
|
||||
#define APP_CMD_SET_LAYER_FLAGS_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetLayerFlags : public Cmd
|
||||
, public WithLayer {
|
||||
public:
|
||||
SetLayerFlags(Layer* layer, LayerFlags flags);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
LayerFlags m_oldFlags;
|
||||
LayerFlags m_newFlags;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,37 +20,29 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_layer_flags.h"
|
||||
#include "app/cmd/set_layer_name.h"
|
||||
|
||||
#include "doc/layer.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
|
||||
SetLayerFlags::SetLayerFlags(ObjectsContainer* objects, Layer* layer)
|
||||
: m_layerId(objects->addObject(layer))
|
||||
, m_flags(uint32_t(layer->flags()))
|
||||
SetLayerName::SetLayerName(Layer* layer, const std::string& name)
|
||||
: WithLayer(layer)
|
||||
, m_oldName(layer->name())
|
||||
, m_newName(name)
|
||||
{
|
||||
}
|
||||
|
||||
void SetLayerFlags::dispose()
|
||||
void SetLayerName::onExecute()
|
||||
{
|
||||
delete this;
|
||||
layer()->setName(m_newName);
|
||||
}
|
||||
|
||||
void SetLayerFlags::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetLayerName::onUndo()
|
||||
{
|
||||
Layer* layer = objects->getObjectT<Layer>(m_layerId);
|
||||
|
||||
// Push another SetLayerFlags as redoer
|
||||
redoers->pushUndoer(new SetLayerFlags(objects, layer));
|
||||
|
||||
layer->setFlags(LayerFlags(m_flags));
|
||||
layer()->setName(m_oldName);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,38 +16,37 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_SET_LAYER_FLAGS_H_INCLUDED
|
||||
#define APP_UNDOERS_SET_LAYER_FLAGS_H_INCLUDED
|
||||
#ifndef APP_CMD_SET_LAYER_NAME_H_INCLUDED
|
||||
#define APP_CMD_SET_LAYER_NAME_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace doc {
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetLayerFlags : public UndoerBase {
|
||||
public:
|
||||
SetLayerFlags(ObjectsContainer* objects, Layer* layer);
|
||||
class SetLayerName : public Cmd
|
||||
, public WithLayer {
|
||||
public:
|
||||
SetLayerName(Layer* layer, const std::string& name);
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
undo::ObjectId m_layerId;
|
||||
uint32_t m_flags;
|
||||
};
|
||||
private:
|
||||
std::string m_oldName;
|
||||
std::string m_newName;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_SET_LAYER_FLAGS_H_INCLUDED
|
||||
#endif
|
77
src/app/cmd/set_mask.cpp
Normal file
77
src/app/cmd/set_mask.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_mask.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/mask.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
SetMask::SetMask(Document* doc, Mask* newMask)
|
||||
: WithDocument(doc)
|
||||
, m_oldMask(doc->isMaskVisible() ? new Mask(*doc->mask()): nullptr)
|
||||
, m_newMask(newMask && !newMask->isEmpty() ? new Mask(*newMask): nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void SetMask::setNewMask(Mask* newMask)
|
||||
{
|
||||
m_newMask.reset(newMask ? new Mask(*newMask): nullptr);
|
||||
setMask(m_newMask);
|
||||
}
|
||||
|
||||
void SetMask::onExecute()
|
||||
{
|
||||
setMask(m_newMask);
|
||||
}
|
||||
|
||||
void SetMask::onUndo()
|
||||
{
|
||||
setMask(m_oldMask);
|
||||
}
|
||||
|
||||
size_t SetMask::onMemSize() const
|
||||
{
|
||||
return sizeof(*this) +
|
||||
(m_oldMask ? m_oldMask->getMemSize(): 0) +
|
||||
(m_newMask ? m_newMask->getMemSize(): 0);
|
||||
}
|
||||
|
||||
void SetMask::setMask(Mask* mask)
|
||||
{
|
||||
app::Document* doc = document();
|
||||
|
||||
if (mask) {
|
||||
doc->setMask(mask);
|
||||
doc->setMaskVisible(!mask->isEmpty());
|
||||
}
|
||||
else {
|
||||
Mask empty;
|
||||
doc->setMask(&empty);
|
||||
doc->setMaskVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,35 +16,45 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_SET_MASK_POSITION_H_INCLUDED
|
||||
#define APP_UNDOERS_SET_MASK_POSITION_H_INCLUDED
|
||||
#ifndef APP_CMD_SET_MASK_H_INCLUDED
|
||||
#define APP_CMD_SET_MASK_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "undo/object_id.h"
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_document.h"
|
||||
#include "base/unique_ptr.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace doc {
|
||||
class Mask;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class Document;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
namespace undoers {
|
||||
using namespace undo;
|
||||
class SetMask : public Cmd
|
||||
, public WithDocument {
|
||||
public:
|
||||
SetMask(Document* doc, Mask* newMask);
|
||||
|
||||
class SetMaskPosition : public UndoerBase {
|
||||
public:
|
||||
SetMaskPosition(ObjectsContainer* objects, Document* document);
|
||||
// Used to change the new mask used in the onRedo()
|
||||
void setNewMask(Mask* newMask);
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override;
|
||||
|
||||
private:
|
||||
undo::ObjectId m_documentId;
|
||||
int m_x, m_y;
|
||||
};
|
||||
private:
|
||||
void setMask(Mask* mask);
|
||||
|
||||
} // namespace undoers
|
||||
base::UniquePtr<Mask> m_oldMask;
|
||||
base::UniquePtr<Mask> m_newMask;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_SET_MASK_POSITION_H_INCLUDED
|
||||
#endif
|
56
src/app/cmd/set_mask_position.cpp
Normal file
56
src/app/cmd/set_mask_position.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_mask_position.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/mask.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
SetMaskPosition::SetMaskPosition(Document* doc, const gfx::Point& pos)
|
||||
: WithDocument(doc)
|
||||
, m_oldPosition(doc->mask()->bounds().getOrigin())
|
||||
, m_newPosition(pos)
|
||||
{
|
||||
}
|
||||
|
||||
void SetMaskPosition::onExecute()
|
||||
{
|
||||
setMaskPosition(m_newPosition);
|
||||
}
|
||||
|
||||
void SetMaskPosition::onUndo()
|
||||
{
|
||||
setMaskPosition(m_oldPosition);
|
||||
}
|
||||
|
||||
void SetMaskPosition::setMaskPosition(const gfx::Point& pos)
|
||||
{
|
||||
Document* doc = document();
|
||||
doc->mask()->setOrigin(pos.x, pos.y);
|
||||
doc->resetTransformation();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
53
src/app/cmd/set_mask_position.h
Normal file
53
src/app/cmd/set_mask_position.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_MASK_POSITION_H_INCLUDED
|
||||
#define APP_CMD_SET_MASK_POSITION_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_document.h"
|
||||
#include "gfx/point.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetMaskPosition : public Cmd
|
||||
, public WithDocument {
|
||||
public:
|
||||
SetMaskPosition(Document* doc, const gfx::Point& pos);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
void setMaskPosition(const gfx::Point& pos);
|
||||
|
||||
gfx::Point m_oldPosition;
|
||||
gfx::Point m_newPosition;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
75
src/app/cmd/set_palette.cpp
Normal file
75
src/app/cmd/set_palette.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_palette.h"
|
||||
|
||||
#include "base/serialization.h"
|
||||
#include "doc/palette.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
SetPalette::SetPalette(Sprite* sprite, frame_t frame, Palette* newPalette)
|
||||
: WithSprite(sprite)
|
||||
, m_frame(frame)
|
||||
{
|
||||
Palette* curPalette = sprite->palette(frame);
|
||||
|
||||
// Check differences between current sprite palette and the new one
|
||||
m_from = m_to = -1;
|
||||
curPalette->countDiff(newPalette, &m_from, &m_to);
|
||||
|
||||
if (m_from >= 0 && m_to >= m_from) {
|
||||
size_t ncolors = m_to-m_from+1;
|
||||
m_oldColors.resize(ncolors);
|
||||
m_newColors.resize(ncolors);
|
||||
|
||||
for (size_t i=0; i<ncolors; ++i) {
|
||||
m_oldColors[i] = curPalette->getEntry(m_from+i);
|
||||
m_newColors[i] = newPalette->getEntry(m_from+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetPalette::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* palette = sprite->palette(m_frame);
|
||||
|
||||
for (size_t i=0; i<m_newColors.size(); ++i)
|
||||
palette->setEntry(m_from+i, m_newColors[i]);
|
||||
}
|
||||
|
||||
void SetPalette::onUndo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* palette = sprite->palette(m_frame);
|
||||
|
||||
for (size_t i=0; i<m_oldColors.size(); ++i)
|
||||
palette->setEntry(m_from+i, m_oldColors[i]);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
63
src/app/cmd/set_palette.h
Normal file
63
src/app/cmd/set_palette.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_PALETTE_COLORS_H_INCLUDED
|
||||
#define APP_CMD_SET_PALETTE_COLORS_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace doc {
|
||||
class Palette;
|
||||
class Sprite;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetPalette : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
SetPalette(Sprite* sprite, frame_t frame, Palette* newPalette);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
sizeof(doc::color_t) * (m_oldColors.size() +
|
||||
m_newColors.size());
|
||||
}
|
||||
|
||||
private:
|
||||
frame_t m_frame;
|
||||
int m_from, m_to;
|
||||
std::vector<color_t> m_oldColors;
|
||||
std::vector<color_t> m_newColors;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
142
src/app/cmd/set_pixel_format.cpp
Normal file
142
src/app/cmd/set_pixel_format.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 3 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_pixel_format.h"
|
||||
|
||||
#include "app/cmd/add_palette.h"
|
||||
#include "app/cmd/remove_palette.h"
|
||||
#include "app/cmd/replace_image.h"
|
||||
#include "app/cmd/set_cel_opacity.h"
|
||||
#include "app/document.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/palette.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "render/quantization.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
SetPixelFormat::SetPixelFormat(Sprite* sprite,
|
||||
PixelFormat newFormat, DitheringMethod dithering)
|
||||
: WithSprite(sprite)
|
||||
, m_oldFormat(sprite->pixelFormat())
|
||||
, m_newFormat(newFormat)
|
||||
, m_dithering(dithering)
|
||||
{
|
||||
if (sprite->pixelFormat() == newFormat)
|
||||
return;
|
||||
|
||||
// TODO Review this, why we use the palette in frame 0?
|
||||
frame_t frame(0);
|
||||
|
||||
// Use the rgbmap for the specified sprite
|
||||
const RgbMap* rgbmap = sprite->rgbMap(frame);
|
||||
|
||||
// Get the list of cels from the background layer (if it
|
||||
// exists). This list will be used to check if each image belong to
|
||||
// the background layer.
|
||||
CelList bgCels;
|
||||
if (sprite->backgroundLayer() != NULL)
|
||||
sprite->backgroundLayer()->getCels(bgCels);
|
||||
|
||||
std::vector<Image*> images;
|
||||
sprite->getImages(images);
|
||||
for (auto& old_image : images) {
|
||||
bool is_image_from_background = false;
|
||||
for (CelList::iterator it=bgCels.begin(), end=bgCels.end(); it != end; ++it) {
|
||||
if ((*it)->image()->id() == old_image->id()) {
|
||||
is_image_from_background = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImageRef new_image(render::convert_pixel_format
|
||||
(old_image, NULL, newFormat, m_dithering, rgbmap,
|
||||
sprite->palette(frame),
|
||||
is_image_from_background));
|
||||
|
||||
m_seq.add(new cmd::ReplaceImage(sprite,
|
||||
sprite->getImage(old_image->id()), new_image));
|
||||
}
|
||||
|
||||
// Set all cels opacity to 100% if we are converting to indexed.
|
||||
if (newFormat == IMAGE_INDEXED) {
|
||||
CelList cels;
|
||||
sprite->getCels(cels);
|
||||
for (auto it = cels.begin(), end = cels.end(); it != end; ++it) {
|
||||
Cel* cel = *it;
|
||||
if (cel->opacity() < 255)
|
||||
m_seq.add(new cmd::SetCelOpacity(cel, 255));
|
||||
}
|
||||
}
|
||||
|
||||
// When we are converting to grayscale color mode, we've to destroy
|
||||
// all palettes and put only one grayscaled-palette at the first
|
||||
// frame.
|
||||
if (newFormat == IMAGE_GRAYSCALE) {
|
||||
// Add undoers to revert all palette changes.
|
||||
PalettesList palettes = sprite->getPalettes();
|
||||
for (Palette* pal : palettes)
|
||||
m_seq.add(new cmd::RemovePalette(sprite, pal));
|
||||
|
||||
base::UniquePtr<Palette> graypal(Palette::createGrayscale());
|
||||
graypal->setFrame(0);
|
||||
m_seq.add(new cmd::AddPalette(sprite, graypal));
|
||||
}
|
||||
}
|
||||
|
||||
void SetPixelFormat::onExecute()
|
||||
{
|
||||
m_seq.execute(context());
|
||||
setFormat(m_newFormat);
|
||||
}
|
||||
|
||||
void SetPixelFormat::onUndo()
|
||||
{
|
||||
m_seq.undo();
|
||||
setFormat(m_oldFormat);
|
||||
}
|
||||
|
||||
void SetPixelFormat::onRedo()
|
||||
{
|
||||
m_seq.redo();
|
||||
setFormat(m_newFormat);
|
||||
}
|
||||
|
||||
void SetPixelFormat::setFormat(PixelFormat format)
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
|
||||
sprite->setPixelFormat(format);
|
||||
|
||||
// Regenerate extras
|
||||
static_cast<app::Document*>(sprite->document())
|
||||
->destroyExtraCel();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
63
src/app/cmd/set_pixel_format.h
Normal file
63
src/app/cmd/set_pixel_format.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_PIXEL_FORMAT_H_INCLUDED
|
||||
#define APP_CMD_SET_PIXEL_FORMAT_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd_sequence.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/pixel_format.h"
|
||||
#include "doc/dithering_method.h"
|
||||
|
||||
namespace doc {
|
||||
class Sprite;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetPixelFormat : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
SetPixelFormat(Sprite* sprite,
|
||||
PixelFormat newFormat,
|
||||
DitheringMethod dithering);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) + m_seq.memSize();
|
||||
}
|
||||
|
||||
private:
|
||||
void setFormat(PixelFormat format);
|
||||
|
||||
PixelFormat m_oldFormat;
|
||||
PixelFormat m_newFormat;
|
||||
DitheringMethod m_dithering;
|
||||
CmdSequence m_seq;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,40 +20,43 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_mask_position.h"
|
||||
#include "app/cmd/set_sprite_size.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/mask.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
|
||||
SetMaskPosition::SetMaskPosition(ObjectsContainer* objects, Document* document)
|
||||
: m_documentId(objects->addObject(document))
|
||||
, m_x(document->mask()->bounds().x)
|
||||
, m_y(document->mask()->bounds().y)
|
||||
SetSpriteSize::SetSpriteSize(Sprite* sprite, int newWidth, int newHeight)
|
||||
: WithSprite(sprite)
|
||||
, m_oldWidth(sprite->width())
|
||||
, m_oldHeight(sprite->height())
|
||||
, m_newWidth(newWidth)
|
||||
, m_newHeight(newHeight)
|
||||
{
|
||||
ASSERT(m_newWidth > 0);
|
||||
ASSERT(m_newHeight > 0);
|
||||
}
|
||||
|
||||
void SetMaskPosition::dispose()
|
||||
void SetSpriteSize::onExecute()
|
||||
{
|
||||
delete this;
|
||||
sprite()->setSize(m_newWidth, m_newHeight);
|
||||
}
|
||||
|
||||
void SetMaskPosition::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetSpriteSize::onUndo()
|
||||
{
|
||||
Document* document = objects->getObjectT<Document>(m_documentId);
|
||||
|
||||
// Push another SetMaskPosition as redoer
|
||||
redoers->pushUndoer(new SetMaskPosition(objects, document));
|
||||
|
||||
document->mask()->setOrigin(m_x, m_y);
|
||||
document->resetTransformation();
|
||||
sprite()->setSize(m_oldWidth, m_oldHeight);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void SetSpriteSize::onFireNotifications()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
DocumentEvent ev(sprite->document());
|
||||
ev.sprite(sprite);
|
||||
sprite->document()->notifyObservers<DocumentEvent&>(&DocumentObserver::onSpriteSizeChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
53
src/app/cmd/set_sprite_size.h
Normal file
53
src/app/cmd/set_sprite_size.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_SPRITE_SIZE_H_INCLUDED
|
||||
#define APP_CMD_SET_SPRITE_SIZE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetSpriteSize : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
SetSpriteSize(Sprite* sprite, int newWidth, int newHeight);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_oldWidth;
|
||||
uint32_t m_oldHeight;
|
||||
uint32_t m_newWidth;
|
||||
uint32_t m_newHeight;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,37 +20,41 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_sprite_pixel_format.h"
|
||||
#include "app/cmd/set_total_frames.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
|
||||
SetSpritePixelFormat::SetSpritePixelFormat(ObjectsContainer* objects, Sprite* sprite)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_format(sprite->pixelFormat())
|
||||
SetTotalFrames::SetTotalFrames(Sprite* sprite, frame_t frames)
|
||||
: WithSprite(sprite)
|
||||
, m_oldFrames(sprite->totalFrames())
|
||||
, m_newFrames(frames)
|
||||
{
|
||||
}
|
||||
|
||||
void SetSpritePixelFormat::dispose()
|
||||
void SetTotalFrames::onExecute()
|
||||
{
|
||||
delete this;
|
||||
sprite()->setTotalFrames(m_newFrames);
|
||||
}
|
||||
|
||||
void SetSpritePixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetTotalFrames::onUndo()
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
// Push another SetSpritePixelFormat as redoer
|
||||
redoers->pushUndoer(new SetSpritePixelFormat(objects, sprite));
|
||||
|
||||
sprite->setPixelFormat(static_cast<PixelFormat>(m_format));
|
||||
sprite()->setTotalFrames(m_oldFrames);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void SetTotalFrames::onFireNotifications()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
doc::Document* doc = sprite->document();
|
||||
DocumentEvent ev(doc);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(sprite->totalFrames());
|
||||
doc->notifyObservers<DocumentEvent&>(&DocumentObserver::onTotalFramesChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/set_total_frames.h
Normal file
52
src/app/cmd/set_total_frames.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#define APP_CMD_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetTotalFrames : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
SetTotalFrames(Sprite* sprite, frame_t frames);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
frame_t m_oldFrames;
|
||||
frame_t m_newFrames;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,38 +20,39 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_total_frames.h"
|
||||
#include "app/cmd/set_transparent_color.h"
|
||||
|
||||
#include "app/document.h"
|
||||
#include "app/document_api.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
|
||||
SetTotalFrames::SetTotalFrames(ObjectsContainer* objects, Document* document, Sprite* sprite)
|
||||
: m_documentId(objects->addObject(document))
|
||||
, m_spriteId(objects->addObject(sprite))
|
||||
, m_totalFrames(sprite->totalFrames())
|
||||
SetTransparentColor::SetTransparentColor(Sprite* sprite, color_t newMask)
|
||||
: WithSprite(sprite)
|
||||
, m_oldMaskColor(sprite->transparentColor())
|
||||
, m_newMaskColor(newMask)
|
||||
{
|
||||
}
|
||||
|
||||
void SetTotalFrames::dispose()
|
||||
void SetTransparentColor::onExecute()
|
||||
{
|
||||
delete this;
|
||||
sprite()->setTransparentColor(m_newMaskColor);
|
||||
}
|
||||
|
||||
void SetTotalFrames::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
void SetTransparentColor::onUndo()
|
||||
{
|
||||
Document* document = objects->getObjectT<Document>(m_documentId);
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
|
||||
document->getApi(redoers).setTotalFrames(sprite, m_totalFrames);
|
||||
sprite()->setTransparentColor(m_oldMaskColor);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
void SetTransparentColor::onFireNotifications()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
DocumentEvent ev(sprite->document());
|
||||
ev.sprite(sprite);
|
||||
sprite->document()->notifyObservers<DocumentEvent&>(&DocumentObserver::onSpriteTransparentColorChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
52
src/app/cmd/set_transparent_color.h
Normal file
52
src/app/cmd/set_transparent_color.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_SET_TRANSPARENT_COLOR_H_INCLUDED
|
||||
#define APP_CMD_SET_TRANSPARENT_COLOR_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/color.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetTransparentColor : public Cmd
|
||||
, public WithSprite {
|
||||
public:
|
||||
SetTransparentColor(Sprite* sprite, color_t newMask);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onFireNotifications();
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
color_t m_oldMaskColor;
|
||||
color_t m_newMaskColor;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -20,38 +20,24 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/undoers/set_cel_position.h"
|
||||
#include "app/cmd/with_cel.h"
|
||||
|
||||
#include "doc/cel.h"
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undoers_collector.h"
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
namespace cmd {
|
||||
|
||||
using namespace undo;
|
||||
using namespace doc;
|
||||
|
||||
SetCelPosition::SetCelPosition(ObjectsContainer* objects, Cel* cel)
|
||||
: m_celId(objects->addObject(cel))
|
||||
, m_x(cel->x())
|
||||
, m_y(cel->y())
|
||||
WithCel::WithCel(Cel* cel)
|
||||
: m_celId(cel->id())
|
||||
{
|
||||
}
|
||||
|
||||
void SetCelPosition::dispose()
|
||||
Cel* WithCel::cel()
|
||||
{
|
||||
delete this;
|
||||
return get<Cel>(m_celId);
|
||||
}
|
||||
|
||||
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->setPosition(m_x, m_y);
|
||||
}
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,37 +16,30 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_SET_CEL_OPACITY_H_INCLUDED
|
||||
#define APP_UNDOERS_SET_CEL_OPACITY_H_INCLUDED
|
||||
#ifndef APP_CMD_WITH_CEL_H_INCLUDED
|
||||
#define APP_CMD_WITH_CEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "doc/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetCelOpacity : public UndoerBase {
|
||||
public:
|
||||
SetCelOpacity(ObjectsContainer* objects, Cel* cel);
|
||||
class WithCel {
|
||||
public:
|
||||
WithCel(Cel* cel);
|
||||
Cel* cel();
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
private:
|
||||
ObjectId m_celId;
|
||||
};
|
||||
|
||||
private:
|
||||
undo::ObjectId m_celId;
|
||||
uint8_t m_opacity;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_SET_CEL_OPACITY_H_INCLUDED
|
||||
#endif
|
41
src/app/cmd/with_document.cpp
Normal file
41
src/app/cmd/with_document.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/with_document.h"
|
||||
|
||||
#include "app/document.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
WithDocument::WithDocument(app::Document* doc)
|
||||
: m_docId(doc->id())
|
||||
{
|
||||
}
|
||||
|
||||
app::Document* WithDocument::document()
|
||||
{
|
||||
return doc::get<app::Document>(m_docId);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
41
src/app/cmd/with_document.h
Normal file
41
src/app/cmd/with_document.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_WITH_DOCUMENT_H_INCLUDED
|
||||
#define APP_CMD_WITH_DOCUMENT_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/object_id.h"
|
||||
|
||||
namespace app {
|
||||
class Document;
|
||||
namespace cmd {
|
||||
|
||||
class WithDocument {
|
||||
public:
|
||||
WithDocument(app::Document* doc);
|
||||
app::Document* document();
|
||||
|
||||
private:
|
||||
doc::ObjectId m_docId;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
43
src/app/cmd/with_image.cpp
Normal file
43
src/app/cmd/with_image.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/with_image.h"
|
||||
|
||||
#include "doc/image.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
WithImage::WithImage(Image* image)
|
||||
: m_imageId(image->id())
|
||||
{
|
||||
}
|
||||
|
||||
Image* WithImage::image()
|
||||
{
|
||||
return get<Image>(m_imageId);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
45
src/app/cmd/with_image.h
Normal file
45
src/app/cmd/with_image.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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 APP_CMD_WITH_IMAGE_H_INCLUDED
|
||||
#define APP_CMD_WITH_IMAGE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class Image;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class WithImage {
|
||||
public:
|
||||
WithImage(Image* image);
|
||||
Image* image();
|
||||
|
||||
private:
|
||||
ObjectId m_imageId;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
46
src/app/cmd/with_layer.cpp
Normal file
46
src/app/cmd/with_layer.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2015 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/with_layer.h"
|
||||
|
||||
#include "doc/layer.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
WithLayer::WithLayer(Layer* layer)
|
||||
: m_layerId(layer ? layer->id(): 0)
|
||||
{
|
||||
}
|
||||
|
||||
Layer* WithLayer::layer()
|
||||
{
|
||||
if (m_layerId)
|
||||
return get<Layer>(m_layerId);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,5 +1,5 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
* Copyright (C) 2001-2015 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
|
||||
@ -16,37 +16,30 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef APP_UNDOERS_ADD_CEL_H_INCLUDED
|
||||
#define APP_UNDOERS_ADD_CEL_H_INCLUDED
|
||||
#ifndef APP_CMD_WITH_LAYER_H_INCLUDED
|
||||
#define APP_CMD_WITH_LAYER_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/undoers/undoer_base.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "doc/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class Cel;
|
||||
class Layer;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace undoers {
|
||||
using namespace doc;
|
||||
using namespace undo;
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class AddCel : public UndoerBase {
|
||||
public:
|
||||
AddCel(ObjectsContainer* objects, Layer* layer, Cel* cel);
|
||||
class WithLayer {
|
||||
public:
|
||||
WithLayer(Layer* layer);
|
||||
Layer* layer();
|
||||
|
||||
void dispose() override;
|
||||
size_t getMemSize() const override { return sizeof(*this); }
|
||||
void revert(ObjectsContainer* objects, UndoersCollector* redoers) override;
|
||||
private:
|
||||
ObjectId m_layerId;
|
||||
};
|
||||
|
||||
private:
|
||||
undo::ObjectId m_layerId;
|
||||
undo::ObjectId m_celId;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif // UNDOERS_ADD_CEL_H_INCLUDED
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user