add vr_draw_ui method and make ui observer as method to be wildly available
This commit is contained in:
90
src/app.cpp
90
src/app.cpp
@@ -525,6 +525,50 @@ void App::async_end()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool App::update_ui_observer(Node *n)
|
||||
{
|
||||
if (n && n->m_display)
|
||||
{
|
||||
auto box = n->m_clip_uncut;
|
||||
Node* p = n->m_parent;
|
||||
while (p)
|
||||
{
|
||||
float pt = YGNodeLayoutGetPadding(p->y_node, YGEdgeTop);
|
||||
float pr = YGNodeLayoutGetPadding(p->y_node, YGEdgeRight);
|
||||
float pb = YGNodeLayoutGetPadding(p->y_node, YGEdgeBottom);
|
||||
float pl = YGNodeLayoutGetPadding(p->y_node, YGEdgeLeft);
|
||||
glm::vec2 off_p(pl, pt);
|
||||
glm::vec2 off_s(pr, pb);
|
||||
glm::vec4 pclip = { xy(p->m_clip_uncut) + off_p, zw(p->m_clip_uncut) - off_s - off_p };
|
||||
box = rect_intersection(box, pclip);
|
||||
p = p->m_parent;
|
||||
}
|
||||
//auto box = n->m_clip;
|
||||
//glm::ivec4 c = glm::vec4((int)box.x - 1, (int)(height / zoom - box.y - box.w) - 1, (int)box.z + 2, (int)box.w + 2) * zoom;
|
||||
if (box.z <= 0.f || box.w <= 0.f)
|
||||
{
|
||||
if (n->m_on_screen)
|
||||
{
|
||||
if (dynamic_cast<NodeStrokePreview*>(n))
|
||||
p = p;
|
||||
n->handle_on_screen(true, false);
|
||||
n->m_on_screen = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!n->m_on_screen)
|
||||
{
|
||||
n->handle_on_screen(false, true);
|
||||
n->m_on_screen = true;
|
||||
}
|
||||
glm::ivec4 c = glm::vec4((int)box.x, (int)(height / zoom - box.y - box.w), (int)box.z, (int)box.w) * zoom;
|
||||
glScissor(c.x + off_x, c.y + off_y, c.z, c.w);
|
||||
n->draw();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void App::update(float dt)
|
||||
{
|
||||
static std::mutex mutex;
|
||||
@@ -584,50 +628,8 @@ void App::update(float dt)
|
||||
layout[main_id]->find<NodeButtonCustom>("btn-mask-line")->set_active(mode == kCanvasMode::MaskLine);
|
||||
}
|
||||
|
||||
auto observer = [this](Node* n)
|
||||
{
|
||||
if (n && n->m_display)
|
||||
{
|
||||
auto box = n->m_clip_uncut;
|
||||
Node* p = n->m_parent;
|
||||
while (p)
|
||||
{
|
||||
float pt = YGNodeLayoutGetPadding(p->y_node, YGEdgeTop);
|
||||
float pr = YGNodeLayoutGetPadding(p->y_node, YGEdgeRight);
|
||||
float pb = YGNodeLayoutGetPadding(p->y_node, YGEdgeBottom);
|
||||
float pl = YGNodeLayoutGetPadding(p->y_node, YGEdgeLeft);
|
||||
glm::vec2 off_p(pl, pt);
|
||||
glm::vec2 off_s(pr, pb);
|
||||
glm::vec4 pclip = { xy(p->m_clip_uncut) + off_p, zw(p->m_clip_uncut) - off_s - off_p };
|
||||
box = rect_intersection(box, pclip);
|
||||
p = p->m_parent;
|
||||
}
|
||||
//auto box = n->m_clip;
|
||||
//glm::ivec4 c = glm::vec4((int)box.x - 1, (int)(height / zoom - box.y - box.w) - 1, (int)box.z + 2, (int)box.w + 2) * zoom;
|
||||
if (box.z <= 0.f || box.w <= 0.f)
|
||||
{
|
||||
if (n->m_on_screen)
|
||||
{
|
||||
if (dynamic_cast<NodeStrokePreview*>(n))
|
||||
p = p;
|
||||
n->handle_on_screen(true, false);
|
||||
n->m_on_screen = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!n->m_on_screen)
|
||||
{
|
||||
n->handle_on_screen(false, true);
|
||||
n->m_on_screen = true;
|
||||
}
|
||||
glm::ivec4 c = glm::vec4((int)box.x, (int)(height / zoom - box.y - box.w), (int)box.z, (int)box.w) * zoom;
|
||||
glScissor(c.x + off_x, c.y + off_y, c.z, c.w);
|
||||
n->draw();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
auto observer = std::bind(&App::update_ui_observer, this, std::placeholders::_1);
|
||||
|
||||
if (vr_active)
|
||||
{
|
||||
uirtt.bindFramebuffer();
|
||||
|
||||
@@ -137,9 +137,11 @@ public:
|
||||
void clear();
|
||||
void tick(float dt);
|
||||
void update(float dt);
|
||||
bool update_ui_observer(Node* n);
|
||||
bool vr_start();
|
||||
void vr_stop();
|
||||
void vr_draw(const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose);
|
||||
void vr_draw_ui();
|
||||
void async_start();
|
||||
void async_update();
|
||||
void async_redraw();
|
||||
|
||||
@@ -30,6 +30,7 @@ void App::tick(float dt)
|
||||
|
||||
void App::resize(float w, float h)
|
||||
{
|
||||
LOG("App::resize %d %d", (int)w, (int)h);
|
||||
uirtt.create(w, h);
|
||||
redraw = true;
|
||||
width = w;
|
||||
|
||||
@@ -23,6 +23,23 @@ void App::vr_stop()
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::vr_draw_ui()
|
||||
{
|
||||
if (auto* main = layout[main_id])
|
||||
main->update(width, height, zoom);
|
||||
|
||||
uirtt.bindFramebuffer();
|
||||
uirtt.clear();
|
||||
glViewport(0, 0, uirtt.getWidth(), uirtt.getHeight());
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
auto observer = std::bind(&App::update_ui_observer, this, std::placeholders::_1);
|
||||
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
|
||||
layout[main_id]->m_children[i]->watch(observer);
|
||||
//msgbox->watch(observer);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
uirtt.unbindFramebuffer();
|
||||
}
|
||||
|
||||
void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat4& pose)
|
||||
{
|
||||
//glm::mat4 ortho_proj = glm::ortho(0.f, box.z, 0.f, box.w, -1000.f, 1000.f);
|
||||
|
||||
Reference in New Issue
Block a user