fix undo and redo
This commit is contained in:
72
src/canvas.h
72
src/canvas.h
@@ -236,7 +236,6 @@ public:
|
||||
void snapshot_save();
|
||||
void snapshot_restore();
|
||||
void snap_history(const std::vector<int>& planes);
|
||||
class ActionStroke* create_action(int layer);
|
||||
void clear_context();
|
||||
void import_equirectangular(std::string file_path);
|
||||
void import_equirectangular_thread(std::string file_path);
|
||||
@@ -278,75 +277,18 @@ public:
|
||||
class ActionStroke : public Action
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<Stroke> m_stroke;
|
||||
//std::unique_ptr<Stroke> m_stroke;
|
||||
std::unique_ptr<uint8_t[]> m_image[6] = SIXPLETTE(nullptr);
|
||||
glm::ivec4 m_old_box[6] = SIXPLETTE(glm::ivec4(0));
|
||||
bool m_old_dirty[6] = SIXPLETTE(false);
|
||||
glm::ivec4 m_box[6] = SIXPLETTE(glm::ivec4(0));
|
||||
bool m_dirty[6] = SIXPLETTE(false);
|
||||
bool clear_layer = false;
|
||||
int m_layer_idx;
|
||||
int m_layer_idx = 0;
|
||||
Canvas* m_canvas;
|
||||
ActionStroke() = default;
|
||||
virtual void run() override
|
||||
{
|
||||
|
||||
}
|
||||
virtual Action* get_redo() override
|
||||
{
|
||||
auto redo = m_canvas->create_action(m_layer_idx);
|
||||
return redo;
|
||||
}
|
||||
virtual void undo() override
|
||||
{
|
||||
if (clear_layer)
|
||||
m_canvas->m_layers[m_layer_idx].clear({ 0, 0, 0, 0 });
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
// empty data
|
||||
if (!m_image[i])
|
||||
continue;
|
||||
|
||||
LOG("undo box %d dirty=%s [%d,%d,%d,%d] to dirty=%s [%d,%d,%d,%d]",
|
||||
i,
|
||||
m_canvas->m_layers[m_layer_idx].m_dirty_face[i] ? "true" : "false",
|
||||
(int)m_canvas->m_layers[m_layer_idx].m_dirty_box[i].x,
|
||||
(int)m_canvas->m_layers[m_layer_idx].m_dirty_box[i].y,
|
||||
(int)m_canvas->m_layers[m_layer_idx].m_dirty_box[i].z,
|
||||
(int)m_canvas->m_layers[m_layer_idx].m_dirty_box[i].w,
|
||||
m_old_dirty[i] ? "true" : "false",
|
||||
(int)m_old_box[i].x,
|
||||
(int)m_old_box[i].y,
|
||||
(int)m_old_box[i].z,
|
||||
(int)m_old_box[i].w);
|
||||
m_canvas->m_layers[m_layer_idx].m_dirty_box[i] = m_old_box[i];
|
||||
m_canvas->m_layers[m_layer_idx].m_dirty_face[i] = m_old_dirty[i];
|
||||
|
||||
|
||||
glm::vec2 box_sz = zw(m_box[i]) - xy(m_box[i]);
|
||||
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= m_canvas->m_layers[m_layer_idx].w && box_sz.y <= m_canvas->m_layers[m_layer_idx].h)
|
||||
{
|
||||
m_canvas->m_layers[m_layer_idx].m_rtt[i].bindTexture();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, (int)m_box[i].x, (int)m_box[i].y, (int)box_sz.x, (int)box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, m_image[i].get());
|
||||
m_canvas->m_layers[m_layer_idx].m_rtt[i].unbindTexture();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("undo invalid box size (%d, %d)", (int)box_sz.x, (int)box_sz.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual size_t memory() override
|
||||
{
|
||||
size_t mem = 0;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
glm::ivec2 sz = zw(m_box[i]) - xy(m_box[i]);
|
||||
mem += sz.x * sz.y * 4 + sizeof(*this);
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
virtual ~ActionStroke()
|
||||
{
|
||||
}
|
||||
virtual ~ActionStroke() = default;
|
||||
virtual void run() override { }
|
||||
virtual Action* get_redo() override;
|
||||
virtual void undo() override;
|
||||
virtual size_t memory() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user