Plan UI observer frame clipping
This commit is contained in:
105
src/app.cpp
105
src/app.cpp
@@ -495,54 +495,67 @@ void App::async_swap()
|
||||
|
||||
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::vec2 parent_offset = p->m_parent ? -p->m_parent->m_pos_offset_childred : glm::vec2(0.f);
|
||||
glm::vec4 pclip = { xy(p->m_clip_uncut) + off_p, zw(p->m_clip_uncut) - off_s - off_p/* + parent_offset*/ };
|
||||
box = rect_intersection(box, pclip);
|
||||
p = p->m_parent;
|
||||
std::vector<pp::app::AppUiObserverParentClip> parent_clips;
|
||||
if (n) {
|
||||
for (Node* p = n->m_parent; p; p = p->m_parent) {
|
||||
parent_clips.push_back(pp::app::AppUiObserverParentClip {
|
||||
.clip = pp::app::AppUiObserverRect {
|
||||
.x = p->m_clip_uncut.x,
|
||||
.y = p->m_clip_uncut.y,
|
||||
.width = p->m_clip_uncut.z,
|
||||
.height = p->m_clip_uncut.w,
|
||||
},
|
||||
.padding_top = YGNodeLayoutGetPadding(p->y_node, YGEdgeTop),
|
||||
.padding_right = YGNodeLayoutGetPadding(p->y_node, YGEdgeRight),
|
||||
.padding_bottom = YGNodeLayoutGetPadding(p->y_node, YGEdgeBottom),
|
||||
.padding_left = YGNodeLayoutGetPadding(p->y_node, YGEdgeLeft),
|
||||
});
|
||||
}
|
||||
//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;
|
||||
glm::vec2 parent_offset = n->m_parent ? n->m_parent->m_pos_offset_childred : glm::vec2(0.f);
|
||||
if (box.z <= 0 || box.w <= 0)
|
||||
{
|
||||
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(box.x - 1, (height / zoom - box.y - box.w - 1), box.z + 2, box.w + 2) * zoom;
|
||||
apply_app_scissor(pp::renderer::gl::OpenGlScissorRect {
|
||||
.enabled = 1U,
|
||||
.x = static_cast<std::int32_t>(floorf(c.x + off_x)),
|
||||
.y = static_cast<std::int32_t>(floorf(c.y + off_y)),
|
||||
.width = static_cast<std::int32_t>(ceilf(c.z)),
|
||||
.height = static_cast<std::int32_t>(ceilf(c.w)),
|
||||
});
|
||||
n->draw();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
const auto plan = pp::app::plan_app_ui_observer(
|
||||
n != nullptr,
|
||||
n && n->m_display,
|
||||
n && n->m_on_screen,
|
||||
n
|
||||
? pp::app::AppUiObserverRect {
|
||||
.x = n->m_clip_uncut.x,
|
||||
.y = n->m_clip_uncut.y,
|
||||
.width = n->m_clip_uncut.z,
|
||||
.height = n->m_clip_uncut.w,
|
||||
}
|
||||
: pp::app::AppUiObserverRect {},
|
||||
parent_clips,
|
||||
height,
|
||||
zoom,
|
||||
off_x,
|
||||
off_y);
|
||||
if (!plan) {
|
||||
LOG("UI observer plan failed: %s", plan.status().message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!n)
|
||||
return false;
|
||||
|
||||
if (plan.value().notify_leave_screen)
|
||||
n->handle_on_screen(true, false);
|
||||
if (plan.value().notify_enter_screen)
|
||||
n->handle_on_screen(false, true);
|
||||
n->m_on_screen = plan.value().next_on_screen;
|
||||
|
||||
if (!plan.value().draw_node)
|
||||
return false;
|
||||
|
||||
apply_app_scissor(pp::renderer::gl::OpenGlScissorRect {
|
||||
.enabled = 1U,
|
||||
.x = plan.value().scissor_x,
|
||||
.y = plan.value().scissor_y,
|
||||
.width = plan.value().scissor_width,
|
||||
.height = plan.value().scissor_height,
|
||||
});
|
||||
n->draw();
|
||||
return true;
|
||||
}
|
||||
|
||||
void App::draw(float dt)
|
||||
|
||||
Reference in New Issue
Block a user