fix manager assignment

This commit is contained in:
2019-09-26 19:49:57 +02:00
parent 13b2f6eb07
commit 755e1ff856
12 changed files with 44 additions and 43 deletions

View File

@@ -79,7 +79,7 @@ void App::cloud_browse()
// load thumbnail test // load thumbnail test
auto dialog = std::make_shared<NodeDialogCloud>(); auto dialog = std::make_shared<NodeDialogCloud>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();

View File

@@ -17,7 +17,7 @@
std::shared_ptr<NodeProgressBar> App::show_progress(const std::string& title, int total /*= 0*/) std::shared_ptr<NodeProgressBar> App::show_progress(const std::string& title, int total /*= 0*/)
{ {
auto pb = std::make_shared<NodeProgressBar>(); auto pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &layout; pb->set_manager(&layout);
pb->init(); pb->init();
pb->create(); pb->create();
pb->loaded(); pb->loaded();
@@ -32,7 +32,7 @@ std::shared_ptr<NodeProgressBar> App::show_progress(const std::string& title, in
std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const std::string& text, bool cancel_button) std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const std::string& text, bool cancel_button)
{ {
auto m = std::make_shared<NodeMessageBox>(); auto m = std::make_shared<NodeMessageBox>();
m->m_manager = &layout; m->set_manager(&layout);
m->init(); m->init();
m->create(); m->create();
m->loaded(); m->loaded();
@@ -49,7 +49,7 @@ std::shared_ptr<NodeInputBox> App::input_box(const std::string& title,
const std::string& field_name, const std::string& ok_caption /*= "Ok"*/) const std::string& field_name, const std::string& ok_caption /*= "Ok"*/)
{ {
auto m = std::make_shared<NodeInputBox>(); auto m = std::make_shared<NodeInputBox>();
m->m_manager = &layout; m->set_manager(&layout);
m->init(); m->init();
m->create(); m->create();
m->loaded(); m->loaded();
@@ -63,7 +63,7 @@ std::shared_ptr<NodeInputBox> App::input_box(const std::string& title,
void App::dialog_usermanual() void App::dialog_usermanual()
{ {
auto dialog = std::make_shared<NodeUserManual>(); auto dialog = std::make_shared<NodeUserManual>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -74,7 +74,7 @@ void App::dialog_usermanual()
void App::dialog_changelog() void App::dialog_changelog()
{ {
auto dialog = std::make_shared<NodeChangelog>(); auto dialog = std::make_shared<NodeChangelog>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -85,7 +85,7 @@ void App::dialog_changelog()
void App::dialog_about() void App::dialog_about()
{ {
auto dialog = std::make_shared<NodeAbout>(); auto dialog = std::make_shared<NodeAbout>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -97,7 +97,7 @@ void App::dialog_newdoc()
{ {
auto show_dialog = [this] { auto show_dialog = [this] {
auto dialog = std::make_shared<NodeDialogNewDoc>(); auto dialog = std::make_shared<NodeDialogNewDoc>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -146,7 +146,7 @@ void App::dialog_newdoc()
{ {
// ask confirm is file already exist // ask confirm is file already exist
auto msgbox = new NodeMessageBox(); auto msgbox = new NodeMessageBox();
msgbox->m_manager = &layout; msgbox->set_manager(&layout);
msgbox->init(); msgbox->init();
msgbox->m_title->set_text("Warning"); msgbox->m_title->set_text("Warning");
msgbox->m_message->set_text("A document with this name already exists, continue?"); msgbox->m_message->set_text("A document with this name already exists, continue?");
@@ -205,7 +205,7 @@ void App::dialog_open()
auto show_dialog = [this] { auto show_dialog = [this] {
// load thumbnail test // load thumbnail test
auto dialog = std::make_shared<NodeDialogOpen>(); auto dialog = std::make_shared<NodeDialogOpen>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -265,7 +265,7 @@ void App::dialog_browse()
auto show_dialog = [this] { auto show_dialog = [this] {
// load thumbnail test // load thumbnail test
auto dialog = std::make_shared<NodeDialogBrowse>(); auto dialog = std::make_shared<NodeDialogBrowse>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
#ifdef __IOS__ #ifdef __IOS__
dialog->search_paths = {work_path, data_path + "/Inbox"}; dialog->search_paths = {work_path, data_path + "/Inbox"};
#else #else
@@ -365,7 +365,7 @@ void App::dialog_save()
if (canvas) if (canvas)
{ {
auto dialog = std::make_shared<NodeDialogSave>(); auto dialog = std::make_shared<NodeDialogSave>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -398,7 +398,7 @@ void App::dialog_save()
{ {
// ask confirm is file already exist // ask confirm is file already exist
auto msgbox = new NodeMessageBox(); auto msgbox = new NodeMessageBox();
msgbox->m_manager = &layout; msgbox->set_manager(&layout);
msgbox->init(); msgbox->init();
msgbox->m_title->set_text("Warning"); msgbox->m_title->set_text("Warning");
msgbox->m_message->set_text(("Are you sure you want to overwrite " + name + "?").c_str()); msgbox->m_message->set_text(("Are you sure you want to overwrite " + name + "?").c_str());
@@ -505,7 +505,7 @@ void App::dialog_export_depth()
void App::dialog_resize() void App::dialog_resize()
{ {
auto dialog = std::make_shared<NodeDialogResize>(); auto dialog = std::make_shared<NodeDialogResize>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();
@@ -542,7 +542,7 @@ void App::dialog_export_cube_faces()
void App::dialog_layer_rename() void App::dialog_layer_rename()
{ {
auto dialog = std::make_shared<NodeDialogLayerRename>(); auto dialog = std::make_shared<NodeDialogLayerRename>();
dialog->m_manager = &layout; dialog->set_manager(&layout);
dialog->init(); dialog->init();
dialog->create(); dialog->create();
dialog->loaded(); dialog->loaded();

View File

@@ -73,7 +73,7 @@ void App::init_toolbar_main()
{ {
button->on_click = [this](Node*) { button->on_click = [this](Node*) {
msgbox = new NodeMessageBox(); msgbox = new NodeMessageBox();
msgbox->m_manager = &layout; msgbox->set_manager(&layout);
msgbox->init(); msgbox->init();
layout[main_id]->add_child(msgbox); layout[main_id]->add_child(msgbox);
}; };
@@ -82,7 +82,7 @@ void App::init_toolbar_main()
{ {
button->on_click = [this](Node*) { button->on_click = [this](Node*) {
settings = new NodeSettings(); settings = new NodeSettings();
settings->m_manager = &layout; settings->set_manager(&layout);
settings->init(); settings->init();
layout[main_id]->add_child(settings); layout[main_id]->add_child(settings);
}; };
@@ -93,7 +93,7 @@ template <class T> std::shared_ptr<T> create_panel(LayoutManager& manager)
{ {
std::shared_ptr<T> ret; std::shared_ptr<T> ret;
ret = std::make_shared<T>(); ret = std::make_shared<T>();
ret->m_manager = &manager; ret->set_manager(&manager);
ret->init(); ret->init();
ret->create(); ret->create();
ret->loaded(); ret->loaded();
@@ -1405,13 +1405,12 @@ void App::initLayout()
layout.load("data/layout.xml"); layout.load("data/layout.xml");
LOG("initializing layout completed"); LOG("initializing layout completed");
//LOG("initializing layout designer xml"); LOG("initializing layout designer xml");
//layout_designer.on_loaded = [&](bool reloaded) { layout_designer.on_loaded = [&](bool reloaded) {
// if (!reloaded) layout_designer.create();
// layout_designer.create(); layout_designer[main_id]->add_child(layout_designer.instantiate("usermanual"));
// layout_designer[main_id]->add_child(layout_designer.instantiate("changelog")); };
//}; //layout_designer.load("data/dialogs/usermanual.xml");
//layout_designer.load("data/dialogs/changelog.xml");
} }
void App::set_ui_scale(float scale) void App::set_ui_scale(float scale)

View File

@@ -2222,7 +2222,7 @@ bool Canvas::project_open_thread(std::string file_path)
if (App::I->layout.m_loaded) if (App::I->layout.m_loaded)
{ {
pb = std::make_shared<NodeProgressBar>(); pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I->layout; pb->set_manager(&App::I->layout);
pb->init(); pb->init();
pb->create(); pb->create();
pb->loaded(); pb->loaded();

View File

@@ -90,7 +90,7 @@ bool LayoutManager::load(const char* path)
node.reset(new Node()); node.reset(new Node());
break; break;
} }
node->m_manager = this; node->set_manager(this);
// try to copy the old size values // try to copy the old size values
if (old.count(id)) if (old.count(id))
{ {

View File

@@ -340,21 +340,22 @@ void Node::removed(Node* parent)
const Node* Node::init_template(const char* id) const Node* Node::init_template(const char* id)
{ {
Node* m_template = nullptr; Node* t = nullptr;
App::I->ui_task([&] App::I->ui_task([&]
{ {
auto hid = const_hash(id); auto hid = const_hash(id);
Node* top = m_manager->get(hid); Node* top = m_manager->get(hid);
m_template = static_cast<Node*>(top->m_children[0].get()); t = static_cast<Node*>(top->m_children[0].get());
for (auto& c : m_template->m_children) t->set_manager(m_manager);
for (auto& c : t->m_children)
{ {
auto node = c->clone(); auto node = c->clone();
add_child(node); add_child(node);
} }
YGNodeCopyStyle(y_node, m_template->y_node); YGNodeCopyStyle(y_node, t->y_node);
m_template->clone_copy(this); t->clone_copy(this);
}); });
return m_template; return t;
} }
bool Node::init_template_file(const std::string& path, const std::string& id) bool Node::init_template_file(const std::string& path, const std::string& id)
@@ -366,6 +367,7 @@ bool Node::init_template_file(const std::string& path, const std::string& id)
if (m.load(path.c_str())) if (m.load(path.c_str()))
{ {
auto t = m.get_ref(id.c_str())->m_children[0]; auto t = m.get_ref(id.c_str())->m_children[0];
t->set_manager(m_manager);
for (auto& c : t->m_children) for (auto& c : t->m_children)
add_child(c->clone()); add_child(c->clone());
YGNodeCopyStyle(y_node, t->y_node); YGNodeCopyStyle(y_node, t->y_node);

View File

@@ -103,8 +103,8 @@ class Node : public std::enable_shared_from_this<Node>
public: public:
Node* m_parent{ nullptr }; Node* m_parent{ nullptr };
YGNodeRef y_node{ nullptr }; YGNodeRef y_node{ nullptr };
class LayoutManager* m_manager; class LayoutManager* m_manager = nullptr;
uint16_t m_nodeID; uint16_t m_nodeID = 0;
std::string m_nodeID_s; std::string m_nodeID_s;
std::vector<std::shared_ptr<Node>> m_children; std::vector<std::shared_ptr<Node>> m_children;
std::shared_ptr<Node> current_mouse_capture = nullptr; std::shared_ptr<Node> current_mouse_capture = nullptr;

View File

@@ -38,7 +38,7 @@ void NodeDialogBrowse::init_controls()
return; return;
auto msgbox = new NodeMessageBox(); auto msgbox = new NodeMessageBox();
msgbox->m_manager = m_manager; msgbox->set_manager(m_manager);
msgbox->init(); msgbox->init();
msgbox->m_title->set_text("Delete Project"); msgbox->m_title->set_text("Delete Project");
msgbox->m_message->set_text(("Are you sure you want to delete " + current->m_file_name + "?").c_str()); msgbox->m_message->set_text(("Are you sure you want to delete " + current->m_file_name + "?").c_str());
@@ -134,7 +134,7 @@ void NodeDialogBrowse::init_list()
continue; continue;
auto node = new NodeDialogBrowseItem; auto node = new NodeDialogBrowseItem;
node->m_manager = m_manager; node->set_manager(m_manager);
node->init(); node->init();
node->m_text->set_text(f_name.substr(0, f_name.length() - strlen(".ppi")).c_str()); node->m_text->set_text(f_name.substr(0, f_name.length() - strlen(".ppi")).c_str());
node->m_path = f_path; node->m_path = f_path;

View File

@@ -88,7 +88,7 @@ void NodeDialogCloud::load_thumbs_thread()
for (const auto& n : names) for (const auto& n : names)
{ {
auto node = new NodeDialogCloudItem; auto node = new NodeDialogCloudItem;
node->m_manager = m_manager; node->set_manager(m_manager);
node->init(); node->init();
node->m_text->set_text(n.c_str()); node->m_text->set_text(n.c_str());
node->m_path = App::I->work_path + "/" + n; node->m_path = App::I->work_path + "/" + n;

View File

@@ -40,7 +40,7 @@ void NodeDialogOpen::init_controls()
return; return;
auto msgbox = new NodeMessageBox(); auto msgbox = new NodeMessageBox();
msgbox->m_manager = m_manager; msgbox->set_manager(m_manager);
msgbox->init(); msgbox->init();
msgbox->m_title->set_text("Delete Project"); msgbox->m_title->set_text("Delete Project");
msgbox->m_message->set_text(("Are you sure you want to delete " + current->m_file_name + "?").c_str()); msgbox->m_message->set_text(("Are you sure you want to delete " + current->m_file_name + "?").c_str());
@@ -73,7 +73,7 @@ void NodeDialogOpen::init_controls()
for (const auto& n : names) for (const auto& n : names)
{ {
auto node = new NodeDialogOpenItem; auto node = new NodeDialogOpenItem;
node->m_manager = m_manager; node->set_manager(m_manager);
node->init(); node->init();
node->m_text->set_text(n.c_str()); node->m_text->set_text(n.c_str());
node->m_path = App::I->work_path + "/" + n; node->m_path = App::I->work_path + "/" + n;

View File

@@ -108,7 +108,7 @@ void NodePanelQuick::reset_state(bool fire_event /*= false*/)
void NodePanelQuick::init_controls() void NodePanelQuick::init_controls()
{ {
m_picker = std::make_shared<NodeColorPicker>(); m_picker = std::make_shared<NodeColorPicker>();
m_picker->m_manager = m_manager; m_picker->set_manager(m_manager);
m_picker->init(); m_picker->init();
m_picker->create(); m_picker->create();
m_picker->loaded(); m_picker->loaded();

View File

@@ -121,7 +121,7 @@ void NodePanelStroke::init_fold(const std::string& name)
void NodePanelStroke::init_controls() void NodePanelStroke::init_controls()
{ {
m_brush_popup = std::make_shared<NodePanelBrush>(); m_brush_popup = std::make_shared<NodePanelBrush>();
m_brush_popup->m_manager = m_manager; m_brush_popup->set_manager(m_manager);
m_brush_popup->m_dir_name = "brushes"; m_brush_popup->m_dir_name = "brushes";
m_brush_popup->init(); m_brush_popup->init();
m_brush_popup->create(); m_brush_popup->create();
@@ -133,7 +133,7 @@ void NodePanelStroke::init_controls()
m_brush_popup->m_capture_children = false; m_brush_popup->m_capture_children = false;
m_pattern_popup = std::make_shared<NodePanelBrush>(); m_pattern_popup = std::make_shared<NodePanelBrush>();
m_pattern_popup->m_manager = m_manager; m_pattern_popup->set_manager(m_manager);
m_pattern_popup->m_dir_name = "patterns"; m_pattern_popup->m_dir_name = "patterns";
m_pattern_popup->init(); m_pattern_popup->init();
m_pattern_popup->create(); m_pattern_popup->create();