From 8b179260fb4d56b286706d19bfe5d53fe233c4d5 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 26 Sep 2019 17:48:38 +0200 Subject: [PATCH] fix layout designer --- src/app_events.cpp | 2 ++ src/layout.cpp | 1 + src/node.cpp | 14 ++++++++++---- src/node.h | 1 + src/node_dialog_export_ppbr.cpp | 3 ++- src/node_image.cpp | 4 ++-- src/node_input_box.cpp | 7 +++++-- src/node_message_box.cpp | 3 ++- src/node_progress_bar.cpp | 3 ++- 9 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/app_events.cpp b/src/app_events.cpp index d7f9688..4f27323 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -67,6 +67,8 @@ void App::crash_test() void App::tick(float dt) { + if (auto* main = layout_designer[main_id]) + main->tick(dt); if (auto* main = layout[main_id]) main->tick(dt); } diff --git a/src/layout.cpp b/src/layout.cpp index 0bcb361..af2c364 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -16,6 +16,7 @@ void LayoutManager::unload() void LayoutManager::create() { m_layouts[const_hash("main")] = std::make_unique(); + m_layouts[const_hash("main")]->m_manager = this; } bool LayoutManager::load(const char* path) diff --git a/src/node.cpp b/src/node.cpp index 8e389e2..480380e 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -96,6 +96,12 @@ void Node::set_manager(LayoutManager* manager) c->set_manager(manager); } +bool Node::added_to_root() +{ + auto r = root(); + return r == m_manager->get(App::I->main_id); +} + kEventResult Node::on_event(Event* e) { kEventResult ret = kEventResult::Available; @@ -599,7 +605,7 @@ bool Node::is_child(Node* o) const void Node::mouse_capture() { - auto root = App::I->layout.get_ref("main"); + auto root = m_manager->get_ref("main"); if (!root) return; auto& c = root->current_mouse_capture; @@ -644,7 +650,7 @@ void Node::mouse_release() if (!m_parent) return; - auto root = App::I->layout.get_ref("main"); + auto root = m_manager->get_ref("main"); if (!root) return; auto& c = root->current_mouse_capture; @@ -673,7 +679,7 @@ void Node::key_capture() if (!m_parent) return; - auto root = App::I->layout.get_ref("main"); + auto root = m_manager->get_ref("main"); if (!root) return; root->current_key_capture = shared_from_this(); @@ -682,7 +688,7 @@ void Node::key_capture() void Node::key_release() { - auto root = App::I->layout.get_ref("main"); + auto root = m_manager->get_ref("main"); if (!root) return; if (root->current_key_capture.get() == this) diff --git a/src/node.h b/src/node.h index adfb8e0..1201216 100644 --- a/src/node.h +++ b/src/node.h @@ -208,6 +208,7 @@ public: virtual void destroy(); Node* root(); void set_manager(LayoutManager* manager); + bool added_to_root(); template std::shared_ptr clone() { diff --git a/src/node_dialog_export_ppbr.cpp b/src/node_dialog_export_ppbr.cpp index ee23523..8c7271e 100644 --- a/src/node_dialog_export_ppbr.cpp +++ b/src/node_dialog_export_ppbr.cpp @@ -82,5 +82,6 @@ void NodeDialogExportPPBR::open_header() void NodeDialogExportPPBR::added(Node* parent) { NodeBorder::added(parent); - mouse_capture(); + if (added_to_root()) + mouse_capture(); } diff --git a/src/node_image.cpp b/src/node_image.cpp index 2ca3b1b..9e7f491 100644 --- a/src/node_image.cpp +++ b/src/node_image.cpp @@ -152,7 +152,7 @@ void NodeImage::load_url(const std::string& url) m_remote_texture->create_mipmaps(); delete rgba; if (m_autosize) - SetAspectRatio(w / h); + SetAspectRatio((float)w / (float)h); } m_remote_asset.reset(); } @@ -162,6 +162,6 @@ void NodeImage::load_url(const std::string& url) void NodeImage::added(Node* parent) { Node::added(parent); - if (!m_url.empty() && root() == App::I->layout.get(App::I->main_id)) + if (!m_url.empty() && added_to_root()) load_url(m_url); } diff --git a/src/node_input_box.cpp b/src/node_input_box.cpp index b0c6cfb..f501cb5 100644 --- a/src/node_input_box.cpp +++ b/src/node_input_box.cpp @@ -52,6 +52,9 @@ kEventResult NodeInputBox::handle_event(Event* e) void NodeInputBox::added(Node* parent) { Node::added(parent); - mouse_capture(); - m_field_text->key_capture(); + if (added_to_root()) + { + mouse_capture(); + m_field_text->key_capture(); + } } diff --git a/src/node_message_box.cpp b/src/node_message_box.cpp index 6203b03..a185e90 100644 --- a/src/node_message_box.cpp +++ b/src/node_message_box.cpp @@ -51,5 +51,6 @@ kEventResult NodeMessageBox::handle_event(Event* e) void NodeMessageBox::added(Node* parent) { Node::added(parent); - mouse_capture(); + if (added_to_root()) + mouse_capture(); } diff --git a/src/node_progress_bar.cpp b/src/node_progress_bar.cpp index 3e49ced..11ad038 100644 --- a/src/node_progress_bar.cpp +++ b/src/node_progress_bar.cpp @@ -37,5 +37,6 @@ void NodeProgressBar::set_progress(float p) noexcept void NodeProgressBar::added(Node* parent) { NodeBorder::added(parent); - mouse_capture(); + if (added_to_root()) + mouse_capture(); }