complete open/save project including layer names, in layout bring canvas to background and use translucent UI on top, save computation on Android with lazy rendering on events only
This commit is contained in:
@@ -515,16 +515,23 @@ void ui::Canvas::save_project(std::string data_path)
|
||||
}
|
||||
fwrite(&m_width, sizeof(int), 1, fp);
|
||||
fwrite(&m_height, sizeof(int), 1, fp);
|
||||
|
||||
int n_layers = (int)m_layers.size();
|
||||
fwrite(&n_layers, sizeof(int), 1, fp);
|
||||
|
||||
for (int i = 0; i < (int)m_layers.size(); i++)
|
||||
{
|
||||
int n_order = m_order[i];
|
||||
fwrite(&n_order, sizeof(int), 1, fp);
|
||||
|
||||
int name_len = m_layers[i].m_name.size();
|
||||
fwrite(&name_len, sizeof(int), 1, fp);
|
||||
fwrite(m_layers[i].m_name.data(), name_len, 1, fp);
|
||||
|
||||
auto snap = m_layers[i].snapshot(data_path);
|
||||
for (int layer_index = 0; layer_index < 6; layer_index++)
|
||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||
{
|
||||
fwrite(snap.image[i].get(), 1, m_width * m_height * 4, fp);
|
||||
fwrite(snap.image[plane_index].get(), 1, m_width * m_height * 4, fp);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
@@ -543,25 +550,33 @@ void ui::Canvas::open_project(std::string data_path)
|
||||
}
|
||||
fread(&m_width, sizeof(int), 1, fp);
|
||||
fread(&m_height, sizeof(int), 1, fp);
|
||||
|
||||
int n_layers = (int)m_layers.size();
|
||||
fread(&n_layers, sizeof(int), 1, fp);
|
||||
|
||||
const int bytes = m_width * m_height * 4;
|
||||
Layer::Snapshot snap;
|
||||
snap.create(m_width, m_height);
|
||||
|
||||
m_layers.clear();
|
||||
m_order.clear();
|
||||
for (int i = 0; i < n_layers; i++)
|
||||
{
|
||||
int n_order = m_order[i];
|
||||
int n_order;
|
||||
fread(&n_order, sizeof(int), 1, fp);
|
||||
m_order.push_back(n_order);
|
||||
for (int layer_index = 0; layer_index < 6; layer_index++)
|
||||
|
||||
int name_len;
|
||||
fread(&name_len, sizeof(int), 1, fp);
|
||||
std::string name(name_len, '\0');
|
||||
fread((char*)name.data(), name_len, 1, fp);
|
||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||
{
|
||||
fread(snap.image[i].get(), 1, bytes, fp);
|
||||
m_layers.emplace_back();
|
||||
m_layers.back().create(m_width, m_height, "");
|
||||
m_layers.back().restore(snap);
|
||||
fread(snap.image[plane_index].get(), 1, bytes, fp);
|
||||
}
|
||||
m_layers.emplace_back();
|
||||
m_layers.back().create(m_width, m_height, name.c_str());
|
||||
m_layers.back().restore(snap);
|
||||
}
|
||||
fclose(fp);
|
||||
LOG("project restore from %s", name);
|
||||
@@ -582,7 +597,7 @@ void ui::Layer::restore(const Snapshot& snap)
|
||||
{
|
||||
if (!snap.image[i])
|
||||
continue;
|
||||
m_rtt[i].create(512, 512); // TODO: this should not be recreated here! Sorry I messed up with this, just quick fix DON'T SHIP!!
|
||||
m_rtt[i].recreate(); // TODO: this should not be recreated here! Sorry I messed up with this, just quick fix DON'T SHIP!!
|
||||
m_rtt[i].bindTexture();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_rtt[i].getWidth(), m_rtt[i].getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get());
|
||||
m_rtt[i].unbindTexture();
|
||||
@@ -630,6 +645,7 @@ void ui::Layer::clear(const glm::vec4& c)
|
||||
|
||||
bool ui::Layer::create(int width, int height, std::string name)
|
||||
{
|
||||
m_name = name;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_rtt[i].create(width, height);
|
||||
|
||||
Reference in New Issue
Block a user