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:
@@ -417,7 +417,7 @@ void App::initLayout()
|
||||
};
|
||||
|
||||
layers->on_layer_add = [this](Node*) {
|
||||
canvas->m_canvas->layer_add("asd");
|
||||
canvas->m_canvas->layer_add(layers->m_layers.back()->m_label_text.c_str());
|
||||
};
|
||||
|
||||
layers->on_layer_change = [this](Node*, int old_idx, int new_idx) {
|
||||
@@ -477,7 +477,9 @@ void App::initLayout()
|
||||
button->on_click = [this,button](Node*) {
|
||||
if (canvas)
|
||||
{
|
||||
canvas->m_canvas->save(data_path);
|
||||
canvas->m_canvas->open_project(data_path);
|
||||
for (auto& i : canvas->m_canvas->m_order)
|
||||
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
void stroke_draw();
|
||||
void stroke_end();
|
||||
void stroke_commit();
|
||||
void clear(const glm::vec4& color = { 1, 1, 1, 1 });
|
||||
void clear(const glm::vec4& color = { 1, 1, 1, 0 });
|
||||
void snapshot_save(std::string data_path);
|
||||
void snapshot_restore();
|
||||
void clear_context();
|
||||
|
||||
@@ -651,9 +651,10 @@ public:
|
||||
on_click(this);
|
||||
break;
|
||||
default:
|
||||
return kEventResult::Available;
|
||||
break;
|
||||
}
|
||||
return m_mouse_inside ? kEventResult::Consumed : kEventResult::Available;
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1345,14 +1346,14 @@ public:
|
||||
LOG("template initted");
|
||||
m_layers_container = find<NodeBorder>("layers-container");
|
||||
LOG("template container found");
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
LOG("add layer");
|
||||
add_layer();
|
||||
}
|
||||
// for (int i = 0; i < 1; i++)
|
||||
// {
|
||||
// LOG("add layer");
|
||||
// add_layer();
|
||||
// }
|
||||
LOG("find components");
|
||||
m_current_layer = m_layers[0];
|
||||
m_layers[0]->m_selected = true;
|
||||
// m_current_layer = m_layers[0];
|
||||
// m_layers[0]->m_selected = true;
|
||||
btn_add = find<NodeButtonCustom>("btn-add");
|
||||
btn_remove = find<NodeButtonCustom>("btn-remove");
|
||||
btn_up = find<NodeButtonCustom>("btn-up");
|
||||
@@ -1360,6 +1361,8 @@ public:
|
||||
LOG("attach events");
|
||||
btn_add->on_click = [this](Node*) {
|
||||
add_layer();
|
||||
if (on_layer_add)
|
||||
on_layer_add(this);
|
||||
};
|
||||
btn_remove->on_click = [this](Node*) {
|
||||
if (m_layers.size() == 1)
|
||||
@@ -1403,8 +1406,6 @@ public:
|
||||
l->on_selected = std::bind(&NodePanelLayer::handle_layer_selected, this, std::placeholders::_1);
|
||||
l->on_opacity_changed = std::bind(&NodePanelLayer::handle_layer_opacity, this, std::placeholders::_1, std::placeholders::_2);
|
||||
m_layers.push_back(l);
|
||||
if (on_layer_add)
|
||||
on_layer_add(this);
|
||||
}
|
||||
void remove_layer(NodeLayer* layer)
|
||||
{
|
||||
@@ -1886,16 +1887,16 @@ public:
|
||||
{
|
||||
m_mouse_ignore = false;
|
||||
m_canvas = std::make_unique<ui::Canvas>();
|
||||
m_canvas->create(512, 512);
|
||||
m_canvas->layer_add("asd");
|
||||
m_canvas->clear();
|
||||
m_canvas->create(1024, 1024);
|
||||
//m_canvas->layer_add("asd");
|
||||
//m_canvas->clear();
|
||||
m_sampler.create();
|
||||
m_face_plane.create<1>(2, 2);
|
||||
}
|
||||
virtual void restore_context() override
|
||||
{
|
||||
Node::restore_context();
|
||||
m_canvas->create(512, 512);
|
||||
m_canvas->create(1024, 1024);
|
||||
m_sampler.create();
|
||||
//m_canvas->clear();
|
||||
m_face_plane.create<1>(2, 2);
|
||||
@@ -1922,7 +1923,7 @@ public:
|
||||
glm::ivec4 c = (glm::ivec4)glm::vec4(box.x, (int)(vp[3] - box.y - box.w), box.z, box.w);
|
||||
glViewport(c.x, c.y, c.z, c.w);
|
||||
|
||||
m_canvas->m_cam_rot = m_pan * 0.001f;
|
||||
m_canvas->m_cam_rot = m_pan * 0.003f;
|
||||
|
||||
//glm::mat4 proj = glm::ortho(0.f, box.z, 0.f, box.w, -1000.f, 1000.f);
|
||||
glm::mat4 proj = glm::perspective(glm::radians(m_canvas->m_cam_fov), box.z / box.w, 0.1f, 1000.f);
|
||||
@@ -2064,8 +2065,8 @@ public:
|
||||
m_camera_fov = m_canvas->m_cam_fov;
|
||||
break;
|
||||
case kEventType::GestureMove:
|
||||
m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1);
|
||||
m_canvas->m_cam_fov = m_camera_fov - ge->m_distance_delta * .1f;
|
||||
m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1) * 0.3f;
|
||||
m_canvas->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f;
|
||||
//m_zoom_canvas = m_zoom_start + ge->m_distance_delta * .001f;
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user