implement simple stroke undo based on actions history
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "shader.h"
|
||||
#include "shape.h"
|
||||
#include "brush.h"
|
||||
#include "action.h"
|
||||
|
||||
NS_START
|
||||
|
||||
@@ -15,14 +16,14 @@ class Canvas
|
||||
public:
|
||||
bool m_erase = false;
|
||||
glm::mat4 m_mvp;
|
||||
glm::vec4 m_box;
|
||||
int m_width;
|
||||
int m_height;
|
||||
bool m_use_instanced = false;
|
||||
int m_current_layer_idx = 0;
|
||||
Stroke* m_current_stroke = nullptr;
|
||||
std::unique_ptr<Stroke> m_current_stroke;
|
||||
bool m_show_tmp = false;
|
||||
std::vector<Layer> m_layers;
|
||||
std::vector<Stroke> m_strokes;
|
||||
std::vector<int> m_order;
|
||||
RTT m_tmp;
|
||||
Texture2D m_tex;
|
||||
@@ -42,4 +43,28 @@ public:
|
||||
void clear(const glm::vec4& color = { 1, 1, 1, 1 });
|
||||
};
|
||||
|
||||
|
||||
class ActionStroke : public Action
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<Stroke> m_stroke;
|
||||
std::unique_ptr<uint8_t[]> m_image;
|
||||
glm::ivec4 m_box;
|
||||
int m_layer_idx;
|
||||
Canvas* m_canvas;
|
||||
virtual void run() override
|
||||
{
|
||||
|
||||
}
|
||||
virtual void undo() override
|
||||
{
|
||||
m_canvas->m_layers[m_stroke->m_layer].m_rtt.bindTexture();
|
||||
|
||||
glm::vec2 box_sz = m_box.zw() - m_box.xy();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, m_box.x, m_box.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, m_image.get());
|
||||
|
||||
m_canvas->m_layers[m_stroke->m_layer].m_rtt.unbindTexture();
|
||||
}
|
||||
};
|
||||
|
||||
NS_END
|
||||
|
||||
Reference in New Issue
Block a user