implement document resize with menu and dialog

This commit is contained in:
2018-10-05 18:10:26 +02:00
parent 4723bedc31
commit 5baa807cce
14 changed files with 245 additions and 15 deletions

View File

@@ -136,7 +136,11 @@ void ui::Canvas::clear(const glm::vec4& c/*={0,0,0,1}*/)
snap_history({ 0, 1, 2, 3, 4, 5 });
m_layers[m_current_layer_idx].clear(c);
m_unsaved = true;
App::I.title_update();
}
void ui::Canvas::clear_all()
{
for (auto& l : m_layers)
l.clear({0, 0, 0, 0});
}
void ui::Canvas::snap_history(const std::vector<int>& planes)
{
@@ -908,9 +912,9 @@ void ui::Canvas::resize(int width, int height)
m_tex2[i].create(width, height, GL_RGBA8);
}
for (auto& l : m_layers)
{
l.create(width, height, "");
}
l.resize(width, height);
m_smask.create(width*2, height*2, "mask");
m_unsaved = true;
}
bool ui::Canvas::create(int width, int height)
{
@@ -1733,12 +1737,13 @@ void ui::Canvas::project_open_thread(std::string file_path)
int progress = 0;
int total = n_layers * 6;
App::I.async_start();
for (auto& l : m_layers)
l.destroy();
m_layers.clear();
m_order.clear();
//clear_all();
resize(m_width, m_height);
App::I.async_end();
@@ -1757,6 +1762,7 @@ void ui::Canvas::project_open_thread(std::string file_path)
fread(&name_len, sizeof(int), 1, fp);
std::string name(name_len, '\0');
fread((char*)name.data(), name_len, 1, fp);
snap.clear();
for (int plane_index = 0; plane_index < 6; plane_index++)
{
int has_data;
@@ -1802,6 +1808,7 @@ void ui::Canvas::project_open_thread(std::string file_path)
tmp_layers.emplace_back();
tmp_layers.back().m_opacity = layer_opacity;
tmp_layers.back().create(m_width, m_height, name.c_str());
tmp_layers.back().clear({0, 0, 0, 0});
tmp_layers.back().restore(snap);
tmp_order.push_back(n_order);
App::I.async_end();
@@ -2106,12 +2113,20 @@ void ui::Layer::restore(const Snapshot& snap)
m_dirty_box[i] = snap.m_dirty_box[i];
m_dirty_face[i] = snap.m_dirty_face[i];
m_rtt[i].recreate(); // TODO: this should not be recreated here! Sorry I messed up with this, just quick fix DON'T SHIP!!
// TODO: this should not be recreated here!
// Sorry I messed up with this,
// it's just a quick fix DON'T SHIP!!
//m_rtt[i].recreate();
m_rtt[i].bindTexture();
glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]);
glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_box[i].x, m_dirty_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get());
glTexSubImage2D(GL_TEXTURE_2D, 0,
m_dirty_box[i].x, m_dirty_box[i].y,
box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE,
snap.image[i].get());
m_rtt[i].unbindTexture();
LOG("restore face %d - %d bytes (%dx%d)", i, (int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
LOG("restore face %d - %d bytes (%dx%d)", i,
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
}
}
@@ -2195,3 +2210,16 @@ bool ui::Layer::create(int width, int height, std::string name)
}
return true;
}
void ui::Layer::resize(int width, int height)
{
glm::vec2 ratio = glm::vec2(width, height) / glm::vec2(w, h);
w = width;
h = height;
for (int i = 0; i < 6; i++)
{
m_rtt[i].resize(width, height);
m_dirty_box[i] = m_dirty_box[i] * glm::vec4(ratio, ratio);
//m_dirty_face[i] = true;
}
}