rename parent to m_parent and add floating panel class
This commit is contained in:
@@ -345,6 +345,7 @@
|
||||
<ClCompile Include="src\node_message_box.cpp" />
|
||||
<ClCompile Include="src\node_panel_brush.cpp" />
|
||||
<ClCompile Include="src\node_panel_color.cpp" />
|
||||
<ClCompile Include="src\node_panel_floating.cpp" />
|
||||
<ClCompile Include="src\node_panel_grid.cpp" />
|
||||
<ClCompile Include="src\node_panel_layer.cpp" />
|
||||
<ClCompile Include="src\node_panel_quick.cpp" />
|
||||
@@ -465,6 +466,7 @@
|
||||
<ClInclude Include="src\node_message_box.h" />
|
||||
<ClInclude Include="src\node_panel_brush.h" />
|
||||
<ClInclude Include="src\node_panel_color.h" />
|
||||
<ClInclude Include="src\node_panel_floating.h" />
|
||||
<ClInclude Include="src\node_panel_grid.h" />
|
||||
<ClInclude Include="src\node_panel_layer.h" />
|
||||
<ClInclude Include="src\node_panel_quick.h" />
|
||||
|
||||
@@ -342,6 +342,9 @@
|
||||
<ClCompile Include="libs\yoga\yoga\Utils.cpp">
|
||||
<Filter>libs\yoga</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\node_panel_floating.cpp">
|
||||
<Filter>Source Files\ui</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\app.h">
|
||||
@@ -566,6 +569,9 @@
|
||||
<ClInclude Include="src\serializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\node_panel_floating.h">
|
||||
<Filter>Header Files\ui</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="PanoPainter.rc">
|
||||
|
||||
@@ -1271,6 +1271,20 @@ Here's a list of what's available in this release.
|
||||
</border>
|
||||
</layout>
|
||||
|
||||
<!-- DIALOG FLOATING -->
|
||||
<layout id="tpl-panel-floating">
|
||||
<border thickness="1" border-color=".2" pad="3" max-width="650" dir="col" mouse-capture="true">
|
||||
<border height="30" pad="0 0 0 0" color=".4" align="center" justify="center" dir="row">
|
||||
<button id="button-minimize" width="30" height="20" text="--" margin="0 0 0 5"/>
|
||||
<node align="center" pad="0 30 0 30" justify="center" height="100%" grow="1">
|
||||
<text text="Floating Panel"/>
|
||||
</node>
|
||||
</border>
|
||||
<border id="container" height="400" color="0 0 0 .9" pad="10" dir="col">
|
||||
</border>
|
||||
</border>
|
||||
</layout>
|
||||
|
||||
<!-- MENU POPUP -->
|
||||
<layout id="popup-menu">
|
||||
<popup-menu positioning="absolute" position="100 100" width="150" thickness="1" border-color=".1" color=".4 .4 .4 .8" dir="col">
|
||||
@@ -1469,7 +1483,6 @@ Here's a list of what's available in this release.
|
||||
</popup-menu>
|
||||
</layout>
|
||||
|
||||
|
||||
<!-- MENU TIMELAPSE -->
|
||||
<layout id="timelapse-menu">
|
||||
<popup-menu positioning="absolute" position="100 100" width="150" thickness="1" border-color=".1" color=".4 .4 .4 .8" dir="col">
|
||||
|
||||
@@ -577,7 +577,7 @@ void App::update(float dt)
|
||||
if (n && n->m_display)
|
||||
{
|
||||
auto box = n->m_clip_uncut;
|
||||
Node* p = n->parent;
|
||||
Node* p = n->m_parent;
|
||||
if (dynamic_cast<NodeBrushPresetItem*>(n))
|
||||
p = p;
|
||||
while (p)
|
||||
@@ -590,7 +590,7 @@ void App::update(float dt)
|
||||
glm::vec2 off_s(pr, pb);
|
||||
glm::vec4 pclip = { xy(p->m_clip_uncut) + off_p, zw(p->m_clip_uncut) - off_s - off_p };
|
||||
box = rect_intersection(box, pclip);
|
||||
p = p->parent;
|
||||
p = p->m_parent;
|
||||
}
|
||||
//auto box = n->m_clip;
|
||||
//glm::ivec4 c = glm::vec4((int)box.x - 1, (int)(height / zoom - box.y - box.w) - 1, (int)box.z + 2, (int)box.w + 2) * zoom;
|
||||
|
||||
54
src/node.cpp
54
src/node.cpp
@@ -83,8 +83,8 @@ Node* Node::root()
|
||||
{
|
||||
|
||||
Node* ret = this;
|
||||
while (ret->parent)
|
||||
ret = ret->parent;
|
||||
while (ret->m_parent)
|
||||
ret = ret->m_parent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ const Node* Node::init_template(const char* id)
|
||||
void Node::add_child(Node* n)
|
||||
{
|
||||
m_children.emplace_back(n);
|
||||
n->parent = this;
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
|
||||
n->added(this);
|
||||
@@ -313,7 +313,7 @@ void Node::add_child(Node* n)
|
||||
void Node::add_child(Node* n, int index)
|
||||
{
|
||||
m_children.emplace_back(n);
|
||||
n->parent = this;
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
YGNodeInsertChild(y_node, n->y_node, index);
|
||||
n->added(this);
|
||||
@@ -323,7 +323,7 @@ void Node::add_child(Node* n, int index)
|
||||
void Node::add_child(std::shared_ptr<Node> n)
|
||||
{
|
||||
m_children.push_back(n);
|
||||
n->parent = this;
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
|
||||
n->added(this);
|
||||
@@ -333,7 +333,7 @@ void Node::add_child(std::shared_ptr<Node> n)
|
||||
void Node::add_child(std::shared_ptr<Node> n, int index)
|
||||
{
|
||||
m_children.insert(m_children.begin() + index, n);
|
||||
n->parent = this;
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
YGNodeInsertChild(y_node, n->y_node, index);
|
||||
n->added(this);
|
||||
@@ -489,7 +489,7 @@ void Node::mouse_capture()
|
||||
|
||||
void Node::mouse_release()
|
||||
{
|
||||
if (!parent)
|
||||
if (!m_parent)
|
||||
return;
|
||||
|
||||
auto& c = root()->current_mouse_capture;
|
||||
@@ -514,7 +514,7 @@ void Node::mouse_release()
|
||||
|
||||
void Node::key_capture()
|
||||
{
|
||||
if (!parent)
|
||||
if (!m_parent)
|
||||
return;
|
||||
|
||||
root()->current_key_capture = this;
|
||||
@@ -545,10 +545,10 @@ Node::Node(Node&& o)
|
||||
m_nodeID_s = std::move(o.m_nodeID_s);
|
||||
m_children = std::move(o.m_children);
|
||||
for (auto& c : m_children)
|
||||
c->parent = this;
|
||||
c->m_parent = this;
|
||||
m_nodeID = o.m_nodeID;
|
||||
m_display = o.m_display;
|
||||
parent = o.parent;
|
||||
m_parent = o.m_parent;
|
||||
y_node = o.y_node;
|
||||
m_pos = o.m_pos;
|
||||
m_size = o.m_size;
|
||||
@@ -556,7 +556,7 @@ Node::Node(Node&& o)
|
||||
m_zoom = o.m_zoom;
|
||||
m_mouse_ignore = o.m_mouse_ignore;
|
||||
o.y_node = nullptr;
|
||||
o.parent = nullptr;
|
||||
o.m_parent = nullptr;
|
||||
|
||||
m_manager = o.m_manager;
|
||||
current_mouse_capture = o.current_mouse_capture;
|
||||
@@ -748,20 +748,20 @@ void Node::SetVisibility(bool visible)
|
||||
if (m_display && !visible)
|
||||
{
|
||||
// hide
|
||||
int idx = parent->get_child_index(this);
|
||||
YGNodeRemoveChild(parent->y_node, y_node);
|
||||
int idx = m_parent->get_child_index(this);
|
||||
YGNodeRemoveChild(m_parent->y_node, y_node);
|
||||
y_placeholder = YGNodeNew();
|
||||
YGNodeInsertChild(parent->y_node, y_placeholder, idx);
|
||||
YGNodeInsertChild(m_parent->y_node, y_placeholder, idx);
|
||||
}
|
||||
else if (!m_display && visible)
|
||||
{
|
||||
int count = YGNodeGetChildCount(parent->y_node);
|
||||
int count = YGNodeGetChildCount(m_parent->y_node);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (YGNodeGetChild(parent->y_node, i) == y_placeholder)
|
||||
if (YGNodeGetChild(m_parent->y_node, i) == y_placeholder)
|
||||
{
|
||||
YGNodeRemoveChild(parent->y_node, y_placeholder);
|
||||
YGNodeInsertChild(parent->y_node, y_node, i);
|
||||
YGNodeRemoveChild(m_parent->y_node, y_placeholder);
|
||||
YGNodeInsertChild(m_parent->y_node, y_node, i);
|
||||
YGNodeFree(y_placeholder);
|
||||
y_placeholder = nullptr;
|
||||
break;
|
||||
@@ -836,25 +836,25 @@ 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;
|
||||
glm::vec2 parent_offset = parent ? parent->m_pos_offset_childred : glm::vec2(0.f);
|
||||
glm::vec2 parent_offset = m_parent ? m_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)
|
||||
if (m_parent)
|
||||
{
|
||||
// correct the padding clip
|
||||
// should not clip the padded area
|
||||
// useful to draw decorations
|
||||
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);
|
||||
float pt = YGNodeLayoutGetPadding(m_parent->y_node, YGEdgeTop);
|
||||
float pr = YGNodeLayoutGetPadding(m_parent->y_node, YGEdgeRight);
|
||||
float pb = YGNodeLayoutGetPadding(m_parent->y_node, YGEdgeBottom);
|
||||
float pl = YGNodeLayoutGetPadding(m_parent->y_node, YGEdgeLeft);
|
||||
glm::vec2 off_p(pl, pt);
|
||||
glm::vec2 off_s(pr, pb);
|
||||
glm::vec4 pclip = { xy(parent->m_clip) + off_p, zw(parent->m_clip) - (off_s + off_p)};
|
||||
glm::vec4 pclip = { xy(m_parent->m_clip) + off_p, zw(m_parent->m_clip) - (off_s + off_p)};
|
||||
m_clip_uncut = glm::vec4(m_pos - glm::vec2(1), m_size + glm::vec2(2));
|
||||
m_clip = rect_intersection(m_clip_uncut, parent->m_clip);
|
||||
m_clip = rect_intersection(m_clip_uncut, m_parent->m_clip);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1241,7 +1241,7 @@ void Node::clone_children(Node* dest) const
|
||||
{
|
||||
Node* cn = c->clone();
|
||||
dest->m_children.emplace_back(cn);
|
||||
cn->parent = dest;
|
||||
cn->m_parent = dest;
|
||||
cn->m_manager = dest->m_manager;
|
||||
cn->loaded();
|
||||
YGNodeInsertChild(dest->y_node, cn->y_node, YGNodeGetChildCount(dest->y_node));
|
||||
|
||||
@@ -96,7 +96,7 @@ class Node
|
||||
{
|
||||
friend class LayoutManager;
|
||||
public:
|
||||
Node* parent{ nullptr };
|
||||
Node* m_parent{ nullptr };
|
||||
YGNodeRef y_node{ nullptr };
|
||||
class LayoutManager* m_manager;
|
||||
uint16_t m_nodeID;
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
{
|
||||
auto* n = new T;
|
||||
n->m_manager = m_manager;
|
||||
n->parent = parent;
|
||||
n->m_parent = m_parent;
|
||||
n->init();
|
||||
n->create();
|
||||
n->loaded();
|
||||
|
||||
@@ -59,7 +59,7 @@ kEventResult NodeColorPicker::handle_event(Event* e)
|
||||
m_color_old->m_color = m_color_cur->m_color;
|
||||
}
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ kEventResult NodePanelBrush::handle_event(Event* e)
|
||||
if (!m_mouse_inside)
|
||||
{
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
@@ -480,7 +480,7 @@ kEventResult NodePanelBrushPreset::handle_event(Event* e)
|
||||
if (!m_mouse_inside)
|
||||
{
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ kEventResult NodePanelColor::handle_event(Event* e)
|
||||
if (!m_mouse_inside)
|
||||
{
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
|
||||
68
src/node_panel_floating.cpp
Normal file
68
src/node_panel_floating.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "pch.h"
|
||||
#include "node_panel_floating.h"
|
||||
|
||||
Node* NodePanelFloating::clone_instantiate() const
|
||||
{
|
||||
return new this_class;
|
||||
}
|
||||
|
||||
void NodePanelFloating::clone_finalize(Node* dest) const
|
||||
{
|
||||
parent::clone_finalize(dest);
|
||||
auto n = static_cast<this_class*>(dest);
|
||||
n->init_controls();
|
||||
}
|
||||
|
||||
void NodePanelFloating::init()
|
||||
{
|
||||
parent::init();
|
||||
init_template("tpl-panel-floating");
|
||||
init_controls();
|
||||
}
|
||||
|
||||
void NodePanelFloating::init_controls()
|
||||
{
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
SetPosition({ 0, 0 });
|
||||
m_mouse_ignore = false;
|
||||
m_flood_events = true;
|
||||
m_capture_children = true;
|
||||
m_container = find("container");
|
||||
m_button_minimize = find<NodeButton>("button-minimize");
|
||||
m_button_minimize->on_click = [this](Node*) {
|
||||
m_container->ToggleVisibility();
|
||||
};
|
||||
}
|
||||
|
||||
kEventResult NodePanelFloating::handle_event(Event* e)
|
||||
{
|
||||
parent::handle_event(e);
|
||||
kEventResult ret = kEventResult::Available;
|
||||
auto me = static_cast<MouseEvent*>(e);
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseDownL:
|
||||
m_dragging = true;
|
||||
m_drag_start_pos = m_pos;
|
||||
m_drag_start_cur = me->m_pos;
|
||||
mouse_capture();
|
||||
ret = kEventResult::Consumed;
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
if (m_dragging)
|
||||
{
|
||||
auto newpos = glm::clamp(m_drag_start_pos + me->m_pos - m_drag_start_cur, { 0, 0 }, root()->m_size - m_size);
|
||||
SetPosition(newpos);
|
||||
ret = kEventResult::Consumed;
|
||||
}
|
||||
break;
|
||||
case kEventType::MouseUpL:
|
||||
m_dragging = false;
|
||||
mouse_release();
|
||||
ret = kEventResult::Consumed;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
20
src/node_panel_floating.h
Normal file
20
src/node_panel_floating.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "node_border.h"
|
||||
#include "node_button.h"
|
||||
|
||||
class NodePanelFloating : public NodeBorder
|
||||
{
|
||||
bool m_dragging = false;
|
||||
glm::vec2 m_drag_start_pos;
|
||||
glm::vec2 m_drag_start_cur;
|
||||
NodeButton* m_button_minimize;
|
||||
public:
|
||||
Node* m_container;
|
||||
using this_class = NodePanelFloating;
|
||||
using parent = NodeBorder;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void clone_finalize(Node* dest) const override;
|
||||
virtual kEventResult handle_event(Event* e) override;
|
||||
virtual void init() override;
|
||||
void init_controls();
|
||||
};
|
||||
@@ -324,7 +324,7 @@ kEventResult NodePanelGrid::handle_event(Event* e)
|
||||
if (!m_mouse_inside)
|
||||
{
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ kEventResult NodePanelLayer::handle_event(Event* e)
|
||||
if (!m_mouse_inside)
|
||||
{
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ void NodePanelStroke::init_controls()
|
||||
on_brush_changed(this, m_brush_popup->get_texture_path(index), m_brush_popup->get_thumb_path(index));
|
||||
m_brush_thumb->set_image(m_brush_popup->get_thumb_path(index));
|
||||
//m_brush_popup->mouse_release();
|
||||
//m_brush_popup->parent->remove_child(m_brush_popup.get());
|
||||
//m_brush_popup->m_parent->remove_child(m_brush_popup.get());
|
||||
};
|
||||
};
|
||||
|
||||
@@ -696,7 +696,7 @@ kEventResult NodePanelStroke::handle_event(Event* e)
|
||||
if (!m_mouse_inside)
|
||||
{
|
||||
mouse_release();
|
||||
parent->remove_child(this);
|
||||
m_parent->remove_child(this);
|
||||
if (on_popup_close)
|
||||
on_popup_close(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user