started implementing dynamic widget allocation by xml tag

This commit is contained in:
2017-01-29 17:42:23 +00:00
parent 7436706b37
commit 16c1b6481e
10 changed files with 94 additions and 46 deletions

View File

@@ -1,15 +1,19 @@
#include "pch.h"
#include "layout.h"
#include "util.hpp"
Plane* WidgetBorder::m_plane;
void Node::update(float width, float height)
{
YGNodeStyleSetWidth(y_node, width);
YGNodeStyleSetHeight(y_node, height);
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
update_internal({ 0, 0 });
glm::mat4 proj = glm::ortho(0.f, m_size.x, m_size.y, 0.f, -1.f, 1.f);
update_internal({ 0, 0 }, proj);
}
void Node::update_internal(glm::vec2 origin)
void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
{
float x = YGNodeLayoutGetLeft(y_node);
float y = YGNodeLayoutGetTop(y_node);
@@ -17,12 +21,17 @@ void Node::update_internal(glm::vec2 origin)
float h = YGNodeLayoutGetHeight(y_node);
m_pos = origin + glm::vec2(x, y);
m_size = glm::vec2(w, h);
if (!parent)
m_clip = glm::vec4(m_pos, m_size);
else
m_clip = rect_intersection(glm::vec4(m_pos, m_size), parent->m_clip);
m_clip = !parent ? glm::vec4(m_pos, m_size) : rect_intersection(glm::vec4(m_pos, m_size), parent->m_clip);
if (m_widget)
{
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
glm::mat4 scale = glm::scale(glm::vec3(m_size, 1.f));
glm::mat4 pos = glm::translate(glm::vec3(m_pos, 0));
m_widget->mvp = proj * pos * scale * pivot;
m_widget->clip = m_clip;
}
for (auto& c : m_children)
c.update_internal(m_pos);
c.update_internal(m_pos, proj);
}
void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* attr)
@@ -179,9 +188,18 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
{
m_name = x_node->Name();
auto attr = x_node->FirstAttribute();
att::kWidget widget_id = (att::kWidget)const_hash(x_node->Name());
switch (widget_id)
{
case att::kWidget::Border:
m_widget = std::make_unique<WidgetBorder>();
break;
}
while (attr)
{
parse_attributes((att::kAttribute)att::const_hash(attr->Name()), attr);
parse_attributes((att::kAttribute)const_hash(attr->Name()), attr);
attr = attr->Next();
}