add vr_draw_ui method and make ui observer as method to be wildly available

This commit is contained in:
2019-05-29 22:41:37 +02:00
parent 9d6bb0187e
commit d750f80482
4 changed files with 66 additions and 44 deletions

View File

@@ -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();