Add history to Clear Guides

This commit is contained in:
2019-06-26 15:36:38 +02:00
parent b444cec46d
commit 1bffeb2d03
2 changed files with 7 additions and 37 deletions

View File

@@ -155,43 +155,6 @@ void Canvas::clear_all()
for (auto& l : m_layers)
l->clear({0, 0, 0, 0});
}
void Canvas::snap_history(const std::vector<int>& planes)
{
auto action = new ActionStroke;
action->was_saved = !m_unsaved;
for (auto i : planes)
{
if (!m_layers[m_current_layer_idx]->m_dirty_face[i])
continue; // no stroke on this face, skip it
m_layers[m_current_layer_idx]->m_rtt[i].bindFramebuffer();
// save image before commit
glm::vec2 box_or = xy(m_layers[m_current_layer_idx]->m_dirty_box[i]);
glm::vec2 box_sz = zw(m_layers[m_current_layer_idx]->m_dirty_box[i]) - xy(m_layers[m_current_layer_idx]->m_dirty_box[i]);
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= m_layers[m_current_layer_idx]->w && box_sz.y <= m_layers[m_current_layer_idx]->h)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
}
else
{
LOG("snap_history invalid box size (%d, %d)", (int)box_sz.x, (int)box_sz.y);
}
action->m_box[i] = m_layers[m_current_layer_idx]->m_dirty_box[i];
action->m_old_box[i] = m_layers[m_current_layer_idx]->m_dirty_box[i];
action->m_old_dirty[i] = m_layers[m_current_layer_idx]->m_dirty_face[i];
m_layers[m_current_layer_idx]->m_rtt[i].unbindFramebuffer();
}
// save history
action->m_layer_idx = m_current_layer_idx;
action->m_canvas = this;
//action->m_stroke = std::move(m_current_stroke);
action->clear_layer = true;
ActionManager::add(action);
}
void Canvas::stroke_end()
{
if (!m_current_stroke)

View File

@@ -538,6 +538,13 @@ void CanvasModeGrid::commit()
void CanvasModeGrid::clear()
{
auto a = new ActionModeGrid;
a->m_mode = this;
a->m_highlight = m_highlight;
a->m_selected_index = m_selected_index;
a->m_lines = m_lines;
ActionManager::add(a);
m_lines.clear();
}