improving actions history
This commit is contained in:
102
src/canvas.h
102
src/canvas.h
@@ -4,90 +4,13 @@
|
||||
#include "shader.h"
|
||||
#include "shape.h"
|
||||
#include "brush.h"
|
||||
#include "action.h"
|
||||
#include "canvas_layer.h"
|
||||
#include "canvas_actions.h"
|
||||
#include "canvas_modes.h"
|
||||
#include <stack>
|
||||
|
||||
#define CANVAS_RES 1536
|
||||
|
||||
class LayerFrame
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
Layer() = default;
|
||||
Layer(const Layer&) = delete;
|
||||
RTT m_rtt[6];
|
||||
glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0));
|
||||
bool m_dirty_face[6] = SIXPLETTE(false);
|
||||
bool m_visible = true;
|
||||
bool m_alpha_locked = false;
|
||||
float m_opacity = 1.f;
|
||||
bool m_hightlight = false;
|
||||
int m_blend_mode = 0;
|
||||
std::string m_name;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
struct Snapshot
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0);
|
||||
glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0));
|
||||
bool m_dirty_face[6] = SIXPLETTE(false);
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
void create(int w, int h)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
image[i] = std::make_unique<uint8_t[]>(w*h*4);
|
||||
std::fill_n(image[i].get(), w*h*4, 0);
|
||||
}
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_dirty_face[i] = false;
|
||||
m_dirty_box[i] = glm::vec4(0);
|
||||
std::fill_n(image[i].get(), width*height*4, 0);
|
||||
}
|
||||
}
|
||||
void optimize()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (!m_dirty_face[i] || !image[i])
|
||||
continue;
|
||||
auto data = reinterpret_cast<glm::u8vec4*>(image[i].get());
|
||||
glm::ivec2 bbmin(width, height);
|
||||
glm::ivec2 bbmax(0);
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
if (data[x + y * width].a > 0)
|
||||
{
|
||||
bbmin = glm::min(bbmin, { x, y });
|
||||
bbmax = glm::max(bbmax, { x + 1, y + 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
//glm::vec2 bbsz = bbmax - bbmin;
|
||||
}
|
||||
}
|
||||
};
|
||||
void resize(int width, int height);
|
||||
bool create(int width, int height, std::string name);
|
||||
void clear(const glm::vec4& c);
|
||||
Snapshot snapshot();
|
||||
void restore(const Snapshot& snap);
|
||||
void destroy();
|
||||
void optimize();
|
||||
};
|
||||
|
||||
struct PPIThumb
|
||||
{
|
||||
int width = 128;
|
||||
@@ -241,7 +164,7 @@ public:
|
||||
bool create(int width, int height);
|
||||
void resize(int width, int height);
|
||||
void layer_remove(int idx);
|
||||
void layer_add(std::string name);
|
||||
void layer_add(std::string name, std::unique_ptr<Layer> layer = nullptr, int index = 0);
|
||||
void layer_order(int idx, int pos);
|
||||
void layer_merge(int source_idx, int dest_idx);
|
||||
void stroke_start(glm::vec3 point, float pressure);
|
||||
@@ -302,22 +225,3 @@ public:
|
||||
CameraData get_camera();
|
||||
void set_camera(const CameraData& c);
|
||||
};
|
||||
|
||||
class ActionStroke : public Action
|
||||
{
|
||||
public:
|
||||
//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 clear_layer = false;
|
||||
int m_layer_idx = 0;
|
||||
Canvas* m_canvas;
|
||||
ActionStroke() = default;
|
||||
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