rename engine to src
This commit is contained in:
127
src/node_button.cpp
Normal file
127
src/node_button.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "node_button.h"
|
||||
|
||||
Node* NodeButton::clone_instantiate() const
|
||||
{
|
||||
return new NodeButton();
|
||||
}
|
||||
|
||||
void NodeButton::clone_children(Node* dest) const
|
||||
{
|
||||
Node::clone_children(dest);
|
||||
NodeButton* n = static_cast<NodeButton*>(dest);
|
||||
n->m_border = (NodeBorder*)n->m_children[0].get();
|
||||
n->m_text = (NodeText*)n->m_border->m_children[0].get();
|
||||
}
|
||||
|
||||
void NodeButton::clone_copy(Node* dest) const
|
||||
{
|
||||
Node::clone_copy(dest);
|
||||
NodeButton* n = static_cast<NodeButton*>(dest);
|
||||
//n->m_border = (NodeBorder*)m_border->clone();
|
||||
//n->m_text = (NodeText*)m_text->clone();
|
||||
n->color_normal = color_normal;
|
||||
n->color_hover = color_hover;
|
||||
n->color_down = color_down;
|
||||
//n->on_click = on_click;
|
||||
n->m_mouse_ignore = false;
|
||||
}
|
||||
|
||||
void NodeButton::init()
|
||||
{
|
||||
m_border = new NodeBorder();
|
||||
m_text = new NodeText();
|
||||
add_child(m_border);
|
||||
m_border->add_child(m_text);
|
||||
m_border->init();
|
||||
m_border->m_color = color_normal;
|
||||
m_text->init();
|
||||
m_text->m_font = "arial";
|
||||
m_text->m_font_size = 11;
|
||||
m_border->SetAlign(YGAlignCenter);
|
||||
m_border->SetJustify(YGJustifyCenter);
|
||||
m_border->m_mouse_ignore = false;
|
||||
m_mouse_ignore = false;
|
||||
}
|
||||
|
||||
void NodeButton::create()
|
||||
{
|
||||
m_border->create();
|
||||
m_text->create();
|
||||
m_border->m_mouse_ignore = false;
|
||||
m_mouse_ignore = false;
|
||||
}
|
||||
|
||||
void NodeButton::loaded()
|
||||
{
|
||||
m_border->m_thinkness = 1;
|
||||
m_border->m_border_color = glm::vec4(0, 0, 0, 1);
|
||||
m_border->m_color = color_normal;
|
||||
m_border->m_mouse_ignore = false;
|
||||
m_mouse_ignore = false;
|
||||
}
|
||||
|
||||
void NodeButton::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
||||
{
|
||||
switch (ka)
|
||||
{
|
||||
case kAttribute::Color:
|
||||
m_border->parse_attributes(ka, attr);
|
||||
color_normal = m_border->m_color;
|
||||
color_hover = glm::clamp(m_border->m_color + glm::vec4(.1, .1, .1, 0), {0,0,0,0}, {1,1,1,1});
|
||||
color_down = glm::clamp(m_border->m_color + glm::vec4(.2, .2, .2, 0), {0,0,0,0}, {1,1,1,1});
|
||||
case kAttribute::Padding:
|
||||
case kAttribute::Width:
|
||||
case kAttribute::Height:
|
||||
case kAttribute::Thickness:
|
||||
case kAttribute::BorderColor:
|
||||
m_border->parse_attributes(ka, attr);
|
||||
break;
|
||||
case kAttribute::Text:
|
||||
case kAttribute::FontFace:
|
||||
case kAttribute::FontSize:
|
||||
m_text->parse_attributes(ka, attr);
|
||||
break;
|
||||
default:
|
||||
Node::parse_attributes(ka, attr);
|
||||
break;
|
||||
}
|
||||
// m_border->parse_attributes(ka, attr);
|
||||
// m_text->parse_attributes(ka, attr);
|
||||
}
|
||||
|
||||
void NodeButton::set_color(const glm::vec4& c)
|
||||
{
|
||||
color_normal = c;
|
||||
m_border->m_color = color_normal;
|
||||
}
|
||||
|
||||
kEventResult NodeButton::handle_event(Event* e)
|
||||
{
|
||||
Node::handle_event(e);
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseEnter:
|
||||
m_border->m_color = color_hover;
|
||||
break;
|
||||
case kEventType::MouseLeave:
|
||||
m_border->m_color = color_normal;
|
||||
break;
|
||||
case kEventType::MouseDownL:
|
||||
m_border->m_color = color_down;
|
||||
break;
|
||||
case kEventType::MouseUpL:
|
||||
m_border->m_color = color_normal;
|
||||
if (m_mouse_inside && on_click != nullptr)
|
||||
on_click(this);
|
||||
break;
|
||||
case kEventType::MouseCancel:
|
||||
m_border->m_color = color_normal;
|
||||
break;
|
||||
default:
|
||||
return kEventResult::Available;
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
Reference in New Issue
Block a user