added node alignment and text color

This commit is contained in:
2017-02-07 13:39:17 +00:00
parent 3cc25e7592
commit 83e59573e0
7 changed files with 84 additions and 38 deletions

View File

@@ -29,6 +29,8 @@ enum class kAttribute : uint16_t
Text = const_hash("text"),
FontFace = const_hash("font-face"),
FontSize = const_hash("font-size"),
Justify = const_hash("justify"),
Align = const_hash("align"),
};
enum class kWidget : uint16_t
@@ -222,10 +224,13 @@ public:
TextMesh m_text_mesh;
std::string m_text;
std::string m_font;
glm::vec4 m_color{ 1, 1, 1, 1 };
int m_size;
virtual std::unique_ptr<Widget> clone() override
{
return nullptr;
auto ret = std::make_unique<WidgetText>();
*ret = *this;
return std::move(ret);
}
virtual void create() override
{
@@ -240,6 +245,7 @@ public:
ShaderManager::use(kShader::Font);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_text_mesh.draw();
}
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) override
@@ -255,6 +261,16 @@ public:
case kAttribute::FontSize:
m_size = attr->IntValue();
break;
case 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)
m_color = glm::vec4(pad.x);
else
m_color = pad;
break;
}
default:
break;
}