split app.cpp into multiple files, add NodeScroll and use it to scroll the side panels, some fixes to the events system
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "node_color_quad.h"
|
||||
#include "node_stroke_preview.h"
|
||||
#include "node_canvas.h"
|
||||
#include "node_scroll.h"
|
||||
|
||||
void Node::watch(std::function<void(Node*)> observer)
|
||||
{
|
||||
@@ -47,26 +48,35 @@ Node* Node::root()
|
||||
|
||||
kEventResult Node::on_event(Event* e)
|
||||
{
|
||||
kEventResult ret = kEventResult::Available;
|
||||
|
||||
if (current_mouse_capture)
|
||||
return current_mouse_capture->on_event(e);
|
||||
|
||||
kEventResult ret = kEventResult::Available;
|
||||
for (auto it = m_children.rbegin(); it != m_children.rend(); ++it)
|
||||
bool skip_children = false;
|
||||
skip_children |= (e->m_cat == kEventCategory::MouseEvent) &&
|
||||
(m_mouse_captured) && (root()->current_mouse_capture == this) && m_capture_children;
|
||||
|
||||
if (!skip_children)
|
||||
{
|
||||
if ((*it)->on_event(e) == kEventResult::Consumed)
|
||||
for (auto it = m_children.rbegin(); it != m_children.rend(); ++it)
|
||||
{
|
||||
if (m_flood_events)
|
||||
if ((*it)->on_event(e) == kEventResult::Consumed)
|
||||
{
|
||||
ret = kEventResult::Consumed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kEventResult::Consumed;
|
||||
if (m_flood_events)
|
||||
{
|
||||
ret = kEventResult::Consumed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret == kEventResult::Consumed)
|
||||
return ret;
|
||||
}
|
||||
if (ret == kEventResult::Consumed)
|
||||
return ret;
|
||||
|
||||
switch (e->m_cat)
|
||||
{
|
||||
case kEventCategory::MouseEvent:
|
||||
@@ -79,6 +89,7 @@ kEventResult Node::on_event(Event* e)
|
||||
m_mouse_inside = inside;
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseScroll:
|
||||
case kEventType::MouseDownL:
|
||||
case kEventType::MouseDownR:
|
||||
case kEventType::MouseUpL:
|
||||
@@ -240,24 +251,39 @@ int Node::get_child_index(Node* n)
|
||||
return -1;
|
||||
}
|
||||
|
||||
glm::vec4 Node::get_children_rect() const
|
||||
{
|
||||
if (m_children.empty())
|
||||
return glm::vec4(0);
|
||||
glm::vec4 ret = m_children[0]->m_clip_uncut;
|
||||
for (auto& c : m_children)
|
||||
ret = rect_union(ret, c->m_clip_uncut);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Node::mouse_capture()
|
||||
{
|
||||
root()->current_mouse_capture = this; m_mouse_captured = true;
|
||||
root()->current_mouse_capture = this;
|
||||
m_mouse_captured = true;
|
||||
}
|
||||
|
||||
void Node::mouse_release()
|
||||
{
|
||||
root()->current_mouse_capture = nullptr; m_mouse_captured = false;
|
||||
if (root()->current_mouse_capture == this)
|
||||
root()->current_mouse_capture = nullptr;
|
||||
m_mouse_captured = false;
|
||||
}
|
||||
|
||||
void Node::key_capture()
|
||||
{
|
||||
root()->current_key_capture = this; m_key_captured = true;
|
||||
root()->current_key_capture = this;
|
||||
m_key_captured = true;
|
||||
}
|
||||
|
||||
void Node::key_release()
|
||||
{
|
||||
root()->current_key_capture = nullptr; m_key_captured = false;
|
||||
root()->current_key_capture = nullptr;
|
||||
m_key_captured = false;
|
||||
}
|
||||
|
||||
Node&& Node::operator=(Node&& o)
|
||||
@@ -335,6 +361,15 @@ void Node::SetPadding(float t, float r, float b, float l)
|
||||
YGNodeStyleSetPadding(y_node, YGEdgeLeft, l);
|
||||
}
|
||||
|
||||
glm::vec4 Node::GetPadding() const
|
||||
{
|
||||
float t = YGNodeLayoutGetPadding(y_node, YGEdgeTop);
|
||||
float r = YGNodeLayoutGetPadding(y_node, YGEdgeRight);
|
||||
float b = YGNodeLayoutGetPadding(y_node, YGEdgeBottom);
|
||||
float l = YGNodeLayoutGetPadding(y_node, YGEdgeLeft);
|
||||
return{ t, r, b, l };
|
||||
}
|
||||
|
||||
void Node::SetPosition(const glm::vec2 pos)
|
||||
{
|
||||
SetPosition(pos.x, pos.y);
|
||||
@@ -414,12 +449,26 @@ glm::vec2 Node::GetSize()
|
||||
return{ GetWidth(), GetHeight() };
|
||||
}
|
||||
|
||||
glm::vec4 Node::rect_intersection(glm::vec4 a, glm::vec4 b)
|
||||
glm::vec4 Node::rect_intersection(glm::vec4 a, glm::vec4 b) const
|
||||
{
|
||||
// convert from [x,y,w,h] to [x1,y1,x2,y1]
|
||||
a = glm::vec4(a.xy(), a.xy() + a.zw());
|
||||
b = glm::vec4(b.xy(), b.xy() + b.zw());
|
||||
// compute intersection
|
||||
auto o = glm::vec4(glm::max(a.xy(), b.xy()), glm::min(a.zw(), b.zw()));
|
||||
// back to rect form
|
||||
o = glm::vec4(o.xy(), glm::max({ 0, 0 }, o.zw() - o.xy()));
|
||||
return o;
|
||||
}
|
||||
|
||||
glm::vec4 Node::rect_union(glm::vec4 a, glm::vec4 b) const
|
||||
{
|
||||
// convert from rect [x,y,w,h] to bb [x1,y1,x2,y1]
|
||||
a = glm::vec4(a.xy(), a.xy() + a.zw());
|
||||
b = glm::vec4(b.xy(), b.xy() + b.zw());
|
||||
// compute union
|
||||
glm::vec4 o = { glm::min(a.xy(), b.xy()), glm::max(a.zw(), b.zw()) };
|
||||
// back to rect form
|
||||
o = glm::vec4(o.xy(), glm::max({ 0, 0 }, o.zw() - o.xy()));
|
||||
return o;
|
||||
}
|
||||
@@ -459,7 +508,9 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
float w = YGNodeLayoutGetWidth(y_node);
|
||||
float h = YGNodeLayoutGetHeight(y_node);
|
||||
auto old_size = m_size;
|
||||
m_pos = glm::floor(origin + glm::vec2(x, y));
|
||||
glm::vec2 parent_offset = parent ? parent->m_pos_offset_childred : glm::vec2(0.f);
|
||||
m_pos = glm::floor(origin + glm::vec2(x, y) + m_pos_offset + parent_offset);
|
||||
m_pos_origin = glm::floor(origin + glm::vec2(x, y));
|
||||
m_size = glm::floor(glm::vec2(w, h));
|
||||
|
||||
if (parent)
|
||||
@@ -478,7 +529,7 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_clip = glm::vec4(m_pos, m_size);
|
||||
m_clip_uncut = m_clip = glm::vec4(m_pos, m_size);
|
||||
}
|
||||
|
||||
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
||||
@@ -726,6 +777,7 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
||||
CASE(kWidget::ColorQuad, NodeColorQuad);
|
||||
CASE(kWidget::StrokePreview, NodeStrokePreview);
|
||||
CASE(kWidget::Canvas, NodeCanvas);
|
||||
CASE(kWidget::Scroll, NodeScroll);
|
||||
#undef CASE
|
||||
case kWidget::Ref:
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user