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:
@@ -28,9 +28,10 @@ android {
|
||||
// Sets a flag to enable format macro constants for the C++ compiler.
|
||||
//cppFlags "-D__STDC_FORMAT_MACROS"
|
||||
arguments '-DANDROID_PLATFORM=android-19',
|
||||
'-DANDROID_TOOLCHAIN=clang',
|
||||
'-DANDROID_TOOLCHAIN=clang',
|
||||
'-DANDROID_STL=gnustl_static',
|
||||
'-DCMAKE_BUILD_TYPE=Debug'
|
||||
'-DCMAKE_BUILD_TYPE=Release',
|
||||
'-DANDROID_ARM_NEON=TRUE'
|
||||
}
|
||||
}
|
||||
ndk {
|
||||
|
||||
@@ -604,12 +604,14 @@ void android_main(struct android_app* state) {
|
||||
// If not animating, we will block forever waiting for events.
|
||||
// If animating, we loop until all events are read, then continue
|
||||
// to draw the next frame of animation.
|
||||
while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
|
||||
bool used = false;
|
||||
while (!used && (ident=ALooper_pollAll(-1, NULL, &events,
|
||||
(void**)&source)) >= 0) {
|
||||
|
||||
// Process this event.
|
||||
if (source != NULL) {
|
||||
source->process(state, source);
|
||||
used = true;
|
||||
}
|
||||
|
||||
// If a sensor has data, process it now.
|
||||
@@ -632,7 +634,8 @@ void android_main(struct android_app* state) {
|
||||
}
|
||||
}
|
||||
|
||||
if (engine.animating) {
|
||||
//if (engine.animating)
|
||||
{
|
||||
// Done with events; draw next animation frame.
|
||||
engine.state.angle += .01f;
|
||||
if (engine.state.angle > 1) {
|
||||
|
||||
@@ -328,6 +328,10 @@
|
||||
<!--main-->
|
||||
<layout id="main">
|
||||
<node dir="col" wrap="0" width="100%" height="100%" pad="0">
|
||||
<!-- content panel -->
|
||||
<node positioning="absolute" width="100%" height="100%" grow="1" color=".1" pad="0">
|
||||
<canvas id="paint-canvas" grow="1"/>
|
||||
</node>
|
||||
<!-- menu bar -->
|
||||
<border flood-events="1" margin="0 0 0 0" pad="0 0 0 0" color=".1" width="100%" height="30" dir="row" align="center">
|
||||
<button-custom id="menu-file" height="100%" margin="0 0 0 0" justify="center" align="center" pad="8" color=".1">
|
||||
@@ -389,10 +393,6 @@
|
||||
<!--<panel-color id="panel-color"/>-->
|
||||
</border>
|
||||
</node>
|
||||
<!-- content panel -->
|
||||
<node grow="1" color=".1" pad="0">
|
||||
<canvas id="paint-canvas" grow="1"/>
|
||||
</node>
|
||||
</node>
|
||||
<!-- status bar -->
|
||||
<!--<border height="30" width="100%" color=".15" border-color=".3" dir="row" pad="0 0 0 10" align="center">
|
||||
@@ -403,6 +403,6 @@
|
||||
</node>
|
||||
<!--<ref id="settings"/>-->
|
||||
<!--<ref id="popup-menu"/>-->
|
||||
<ref id="popup-dialog-open"/>
|
||||
<!--<ref id="popup-dialog-open"/>-->
|
||||
</layout>
|
||||
</root>
|
||||
|
||||
@@ -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