fix bucket undo

This commit is contained in:
2019-06-25 14:49:14 +02:00
parent f9cf452af2
commit 5f72f9901f
5 changed files with 18 additions and 12 deletions

View File

@@ -3216,10 +3216,10 @@ void Layer::optimize()
void Layer::restore(const Snapshot& snap) void Layer::restore(const Snapshot& snap)
{ {
//clear({ 0, 0, 0, 0 }); clear({ 0, 0, 0, 0 });
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
if (snap.image[i] == nullptr || snap.m_dirty_face[i] == false) if (snap.image[i] == nullptr)
continue; continue;
m_dirty_box[i] = snap.m_dirty_box[i]; m_dirty_box[i] = snap.m_dirty_box[i];
@@ -3242,7 +3242,7 @@ void Layer::restore(const Snapshot& snap)
} }
} }
Layer::Snapshot Layer::snapshot(glm::vec4 dirty_box[6] /*= nullptr*/, bool dirty_face[6] /*= nullptr*/) Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr*/, std::array<bool, 6> * dirty_face /*= nullptr*/)
{ {
Snapshot snap; Snapshot snap;
static int counter = 0; static int counter = 0;
@@ -3250,8 +3250,8 @@ Layer::Snapshot Layer::snapshot(glm::vec4 dirty_box[6] /*= nullptr*/, bool dirty
//glBindFramebuffer(GL_FRAMEBUFFER, 0); //glBindFramebuffer(GL_FRAMEBUFFER, 0);
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
snap.m_dirty_box[i] = dirty_box ? dirty_box[i] : m_dirty_box[i]; snap.m_dirty_box[i] = dirty_box ? dirty_box->at(i) : m_dirty_box[i];
snap.m_dirty_face[i] = dirty_face ? dirty_face[i] : m_dirty_face[i]; snap.m_dirty_face[i] = dirty_face ? dirty_face->at(i) : m_dirty_face[i];
if (!snap.m_dirty_face[i]) if (!snap.m_dirty_face[i])
continue; continue;

View File

@@ -71,7 +71,7 @@ public:
std::shared_ptr<Layer> layer; std::shared_ptr<Layer> layer;
std::unique_ptr<bool[]> mask[6]; std::unique_ptr<bool[]> mask[6];
std::unique_ptr<glm::u8vec4[]> rgb[6] = SIXPLETTE(0); std::unique_ptr<glm::u8vec4[]> rgb[6] = SIXPLETTE(0);
bool dirty[6] = SIXPLETTE(false); std::array<bool, 6> dirty = SIXPLETTE(false);
glm::vec4 bb[6]; glm::vec4 bb[6];
void apply(); void apply();
}; };

View File

@@ -16,8 +16,8 @@ public:
~Layer() { LOG("LAYER AUTO DESTROY"); destroy(); } ~Layer() { LOG("LAYER AUTO DESTROY"); destroy(); }
uint32_t id; uint32_t id;
RTT m_rtt[6]; RTT m_rtt[6];
glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0)); std::array<glm::vec4, 6> m_dirty_box = SIXPLETTE(glm::vec4(0));
bool m_dirty_face[6] = SIXPLETTE(false); std::array<bool, 6> m_dirty_face = SIXPLETTE(false);
bool m_visible = true; bool m_visible = true;
bool m_alpha_locked = false; bool m_alpha_locked = false;
float m_opacity = 1.f; float m_opacity = 1.f;
@@ -29,8 +29,8 @@ public:
struct Snapshot struct Snapshot
{ {
std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0); std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0);
glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0)); std::array<glm::vec4, 6> m_dirty_box = SIXPLETTE(glm::vec4(0));
bool m_dirty_face[6] = SIXPLETTE(false); std::array<bool, 6> m_dirty_face = SIXPLETTE(false);
int width = 0; int width = 0;
int height = 0; int height = 0;
void create(int w, int h); void create(int w, int h);
@@ -41,7 +41,7 @@ public:
void resize(int width, int height); void resize(int width, int height);
bool create(int width, int height, std::string name); bool create(int width, int height, std::string name);
void clear(const glm::vec4& c); void clear(const glm::vec4& c);
Snapshot snapshot(glm::vec4 dirty_box[6] = nullptr, bool dirty_face[6] = nullptr); Snapshot snapshot(std::array<glm::vec4, 6>* dirty_box = nullptr, std::array<bool, 6>* dirty_face = nullptr);
void restore(const Snapshot& snap); void restore(const Snapshot& snap);
void destroy(); void destroy();
void optimize(); void optimize();

View File

@@ -1565,6 +1565,8 @@ void CanvasModeFloodFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{ {
std::shared_ptr<Layer> m_layer; std::shared_ptr<Layer> m_layer;
std::shared_ptr<Layer::Snapshot> m_snap; std::shared_ptr<Layer::Snapshot> m_snap;
std::array<bool, 6> m_dirty_face = SIXPLETTE(false);
std::array<glm::vec4, 6> m_dirty_box = SIXPLETTE(glm::vec4(0));
glm::ivec2 m_pos; glm::ivec2 m_pos;
glm::vec4 m_color; glm::vec4 m_color;
float m_threshold; float m_threshold;
@@ -1583,6 +1585,8 @@ void CanvasModeFloodFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
a->m_layer_index = m_layer_index; a->m_layer_index = m_layer_index;
a->m_threshold = m_threshold; a->m_threshold = m_threshold;
a->m_plane = m_plane; a->m_plane = m_plane;
a->m_dirty_box = m_dirty_box;
a->m_dirty_face = m_dirty_face;
return a; return a;
} }
virtual void undo() override virtual void undo() override
@@ -1625,6 +1629,8 @@ void CanvasModeFloodFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
a->m_layer_index = Canvas::I->m_current_layer_idx; a->m_layer_index = Canvas::I->m_current_layer_idx;
a->m_threshold = m_tool->get_threshold(); a->m_threshold = m_tool->get_threshold();
a->m_plane = plane; a->m_plane = plane;
a->m_dirty_box = plane_data.layer->m_dirty_box;
a->m_dirty_face = plane_data.layer->m_dirty_face;
ActionManager::add(a); ActionManager::add(a);
plane_data.apply(); plane_data.apply();

View File

@@ -400,7 +400,7 @@ void NodePanelLayer::merge(int src_index, int dst_index, bool create_history)
} }
a->m_snap = std::make_shared<Layer::Snapshot>(); a->m_snap = std::make_shared<Layer::Snapshot>();
*a->m_snap = Canvas::I->m_layers[dst_index]->snapshot( *a->m_snap = Canvas::I->m_layers[dst_index]->snapshot(
Canvas::I->m_layers[src_index]->m_dirty_box, Canvas::I->m_layers[src_index]->m_dirty_face); &Canvas::I->m_layers[src_index]->m_dirty_box, &Canvas::I->m_layers[src_index]->m_dirty_face);
a->m_layer = Canvas::I->m_layers[src_index]; a->m_layer = Canvas::I->m_layers[src_index];
a->m_layer_node = std::static_pointer_cast<NodeLayer>(m_layers_container->m_children[src_index]); a->m_layer_node = std::static_pointer_cast<NodeLayer>(m_layers_container->m_children[src_index]);
a->m_layer_node->m_selected = false; a->m_layer_node->m_selected = false;