added right click, popup menu, mark for destroy
This commit is contained in:
@@ -8,9 +8,15 @@ Sampler NodeImage::m_sampler;
|
||||
|
||||
kEventResult Node::on_event(Event* e)
|
||||
{
|
||||
for (auto& c : m_children)
|
||||
if (c->on_event(e) == kEventResult::Consumed)
|
||||
return kEventResult::Consumed;
|
||||
kEventResult ret = kEventResult::Available;
|
||||
for (auto it = m_children.rbegin(); it != m_children.rend(); ++it)
|
||||
if ((*it)->on_event(e) == kEventResult::Consumed)
|
||||
if (m_flood_events)
|
||||
ret = kEventResult::Consumed;
|
||||
else
|
||||
return kEventResult::Consumed;
|
||||
if (ret == kEventResult::Consumed)
|
||||
return ret;
|
||||
switch (e->m_cat)
|
||||
{
|
||||
case kEventCategory::MouseEvent:
|
||||
@@ -35,7 +41,8 @@ kEventResult Node::on_event(Event* e)
|
||||
handle_event(&e2);
|
||||
}
|
||||
m_mouse_inside = inside;
|
||||
handle_event(e);
|
||||
if (inside)
|
||||
ret = handle_event(e);
|
||||
if (inside_old == true && inside == false)
|
||||
{
|
||||
MouseEvent e2 = *me;
|
||||
@@ -51,7 +58,7 @@ kEventResult Node::on_event(Event* e)
|
||||
return kEventResult::Consumed;
|
||||
break;
|
||||
}
|
||||
return kEventResult::Available;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Node::add_child(Node* n)
|
||||
@@ -77,8 +84,14 @@ void Node::update(float width, float height)
|
||||
YGNodeStyleSetWidth(y_node, width);
|
||||
YGNodeStyleSetHeight(y_node, height);
|
||||
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
glm::mat4 proj = glm::ortho(0.f, width, height, 0.f, -1.f, 1.f);
|
||||
update_internal({ 0, 0 }, proj);
|
||||
m_proj = glm::ortho(0.f, width, height, 0.f, -1.f, 1.f);
|
||||
update_internal({ 0, 0 }, m_proj);
|
||||
}
|
||||
|
||||
void Node::update()
|
||||
{
|
||||
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
update_internal({ 0, 0 }, m_proj);
|
||||
}
|
||||
|
||||
void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
@@ -88,7 +101,7 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
float w = YGNodeLayoutGetWidth(y_node);
|
||||
float h = YGNodeLayoutGetHeight(y_node);
|
||||
m_pos = glm::floor(origin + glm::vec2(x, y));
|
||||
m_size = glm::ceil(glm::vec2(w, h));
|
||||
m_size = glm::floor(glm::vec2(w, h));
|
||||
|
||||
if (parent)
|
||||
{
|
||||
@@ -114,6 +127,16 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
glm::mat4 pos = glm::translate(glm::vec3(m_pos, 0));
|
||||
m_mvp = proj * pos * scale * pivot;
|
||||
m_proj = proj;
|
||||
|
||||
for (int i = 0; i < m_children.size(); i++)
|
||||
{
|
||||
if (m_children[i]->m_destroyed)
|
||||
{
|
||||
remove_child(m_children[i].get());
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& c : m_children)
|
||||
c->update_internal(m_pos, proj);
|
||||
}
|
||||
@@ -346,6 +369,20 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
||||
n->load_internal(x_child);
|
||||
break;
|
||||
}
|
||||
case kWidget::ButtonCustom:
|
||||
{
|
||||
auto n = new NodeButtonCustom();
|
||||
add_child(n);
|
||||
n->load_internal(x_child);
|
||||
break;
|
||||
}
|
||||
case kWidget::PopupMenu:
|
||||
{
|
||||
auto n = new NodePopupMenu();
|
||||
add_child(n);
|
||||
n->load_internal(x_child);
|
||||
break;
|
||||
}
|
||||
case kWidget::Ref:
|
||||
{
|
||||
auto ids = x_child->Attribute("id");
|
||||
@@ -365,6 +402,7 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
||||
}
|
||||
x_child = x_child->NextSiblingElement();
|
||||
}
|
||||
loaded();
|
||||
}
|
||||
|
||||
Node* Node::clone()
|
||||
@@ -392,6 +430,7 @@ void Node::clone_copy(Node* dest) const
|
||||
dest->m_pos = m_pos;
|
||||
dest->m_size = m_size;
|
||||
dest->m_clip = m_clip;
|
||||
dest->m_flood_events = m_flood_events;
|
||||
}
|
||||
|
||||
void Node::clone_children(Node* dest) const
|
||||
|
||||
Reference in New Issue
Block a user