added settings popup and icon node
This commit is contained in:
@@ -8,8 +8,8 @@ enum class kAttribute : uint16_t
|
||||
{
|
||||
id = const_hash("id"),
|
||||
Width = const_hash("width"),
|
||||
MinWidth = const_hash("max-width"),
|
||||
MaxWidth = const_hash("min-width"),
|
||||
MinWidth = const_hash("min-width"),
|
||||
MaxWidth = const_hash("max-width"),
|
||||
Height = const_hash("height"),
|
||||
MinHeight = const_hash("min-height"),
|
||||
MaxHeight = const_hash("max-height"),
|
||||
@@ -35,6 +35,8 @@ enum class kAttribute : uint16_t
|
||||
Region = const_hash("region"),
|
||||
Position = const_hash("position"),
|
||||
Positioning = const_hash("positioning"),
|
||||
FloodEvents = const_hash("flood-events"),
|
||||
Icon = const_hash("icon"),
|
||||
};
|
||||
|
||||
enum class kWidget : uint16_t
|
||||
@@ -43,6 +45,7 @@ enum class kWidget : uint16_t
|
||||
Shape = const_hash("shape"),
|
||||
Text = const_hash("text"),
|
||||
Image = const_hash("image"),
|
||||
Icon = const_hash("icon"),
|
||||
Button = const_hash("button"),
|
||||
ButtonCustom = const_hash("button-custom"),
|
||||
PopupMenu = const_hash("popup-menu"),
|
||||
@@ -300,7 +303,7 @@ public:
|
||||
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);
|
||||
m_color = glm::vec4(pad.x, pad.x, pad.x, 1);
|
||||
else
|
||||
m_color = pad;
|
||||
break;
|
||||
@@ -628,7 +631,6 @@ public:
|
||||
virtual void init() override
|
||||
{
|
||||
m_flood_events = true;
|
||||
SetPadding(10, 10, 10, 10);
|
||||
SetPosition(0, 0);
|
||||
SetWidth(100);
|
||||
SetHeight(400);
|
||||
@@ -658,8 +660,8 @@ public:
|
||||
}
|
||||
virtual void loaded() override
|
||||
{
|
||||
m_thinkness = 1;
|
||||
m_border_color = glm::vec4(0, 0, 0, 1);
|
||||
//m_thinkness = 1;
|
||||
//m_border_color = glm::vec4(0, 0, 0, 1);
|
||||
m_color = color_normal;
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
@@ -686,3 +688,77 @@ public:
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
class NodeSettings : public Node
|
||||
{
|
||||
Node* m_template;
|
||||
NodeButton* btnOk;
|
||||
public:
|
||||
virtual Node* clone_instantiate() const override { return new NodeButtonCustom(); }
|
||||
virtual void init() override
|
||||
{
|
||||
SetPosition(0, 0);
|
||||
SetWidthP(100);
|
||||
SetHeightP(100);
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
m_template = (*m_manager)[const_hash("settings")].m_children[0]->clone();
|
||||
add_child(m_template);
|
||||
btnOk = m_template->find<NodeButton>("btn-ok");
|
||||
btnOk->on_click = [&] { destroy(); };
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
class NodeIcon : public NodeImage
|
||||
{
|
||||
static std::map<std::string, glm::vec4> m_icons;
|
||||
std::string m_icon_name;
|
||||
public:
|
||||
static void static_init()
|
||||
{
|
||||
// spritesheet maker: https://draeton.github.io/stitches/
|
||||
// icons: http://www.famfamfam.com/lab/icons/silk/
|
||||
// regex css -> spritesheet.txt: \.([^{]+) {\s+width: (\d+)px;\s+height: (\d+)px;\s+.*: -(\d+)px -(\d+)px;\s+}\s+
|
||||
// to: "\1",\2,\3,\4,\5\n
|
||||
static char str[256];
|
||||
int x, y, w, h;
|
||||
FILE* f = fopen("data/spritesheet.txt", "r");
|
||||
while (!feof(f) && fscanf(f, "%s %d %d %d %d", str, &w, &h, &x, &y) == 5)
|
||||
{
|
||||
m_icons[str] = glm::vec4(x, y, x+w, y+h);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
virtual Node* clone_instantiate() const override { return new NodeIcon(); }
|
||||
virtual void clone_copy(Node* dest) const override
|
||||
{
|
||||
NodeImage::clone_copy(dest);
|
||||
NodeIcon* n = static_cast<NodeIcon*>(dest);
|
||||
n->m_icon_name = m_icon_name;
|
||||
}
|
||||
virtual void create() override
|
||||
{
|
||||
m_region = m_icons[m_icon_name];
|
||||
m_path = "data/spritesheet.png";
|
||||
m_tex_id = const_hash(m_path.c_str());
|
||||
m_use_atlas = true;
|
||||
NodeImage::create();
|
||||
auto tex_sz = TextureManager::get(m_tex_id).size();
|
||||
YGNodeStyleSetAspectRatio(y_node, tex_sz.x / tex_sz.y);
|
||||
}
|
||||
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) override
|
||||
{
|
||||
NodeImage::parse_attributes(ka, attr);
|
||||
switch (ka)
|
||||
{
|
||||
case kAttribute::Icon:
|
||||
m_icon_name = attr->Value();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user