added singleton shader manager, custom widget attribute forward, parse border thickness and color for Border widget, parse and cache uniform locations, remove unused attrubutes code

This commit is contained in:
2017-01-30 19:52:32 +00:00
parent 16c1b6481e
commit a80556f418
8 changed files with 179 additions and 172 deletions

View File

@@ -2,7 +2,7 @@
#include "layout.h"
#include "util.hpp"
Plane* WidgetBorder::m_plane;
Plane WidgetBorder::m_plane;
void Node::update(float width, float height)
{
@@ -34,11 +34,11 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
c.update_internal(m_pos, proj);
}
void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* attr)
void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
{
switch (ka)
{
case att::kAttribute::Width:
case kAttribute::Width:
if (strcmp(attr->Value(), "auto") == 0)
{
YGNodeStyleSetWidth(y_node, YGUndefined);
@@ -52,16 +52,16 @@ void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* at
YGNodeStyleSetWidth(y_node, attr->FloatValue());
}
break;
case att::kAttribute::MinWidth:
case kAttribute::MinWidth:
if (strchr(attr->Value(), '%'))
YGNodeStyleSetMinWidthPercent(y_node, attr->FloatValue());
else
YGNodeStyleSetMinWidth(y_node, attr->FloatValue());
break;
case att::kAttribute::MaxWidth:
case kAttribute::MaxWidth:
YGNodeStyleSetMaxWidth(y_node, attr->FloatValue());
break;
case att::kAttribute::Height:
case kAttribute::Height:
if (strcmp(attr->Value(), "auto") == 0)
{
YGNodeStyleSetHeight(y_node, YGUndefined);
@@ -75,19 +75,19 @@ void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* at
YGNodeStyleSetHeight(y_node, attr->FloatValue());
}
break;
case att::kAttribute::MinHeight:
case kAttribute::MinHeight:
YGNodeStyleSetMinHeight(y_node, attr->FloatValue());
break;
case att::kAttribute::MaxHeight:
case kAttribute::MaxHeight:
YGNodeStyleSetMaxHeight(y_node, attr->FloatValue());
break;
case att::kAttribute::Grow:
case kAttribute::Grow:
YGNodeStyleSetFlexGrow(y_node, attr->FloatValue());
break;
case att::kAttribute::Shrink:
case kAttribute::Shrink:
YGNodeStyleSetFlexShrink(y_node, attr->FloatValue());
break;
case att::kAttribute::FlexDir:
case kAttribute::FlexDir:
{
YGFlexDirection dir = YGFlexDirectionRow;
if (strcmp("col", attr->Value()) == 0)
@@ -101,10 +101,10 @@ void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* at
YGNodeStyleSetFlexDirection(y_node, dir);
break;
}
case att::kAttribute::FlexWrap:
case kAttribute::FlexWrap:
YGNodeStyleSetFlexWrap(y_node, attr->IntValue() ? YGWrapWrap : YGWrapNoWrap);
break;
case att::kAttribute::Padding:
case kAttribute::Padding:
{
glm::vec4 pad;
int n = sscanf(attr->Value(), "%f %f %f %f", &pad.x, &pad.y, &pad.z, &pad.w);
@@ -124,7 +124,7 @@ void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* at
}
break;
}
case att::kAttribute::Margin:
case kAttribute::Margin:
{
glm::vec4 pad;
int n = sscanf(attr->Value(), "%f %f %f %f", &pad.x, &pad.y, &pad.z, &pad.w);
@@ -144,22 +144,9 @@ void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* at
}
break;
}
case att::kAttribute::Color:
{
glm::vec4 pad;
int n = sscanf(attr->Value(), "%f %f %f %f", &pad.x, &pad.y, &pad.z, &pad.w);
if (n == 1)
{
color = glm::vec4(pad.x);
}
else
{
color = pad;
}
break;
}
default:
// other_attributes_handler()
if (m_widget)
m_widget->parse_attributes(ka, attr);
break;
}
}
@@ -189,17 +176,17 @@ 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());
kWidget widget_id = (kWidget)const_hash(x_node->Name());
switch (widget_id)
{
case att::kWidget::Border:
case kWidget::Border:
m_widget = std::make_unique<WidgetBorder>();
break;
}
while (attr)
{
parse_attributes((att::kAttribute)const_hash(attr->Name()), attr);
parse_attributes((kAttribute)const_hash(attr->Name()), attr);
attr = attr->Next();
}