diff --git a/engine/app_layout.cpp b/engine/app_layout.cpp index 295debe..303bf23 100644 --- a/engine/app_layout.cpp +++ b/engine/app_layout.cpp @@ -273,6 +273,7 @@ void App::initLayout() for (auto& i : canvas->m_canvas->m_order) layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str()); open_dialog->destroy(); + ActionManager::clear(); }; } }; diff --git a/engine/asset.cpp b/engine/asset.cpp index 54d8fa8..826358c 100644 --- a/engine/asset.cpp +++ b/engine/asset.cpp @@ -10,6 +10,73 @@ AAssetManager* Asset::m_am; #endif +std::vector Asset::list_files(std::string folder, bool is_asset, const std::string& filter_regex) +{ + std::vector names; +#ifdef _WIN32 + WIN32_FIND_DATAA fd; + HANDLE hFind = ::FindFirstFileA((folder + "*").c_str(), &fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + // read all (real) files in current folder + // , delete '!' read other 2 default folder . and .. + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + names.push_back(fd.cFileName); + } + } while (::FindNextFileA(hFind, &fd)); + ::FindClose(hFind); + } +#elif __ANDROID__ + if (is_asset) + { + AAssetDir* dir = AAssetManager_openDir(Asset::m_am, folder.c_str()); + while (const char* name = AAssetDir_getNextFileName(dir)) + { + //LOG("asset: %s", name); + names.push_back(name); + } + AAssetDir_close(dir); + } + else + { + + } +#else + if (is_asset) + { + NSString* bundle_path = [[NSBundle mainBundle] resourcePath]; + std::string base = [bundle_path cStringUsingEncoding : 1]; + std::string abs_path = base + "/" + folder; + } + + DIR *dp; + struct dirent *ep; + dp = opendir(abs_path.c_str()); + + if (dp != NULL) + { + while ((ep = readdir(dp))) + if (ep->d_type != DT_DIR) + names.push_back(ep->d_name); + closedir(dp); + } + else + LOG("Couldn't open the directory: %s", folder.c_str()); +#endif + + if (!filter_regex.empty()) + { + std::regex r(filter_regex); + names.erase(std::remove_if(names.begin(), names.end(), + [&r](const std::string& s) { return !std::regex_match(s, r); }), names.end()); + } + + return names; +} + bool Asset::open(const char* path) { LOG("Asset::open %s", path); diff --git a/engine/asset.h b/engine/asset.h index 269707d..79a50ff 100644 --- a/engine/asset.h +++ b/engine/asset.h @@ -7,6 +7,8 @@ public: static AAssetManager* m_am; AAsset* m_asset = nullptr; #endif + static std::vector Asset::list_files(std::string folder, bool is_asset, const std::string& filter_regex); + std::string m_current_path; FILE* m_fp = nullptr; int m_len = 0; diff --git a/engine/node_panel_brush.cpp b/engine/node_panel_brush.cpp index 08793df..fc5d1e4 100644 --- a/engine/node_panel_brush.cpp +++ b/engine/node_panel_brush.cpp @@ -44,7 +44,8 @@ void NodePanelBrush::init() { init_template("tpl-panel-brushes"); //m_layers_container = find("layers-container"); - static auto icons = FindAllBrushes("data/Icons/"); + static auto icons = Asset::list_files("data/Icons/", true, ".*\\.png$"); + if ((m_container = find("brushes"))) { int count = 0; @@ -76,54 +77,6 @@ void NodePanelBrush::handle_click(Node* target) on_brush_changed(this, m_current->m_brushID); } -std::vector NodePanelBrush::FindAllBrushes(std::string folder) -{ - std::vector names; - std::string search_path = folder + "*.png"; -#ifdef _WIN32 - WIN32_FIND_DATAA fd; - HANDLE hFind = ::FindFirstFileA(search_path.c_str(), &fd); - if (hFind != INVALID_HANDLE_VALUE) { - do { - // read all (real) files in current folder - // , delete '!' read other 2 default folder . and .. - if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - names.push_back(fd.cFileName); - } - } while (::FindNextFileA(hFind, &fd)); - ::FindClose(hFind); - } -#elif __ANDROID__ - //LOG("listing brushes"); - AAssetDir* dir = AAssetManager_openDir(Asset::m_am, "data/Icons"); - while (const char* name = AAssetDir_getNextFileName(dir)) - { - //LOG("asset: %s", name); - names.push_back(name); - } - AAssetDir_close(dir); -#else - NSString* bundle_path = [[NSBundle mainBundle] resourcePath]; - std::string base = [bundle_path cStringUsingEncoding:1]; - std::string abs_path = base + "/" + folder; - - DIR *dp; - struct dirent *ep; - dp = opendir(abs_path.c_str()); - - if (dp != NULL) - { - while ((ep = readdir(dp))) - if (ep->d_type != DT_DIR) - names.push_back(ep->d_name); - closedir(dp); - } - else - LOG("Couldn't open the directory: %s", folder.c_str()); -#endif - return names; -} - uint16_t NodePanelBrush::get_texture_id(int index) const { return m_brushes[index]->img->m_tex_id; diff --git a/engine/node_panel_brush.h b/engine/node_panel_brush.h index 558a8b7..3fc50c5 100644 --- a/engine/node_panel_brush.h +++ b/engine/node_panel_brush.h @@ -25,6 +25,6 @@ public: virtual Node* clone_instantiate() const override; virtual void init() override; void handle_click(Node* target); - std::vector FindAllBrushes(std::string folder); + std::vector FindAllBrushes(const std::string& folder); uint16_t get_texture_id(int index) const; };