diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp index 607ee9e..cfc3a79 100644 --- a/src/node_panel_brush.cpp +++ b/src/node_panel_brush.cpp @@ -183,43 +183,7 @@ void NodePanelBrush::init() } if (m_container->m_children.empty() && !m_dir_name.empty()) - { - auto icons = Asset::list_files("data/" + m_dir_name, ".*\\.png$"); - for (auto& i : icons) - { - std::string path = "data/" + m_dir_name + "/thumbs/" + i; - std::string path_hi = "data/" + m_dir_name + "/" + i; - NodeButtonBrush* brush = new NodeButtonBrush; - m_container->add_child(brush); - brush->init(); - brush->create(); - brush->loaded(); - brush->set_icon(path.c_str()); - brush->thumb_path = path; - brush->high_path = path_hi; - brush->brush_name = i; - brush->m_user_brush = false; // system brush, cannot be deleted from file - brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1); - } - - auto custom_icons = Asset::list_files(App::I->data_path + "/" + m_dir_name, ".*\\.png$"); - for (auto& i : custom_icons) - { - std::string path_thumb = App::I->data_path + "/" + m_dir_name + "/thumbs/" + i; - std::string path_high = App::I->data_path + "/" + m_dir_name + "/" + i; - NodeButtonBrush* brush = new NodeButtonBrush; - m_container->add_child(brush); - brush->init(); - brush->create(); - brush->loaded(); - brush->set_icon(path_thumb.c_str()); - brush->thumb_path = path_thumb; - brush->high_path = path_high; - brush->brush_name = i; - brush->m_user_brush = true; - brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1); - } - } + scan(); save(); } @@ -363,6 +327,52 @@ void NodePanelBrush::clear() m_container->remove_all_children(); } +void NodePanelBrush::scan() +{ + auto icons = Asset::list_files("data/" + m_dir_name, ".*\\.png$"); + for (auto& i : icons) + { + std::string path = "data/" + m_dir_name + "/thumbs/" + i; + std::string path_hi = "data/" + m_dir_name + "/" + i; + NodeButtonBrush* brush = new NodeButtonBrush; + m_container->add_child(brush); + brush->init(); + brush->create(); + brush->loaded(); + brush->set_icon(path.c_str()); + brush->thumb_path = path; + brush->high_path = path_hi; + brush->brush_name = i; + brush->m_user_brush = false; // system brush, cannot be deleted from file + brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1); + } + + auto custom_icons = Asset::list_files(App::I->data_path + "/" + m_dir_name, ".*\\.png$"); + for (auto& i : custom_icons) + { + std::string path_thumb = App::I->data_path + "/" + m_dir_name + "/thumbs/" + i; + std::string path_high = App::I->data_path + "/" + m_dir_name + "/" + i; + NodeButtonBrush* brush = new NodeButtonBrush; + m_container->add_child(brush); + brush->init(); + brush->create(); + brush->loaded(); + brush->set_icon(path_thumb.c_str()); + brush->thumb_path = path_thumb; + brush->high_path = path_high; + brush->brush_name = i; + brush->m_user_brush = true; + brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1); + } +} + +void NodePanelBrush::reload() +{ + clear(); + scan(); + save(); +} + void NodePanelBrush::added(Node* parent) { m_interacted = false; @@ -482,7 +492,7 @@ void NodePanelBrushPreset::init() }; m_btn_menu = find("btn-menu"); m_btn_menu->on_click = [this](Node* b) { - auto popup = m_manager->instantiate("tpl-brush-popup"); + auto popup = add_child_file("data/dialogs/panel-brushes.xml", "tpl-brush-popup"); popup->SetPosition(b->m_pos.x + b->m_size.x, b->m_pos.y); root()->add_child(popup); root()->update(); @@ -938,6 +948,8 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path) } save(); + App::I->stroke->m_brush_popup->reload(); + pb->destroy(); return true; @@ -1015,6 +1027,7 @@ bool NodePanelBrushPreset::import_abr(const std::string& path) }); save(); + App::I->stroke->m_brush_popup->reload(); pb->destroy(); return true; diff --git a/src/node_panel_brush.h b/src/node_panel_brush.h index fbaa0ba..e6707b4 100644 --- a/src/node_panel_brush.h +++ b/src/node_panel_brush.h @@ -54,6 +54,8 @@ public: bool save(); bool restore(); void clear(); + void scan(); + void reload(); }; // -----------------------------------------------------------------------