refactor file and assets search
This commit is contained in:
@@ -44,7 +44,8 @@ void NodePanelBrush::init()
|
||||
{
|
||||
init_template("tpl-panel-brushes");
|
||||
//m_layers_container = find<NodeBorder>("layers-container");
|
||||
static auto icons = FindAllBrushes("data/Icons/");
|
||||
static auto icons = Asset::list_files("data/Icons/", true, ".*\\.png$");
|
||||
|
||||
if ((m_container = find<NodeBorder>("brushes")))
|
||||
{
|
||||
int count = 0;
|
||||
@@ -76,54 +77,6 @@ void NodePanelBrush::handle_click(Node* target)
|
||||
on_brush_changed(this, m_current->m_brushID);
|
||||
}
|
||||
|
||||
std::vector<std::string> NodePanelBrush::FindAllBrushes(std::string folder)
|
||||
{
|
||||
std::vector<std::string> 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;
|
||||
|
||||
Reference in New Issue
Block a user