add history to layer create, delete, move, rename, and merge

This commit is contained in:
2019-06-18 17:39:35 +02:00
parent c48a6da8a6
commit 9ee4bc42b9
12 changed files with 259 additions and 137 deletions

View File

@@ -7,6 +7,7 @@
#include "node_combobox.h"
#include "node_scroll.h"
#include "action.h"
#include "canvas_layer.h"
class NodeLayer : public NodeBorder
{
@@ -50,7 +51,7 @@ public:
std::function<void(Node* target, int idx, int mode)> on_layer_blend_mode_changed;
std::function<void(Node* target, int index)> on_layer_delete;
std::function<void(Node* target, int index)> on_layer_duplicate;
std::function<void(Node* target, std::unique_ptr<class Layer> layer, int index)> on_layer_add;
std::function<void(Node* target, std::shared_ptr<class Layer> layer, int index)> on_layer_add;
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_order;
NodeLayer* m_current_layer = nullptr;
std::vector<NodeLayer*> m_layers;
@@ -61,8 +62,10 @@ public:
virtual Node* clone_instantiate() const override;
virtual void init() override;
virtual kEventResult handle_event(Event* e) override;
void add_layer();
NodeLayer* add_layer(const char* name, bool add_history = true, std::unique_ptr<class Layer> layer = nullptr, int index = 0);
void merge(int src_index, int dst_index, bool create_history);
void add_layer(bool add_history = true, bool create_events = false);
NodeLayer* add_layer(const char* name, bool add_history = true, bool create_events = false,
std::shared_ptr<Layer> layer = nullptr, std::shared_ptr<NodeLayer> layer_node = nullptr, int index = -1);
NodeLayer* get_layer_at(int index);
void remove_layer(NodeLayer* layer, bool add_history = true);
void handle_layer_opacity(NodeLayer* target, float value);
@@ -81,6 +84,7 @@ public:
NodePanelLayer* m_panel;
std::shared_ptr<Node> m_layer_node;
int m_layer_order;
uint32_t m_layer_id;
virtual void run() override { }
virtual Action* get_redo() override;
virtual void undo() override;
@@ -92,7 +96,7 @@ class ActionLayerRemove : public Action
public:
NodePanelLayer* m_panel;
std::shared_ptr<Node> m_layer_node;
std::unique_ptr<class Layer> m_layer;
std::shared_ptr<class Layer> m_layer;
int m_layer_order;
virtual void run() override { }
virtual Action* get_redo() override;
@@ -103,11 +107,28 @@ public:
class ActionLayerMove : public Action
{
public:
int m_index_old;
int m_index_new;
NodePanelLayer* m_panel;
std::shared_ptr<Node> m_layer_node;
int m_offset;
virtual void run() override { }
virtual Action* get_redo() override;
virtual void undo() override;
virtual size_t memory() override;
};
struct ActionLayerMerge : public Action
{
enum class Direction { Undo, Redo } m_direction;
Layer::Snapshot m_snap;
std::shared_ptr<Layer> m_layer;
std::shared_ptr<NodeLayer> m_layer_node;
std::shared_ptr<NodePanelLayer> m_panel;
int m_src_index = 0; // removed layer
int m_dst_index = 0;
std::array<glm::vec4, 6> m_dirty_box;
std::array<bool, 6> m_dirty_face;
virtual void run() override { }
virtual size_t memory() override { return 0; }
virtual void undo() override;
virtual Action* get_redo() override;
};