start implementing shape tag
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
|
||||
enum class kAttribute : uint16_t
|
||||
{
|
||||
Width = const_hash("width"),
|
||||
id = const_hash("id"),
|
||||
Width = const_hash("width"),
|
||||
MinWidth = const_hash("max-width"),
|
||||
MaxWidth = const_hash("min-width"),
|
||||
Height = const_hash("height"),
|
||||
@@ -23,11 +24,22 @@ enum class kAttribute : uint16_t
|
||||
Color = const_hash("color"),
|
||||
Thickness = const_hash("thickness"),
|
||||
BorderColor = const_hash("border-color"),
|
||||
Type = const_hash("type"),
|
||||
};
|
||||
|
||||
enum class kWidget : uint16_t
|
||||
{
|
||||
Border = const_hash("border"),
|
||||
Shape = const_hash("shape"),
|
||||
};
|
||||
|
||||
enum class kShapeType : uint16_t
|
||||
{
|
||||
Quad = const_hash("rect"),
|
||||
Poly = const_hash("poly"),
|
||||
RoundRect = const_hash("round-rect"),
|
||||
Slice9 = const_hash("slice9"),
|
||||
|
||||
};
|
||||
|
||||
class Widget
|
||||
@@ -35,8 +47,9 @@ class Widget
|
||||
public:
|
||||
glm::mat4 mvp;
|
||||
glm::vec4 clip;
|
||||
virtual void draw() { };
|
||||
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) { };
|
||||
virtual void create() { }
|
||||
virtual void draw() { }
|
||||
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) { }
|
||||
};
|
||||
|
||||
class WidgetBorder : public Widget
|
||||
@@ -89,6 +102,85 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class WidgetShape : public Widget
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<Shape> m_shape;
|
||||
kShapeType m_type;
|
||||
glm::vec4 m_color;
|
||||
glm::vec4 m_border_color;
|
||||
float m_thinkness{ 1 };
|
||||
float m_radius{ .5f };
|
||||
virtual void create() override
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case kShapeType::Quad:
|
||||
m_shape = std::make_unique<Plane>();
|
||||
((Plane*)m_shape.get())->create<1>(1, 1);
|
||||
break;
|
||||
case kShapeType::Poly:
|
||||
m_shape = std::make_unique<Circle>();
|
||||
((Circle*)m_shape.get())->create<5>(m_radius);
|
||||
break;
|
||||
case kShapeType::RoundRect:
|
||||
m_shape = std::make_unique<Rounded>();
|
||||
((Rounded*)m_shape.get())->create<3>(1, 1, .1f);
|
||||
break;
|
||||
case kShapeType::Slice9:
|
||||
m_shape = std::make_unique<Slice9>();
|
||||
((Slice9*)m_shape.get())->create(1, 1, .1f, .1f);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
virtual void draw() override
|
||||
{
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
|
||||
m_shape->draw_fill();
|
||||
|
||||
glLineWidth(m_thinkness);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
||||
m_shape->draw_stroke();
|
||||
}
|
||||
virtual void parse_attributes(kAttribute id, const tinyxml2::XMLAttribute* attr)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
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;
|
||||
}
|
||||
case kAttribute::BorderColor:
|
||||
{
|
||||
glm::vec4 pad;
|
||||
int n = sscanf(attr->Value(), "%f %f %f %f", &pad.x, &pad.y, &pad.z, &pad.w);
|
||||
if (n == 1)
|
||||
m_border_color = glm::vec4(pad.x);
|
||||
else
|
||||
m_border_color = pad;
|
||||
break;
|
||||
}
|
||||
case kAttribute::Thickness:
|
||||
m_thinkness = attr->FloatValue();
|
||||
break;
|
||||
case kAttribute::Type:
|
||||
m_type = (kShapeType)const_hash(attr->Value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Node
|
||||
{
|
||||
const Node* parent{ nullptr };
|
||||
|
||||
Reference in New Issue
Block a user