This commit is contained in:
2019-08-28 10:00:35 +02:00
parent c1bd377ee8
commit 62a95c1a0f
13 changed files with 122 additions and 63 deletions

View File

@@ -693,7 +693,7 @@
<slider-h id="grid-ground-offset" value="0.25"/>
</node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-ground-resolution" width="100%" height="30" combo-list="0.1,0.5,1,2,4,8" default="2"/>
<combobox id="grid-ground-resolution" width="100%" height="28" combo-list="0.1,0.5,1,2,4,8" default="2"/>
</node>
</node>
</node>
@@ -731,7 +731,7 @@
</node>
<node dir="col" align="center" grow="1" width="1" flood-events="1" color=".3" >
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-shading" width="100%" height="30" combo-list="Transparent,Flat,Solid,Textured" default="0"/>
<combobox id="grid-heightmap-shading" width="100%" height="28" combo-list="Transparent,Flat,Solid,Textured" default="0"/>
</node>
<node height="20" pad="1" width="100%" margin="5 0 0 0">
<slider-h id="grid-heightmap-wireframe" value="1.0"/>
@@ -753,10 +753,10 @@
<slider-h id="grid-heightmap-radius" value="0.25"/>
</node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-samples" width="100%" height="30" combo-list="1,4,8,16,32,64,128" default="2"/>
<combobox id="grid-heightmap-samples" width="100%" height="28" combo-list="1,4,8,16,32,64,128" default="2"/>
</node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-texres" width="100%" height="30" combo-list="256,512,1024,2048,4096" default="1"/>
<combobox id="grid-heightmap-texres" width="100%" height="28" combo-list="256,512,1024,2048,4096" default="1"/>
</node>
</node>
</node>
@@ -771,7 +771,7 @@
<!-- MESSAGE BOX -->
<layout id="message-box">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
<border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text id="title" text="Just a test message"></text>
@@ -789,8 +789,8 @@
<!-- PROGRESS BAR -->
<layout id="progress-bar">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
<border id="body" thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text id="title" text="Just a test message"></text>
</border>

View File

@@ -354,8 +354,11 @@ void App::init_sidebar()
if (grid->m_parent)
{
if (auto fp = dynamic_cast<NodePanelFloating*>(grid->m_parent->m_parent))
{
grid->remove_from_parent();
fp->destroy();
}
}
layout[main_id]->add_child(grid);
auto tick = layout[main_id]->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
@@ -505,7 +508,7 @@ void App::init_menu_file()
{
menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("file-menu")]->m_children[0]->clone();
auto popup = layout[const_hash("file-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
@@ -610,7 +613,7 @@ void App::init_menu_file()
if (auto b = popup->find<NodeButtonCustom>("file-export-tick"))
b->on_click = [this, b, popup](Node*) {
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
auto subpopup = (NodePopupMenu*)layout[const_hash("file-submenu-export")]->m_children[0]->clone();
auto subpopup = layout[const_hash("file-submenu-export")]->m_children[0]->clone<NodePopupMenu>();
subpopup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - subpopup->m_size.x + b->m_size.x;
@@ -685,7 +688,7 @@ void App::init_menu_edit()
{
menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("edit-menu")]->m_children[0]->clone();
auto popup = layout[const_hash("edit-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
@@ -709,7 +712,7 @@ void App::init_menu_tools()
{
menu_exp->on_click = [this, menu_exp, main](Node*) {
glm::vec2 pos = menu_exp->m_pos + glm::vec2(0, menu_exp->m_size.y);
auto popup_exp = (NodePopupMenu*)layout[const_hash("tools-menu")]->m_children[0]->clone();
auto popup_exp = layout[const_hash("tools-menu")]->m_children[0]->clone<NodePopupMenu>();
popup_exp->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup_exp->m_size.x + menu_exp->m_size.x;
@@ -727,7 +730,7 @@ void App::init_menu_tools()
if (auto menu_time = popup_exp->find<NodePopupMenu>("tools-timelapse"))
{
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
auto popup_time = (NodePopupMenu*)layout[const_hash("timelapse-menu")]->m_children[0]->clone();
auto popup_time = layout[const_hash("timelapse-menu")]->m_children[0]->clone<NodePopupMenu>();
popup_time->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup_time->m_size.x + b->m_size.x;
@@ -773,7 +776,7 @@ void App::init_menu_tools()
if (auto menu_time = popup_exp->find<NodePopupMenu>("tools-panels"))
{
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
auto popup_time = (NodePopupMenu*)layout[const_hash("panels-menu")]->m_children[0]->clone();
auto popup_time = layout[const_hash("panels-menu")]->m_children[0]->clone<NodePopupMenu>();
popup_time->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup_time->m_size.x + b->m_size.x;
@@ -1039,7 +1042,7 @@ void App::init_menu_about()
{
menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("about-menu")]->m_children[0]->clone();
auto popup = layout[const_hash("about-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
@@ -1160,7 +1163,7 @@ void App::init_menu_layer()
{
menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("layers-menu")]->m_children[0]->clone();
auto popup = layout[const_hash("layers-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;

View File

@@ -58,13 +58,22 @@ void Node::watch(std::function<bool(Node*)> observer)
void Node::destroy()
{
App::I->ui_task([&]
{
m_destroyed = true;
mouse_release();
key_release();
remove_all_children();
remove_from_parent();
});
// for (auto& c : m_children)
// c->destroy();
for (auto p = m_parent; p; p = p->m_parent)
if (p->child_mouse_focus.get() == this)
p->child_mouse_focus = nullptr;
//App::I->ui_task([&]
//{
// auto cp = m_children;
// for (auto& c : cp)
// c->destroy();
// remove_all_children();
// remove_from_parent();
//});
}
Node* Node::root()
@@ -79,6 +88,9 @@ kEventResult Node::on_event(Event* e)
{
kEventResult ret = kEventResult::Available;
if (m_destroyed)
return ret;
if (current_mouse_capture && current_mouse_capture.get() != this)
{
if (e->m_cat == kEventCategory::MouseEvent &&
@@ -134,7 +146,7 @@ kEventResult Node::on_event(Event* e)
if (e->m_cat == kEventCategory::MouseEvent && child_mouse_focus.get() != it->get())
{
MouseEvent* me = static_cast<MouseEvent*>(e);
if (child_mouse_focus)
if (child_mouse_focus && !child_mouse_focus->m_destroyed)
{
MouseEvent e2 = *me;
e2.m_type = kEventType::MouseUnfocus;
@@ -144,9 +156,16 @@ kEventResult Node::on_event(Event* e)
MouseEvent e2 = *me;
e2.m_type = kEventType::MouseFocus;
(*it)->handle_event(&e2);
if (!(*it)->m_destroyed)
{
child_mouse_focus = *it;
child_mouse_focus->m_mouse_focus = true;
}
//else
//{
// child_mouse_focus = nullptr;
//}
}
ret = kEventResult::Consumed;
break;
}
@@ -295,7 +314,9 @@ void Node::added(Node* parent)
void Node::removed(Node* parent)
{
for (auto p = m_parent; p; p = p->m_parent)
if (p->child_mouse_focus.get() == this)
p->child_mouse_focus = nullptr;
}
const Node* Node::init_template(const char* id)
@@ -329,6 +350,7 @@ void Node::add_child(Node* n)
m_children.emplace_back(n);
n->m_parent = this;
n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->added(this);
on_child_added(n);
@@ -344,6 +366,7 @@ void Node::add_child(Node* n, int index)
m_children.emplace_back(n);
n->m_parent = this;
n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, index);
n->added(this);
on_child_added(n);
@@ -359,6 +382,7 @@ void Node::add_child(std::shared_ptr<Node> n)
m_children.push_back(n);
n->m_parent = this;
n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->added(this);
on_child_added(n.get());
@@ -374,6 +398,7 @@ void Node::add_child(std::shared_ptr<Node> n, int index)
m_children.insert(m_children.begin() + index, n);
n->m_parent = this;
n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, index);
n->added(this);
on_child_added(n.get());
@@ -663,6 +688,7 @@ Node::Node(Node&& o)
m_pos_offset_childred = o.m_pos_offset_childred;
m_clip_uncut = o.m_clip_uncut;
m_destroyed = o.m_destroyed;
}
Node::~Node()
@@ -1015,6 +1041,9 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj, float
for (auto& c : m_children)
c->update_internal(m_pos, proj, zoom);
m_children.erase(std::remove_if(m_children.begin(), m_children.end(),
[](const auto& n) { return n->m_destroyed; }), m_children.end());
}
void Node::tick(float dt)
@@ -1320,15 +1349,6 @@ void Node::draw()
}
Node* Node::clone()
{
Node* n = clone_instantiate();
clone_copy(n);
clone_children(n);
clone_finalize(n);
return n;
}
Node* Node::clone_instantiate() const
{
return new Node();
@@ -1363,14 +1383,16 @@ void Node::clone_copy(Node* dest) const
dest->m_pos_offset = m_pos_offset;
dest->m_pos_offset_childred = m_pos_offset_childred;
dest->m_clip_uncut = m_clip_uncut;
dest->m_destroyed = m_destroyed;
}
void Node::clone_children(Node* dest) const
{
for (auto& c : m_children)
{
Node* cn = c->clone();
dest->m_children.emplace_back(cn);
std::shared_ptr<Node> cn = c->clone();
dest->m_children.push_back(cn);
cn->m_parent = dest;
cn->m_manager = dest->m_manager;
cn->loaded();

View File

@@ -135,6 +135,8 @@ public:
// it's actually rendering
bool m_on_screen = false;
bool m_destroyed = false;
Node(const Node&) = delete;
Node& operator=(const Node&) = delete;
Node&& operator=(Node&& o);
@@ -194,7 +196,6 @@ public:
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr);
void load_internal(const tinyxml2::XMLElement* x_node);
virtual void draw();
Node* clone();
virtual Node* clone_instantiate() const;
virtual void clone_copy(Node* dest) const;
virtual void clone_children(Node* dest) const;
@@ -203,6 +204,16 @@ public:
virtual void destroy();
Node* root();
template<class T = Node> std::shared_ptr<T> clone()
{
std::shared_ptr<T> n = std::shared_ptr<T>((T*)clone_instantiate());
clone_copy(n.get());
clone_children(n.get());
clone_finalize(n.get());
return n;
}
template<class T = Node> T* find(const char* ids)
{
uint16_t id = const_hash(ids);

View File

@@ -8,19 +8,29 @@ Node* NodeAbout::clone_instantiate() const
return new NodeAbout();
}
void NodeAbout::clone_finalize(Node* dest) const
{
NodeAbout* n = static_cast<NodeAbout*>(dest);
n->init_controls();
}
void NodeAbout::init()
{
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("about")]->m_children[0]->clone();
add_child(m_template);
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
init_template("about");
init_controls();
}
kEventResult NodeAbout::handle_event(Event* e)
{
return kEventResult::Consumed;
}
void NodeAbout::init_controls()
{
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
btn_ok = find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
}

View File

@@ -4,10 +4,11 @@
class NodeAbout : public Node
{
Node* m_template;
NodeButton* btn_ok;
public:
virtual Node* clone_instantiate() const override;
virtual void init() override;
virtual kEventResult handle_event(Event* e) override;
virtual void clone_finalize(Node* dest) const override;
void init_controls();
};

View File

@@ -10,13 +10,13 @@ Node* NodeChangelog::clone_instantiate() const
void NodeChangelog::init()
{
init_template("changelog");
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("changelog")]->m_children[0]->clone();
add_child(m_template);
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok = find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
}

View File

@@ -45,6 +45,7 @@ void NodeDialogCloud::loaded()
void NodeDialogCloud::removed(Node* parent)
{
NodeBorder::removed(parent);
closed = true;
}

View File

@@ -10,17 +10,17 @@ Node* NodeMessageBox::clone_instantiate() const
void NodeMessageBox::init()
{
init_template("message-box");
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("message-box")]->m_children[0]->clone();
add_child(m_template);
m_title = m_template->find<NodeText>("title");
m_message = m_template->find<NodeText>("message");
btn_ok = m_template->find<NodeButton>("btn-ok");
m_title = find<NodeText>("title");
m_message = find<NodeText>("message");
btn_ok = find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
btn_cancel = m_template->find<NodeButton>("btn-cancel");
btn_cancel = find<NodeButton>("btn-cancel");
on_submit = btn_cancel->on_click = [&](Node*) { destroy(); };
m_capture_children = false; // don't capture children events on mouse_capture
}

View File

@@ -19,6 +19,7 @@ void NodeProgressBar::init()
btn_cancel = find<NodeButton>("btn-cancel");
btn_cancel->on_click = [&](Node*) { destroy(); };
m_progress = find<NodeBorder>("progress");
m_body = find<NodeBorder>("body");
m_progress->SetWidthP(0);
}
@@ -34,3 +35,9 @@ void NodeProgressBar::set_progress(float p) noexcept
{
m_progress->SetWidthP(p * 100.f);
}
void NodeProgressBar::added(Node* parent)
{
NodeBorder::added(parent);
m_body->mouse_capture();
}

View File

@@ -11,6 +11,7 @@ public:
NodeButton* btn_cancel;
NodeText* m_title;
NodeBorder* m_progress;
NodeBorder* m_body;
int m_total = 0;
int m_count = 0;
virtual Node* clone_instantiate() const override;
@@ -18,4 +19,5 @@ public:
void increment() noexcept;
// set progress where p [0, 1]
void set_progress(float p) noexcept;
virtual void added(Node* parent) override;
};

View File

@@ -10,13 +10,13 @@ Node* NodeSettings::clone_instantiate() const
void NodeSettings::init()
{
init_template("settings");
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("settings")]->m_children[0]->clone();
add_child(m_template);
btnOk = m_template->find<NodeButton>("btn-ok");
btnOk = find<NodeButton>("btn-ok");
btnOk->on_click = [&](Node*) { destroy(); };
}

View File

@@ -10,14 +10,16 @@ Node* NodeUserManual::clone_instantiate() const
void NodeUserManual::init()
{
init_template("usermanual");
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("usermanual")]->m_children[0]->clone();
add_child(m_template);
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
btn_ok = find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) {
destroy();
};
}
kEventResult NodeUserManual::handle_event(Event* e)