Popup presets panel, fix padding scissor, stacked mouse capture
This commit is contained in:
73
src/node.cpp
73
src/node.cpp
@@ -346,29 +346,71 @@ glm::vec4 Node::get_children_rect() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Node::is_child_recursive(Node* o) const
|
||||
{
|
||||
for (const auto& c : m_children)
|
||||
{
|
||||
if (c.get() == o || c->is_child_recursive(o))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Node::mouse_capture()
|
||||
{
|
||||
auto& c = root()->current_mouse_capture;
|
||||
auto& s = root()->m_capture_stack;
|
||||
|
||||
// already owner of capture
|
||||
if (root()->current_mouse_capture == this)
|
||||
if (c == this || std::find(s.begin(), s.end(), this) != s.end())
|
||||
return;
|
||||
|
||||
// cancel previous owner
|
||||
if (auto n = root()->current_mouse_capture)
|
||||
|
||||
if (c)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = kEventType::MouseCancel;
|
||||
n->handle_event(&e);
|
||||
if (c->is_child_recursive(this))
|
||||
{
|
||||
// save on stack
|
||||
s.push_back(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
// cancel previous owner
|
||||
MouseEvent e;
|
||||
e.m_type = kEventType::MouseCancel;
|
||||
c->handle_event(&e);
|
||||
|
||||
// TODO: only delete nodes on a different tree,
|
||||
// so preserve direct parents of this
|
||||
|
||||
// also clear the whole stack
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// make current
|
||||
root()->current_mouse_capture = this;
|
||||
c = this;
|
||||
m_mouse_captured = true;
|
||||
}
|
||||
|
||||
void Node::mouse_release()
|
||||
{
|
||||
if (root()->current_mouse_capture == this)
|
||||
root()->current_mouse_capture = nullptr;
|
||||
auto& c = root()->current_mouse_capture;
|
||||
auto& s = root()->m_capture_stack;
|
||||
|
||||
s.erase(std::remove(s.begin(), s.end(), this), s.end());
|
||||
if (c == this)
|
||||
{
|
||||
if (s.empty())
|
||||
{
|
||||
c = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
c = s.back();
|
||||
s.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
m_mouse_captured = false;
|
||||
}
|
||||
|
||||
@@ -646,13 +688,14 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
// correct the padding clip
|
||||
// should not clip the padded area
|
||||
// useful to draw decorations
|
||||
float pt = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeTop);
|
||||
float pr = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeRight);
|
||||
float pb = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeBottom);
|
||||
float pl = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeLeft);
|
||||
float pt = YGNodeLayoutGetPadding(parent->y_node, YGEdgeTop);
|
||||
float pr = YGNodeLayoutGetPadding(parent->y_node, YGEdgeRight);
|
||||
float pb = YGNodeLayoutGetPadding(parent->y_node, YGEdgeBottom);
|
||||
float pl = YGNodeLayoutGetPadding(parent->y_node, YGEdgeLeft);
|
||||
glm::vec2 off_p(pl, pt);
|
||||
glm::vec2 off_s(pr, pb);
|
||||
m_clip_uncut = glm::vec4(m_pos - off_p - glm::vec2(1), m_size + off_p + off_s + glm::vec2(2));
|
||||
glm::vec4 pclip = { xy(parent->m_clip) + off_p, zw(parent->m_clip) - off_s - off_p};
|
||||
m_clip_uncut = glm::vec4(m_pos, m_size);
|
||||
m_clip = rect_intersection(m_clip_uncut, parent->m_clip);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user