This commit is contained in:
2018-10-08 12:45:06 +02:00
7 changed files with 89 additions and 22 deletions

View File

@@ -5,7 +5,8 @@
void displayKeyboard(android_app* mApplication, bool pShow);
void pick_file(android_app* mApplication, std::function<void(std::string)> callback);
#elif _WIN32
std::string win32_open_file();
std::string win32_open_file(const char* filter);
std::string win32_open_dir();
#endif
@@ -64,7 +65,7 @@ void App::pick_image(std::function<void(std::string path)> callback)
#elif __ANDROID__
pick_file(and_app, callback);
#elif _WIN32
std::string path = win32_open_file();
std::string path = win32_open_file("Image Files (*.jpg, *.png)\0*.jpg;*.png");
if (!path.empty())
callback(path);
#endif
@@ -89,7 +90,21 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
#elif __ANDROID__
pick_file(and_app, callback);
#elif _WIN32
std::string path = win32_open_file();
std::string filter = "Image Files (";
bool first_type = true;
for (auto& t : types)
{
filter += std::string(first_type ? "" : " ,") + "*." + t;
first_type = false;
}
filter += ")\0";
first_type = true;
for (auto& t : types)
{
filter += std::string(first_type ? "" : ";") + "*." + t;
first_type = false;
}
std::string path = win32_open_file(filter.c_str());
if (!path.empty())
callback(path);
#endif
@@ -110,9 +125,9 @@ void App::pick_dir(std::function<void(std::string path)> callback)
// NOT IMPLEMENTED
#elif _WIN32
// TODO: to be implemented
// std::string path = win32_open_file();
// if (!path.empty())
// callback(path);
std::string path = win32_open_dir();
if (!path.empty())
callback(path);
#endif
}

View File

@@ -107,14 +107,14 @@ void async_unlock()
}
}
std::string win32_open_file()
std::string win32_open_file(const char* filter)
{
OPENFILENAMEA ofn;
char fileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = "Image Files (*.jpg, *.png)\0*.jpg;*.png";
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
@@ -127,6 +127,22 @@ std::string win32_open_file()
return "";
}
std::string win32_open_dir()
{
BROWSEINFOA bi;
char Buffer[MAX_PATH];
ZeroMemory(Buffer, MAX_PATH);
ZeroMemory(&bi, sizeof(bi));
bi.hwndOwner = hWnd;
bi.pszDisplayName = Buffer;
bi.lpszTitle = "Title";
bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE;
LPCITEMIDLIST pFolder = SHBrowseForFolderA(&bi);
if (pFolder == NULL) return "";
if (!SHGetPathFromIDListA(pFolder, Buffer)) return "";
return Buffer;
}
struct async_locker
{
async_locker() { async_lock(); }
@@ -472,12 +488,14 @@ int main(int argc, char** argv)
int frames = 0;
float one_sec = 0;
float render_timer = 0;
float frame_timer = 0;
while(running)
{
t1 = GetTickCount();
float dt = (float)(t1 - t0) / 1000.0f;
one_sec += dt;
render_timer += dt;
frame_timer += dt;
t0 = t1;
if (one_sec > 1.f)
@@ -507,20 +525,22 @@ int main(int argc, char** argv)
}
std::unique_lock<std::mutex> lock(render_mutex);
if (render_timer > 1.0f / target_fps || App::I.redraw)
if (render_timer > 1.0f / target_fps)
{
App::I.redraw = true;
render_timer = 0;
if (App::I.redraw)
{
async_lock();
App::I.redraw = true;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
App::I.clear();
App::I.update(dt);
SwapBuffers(hDC);
async_unlock();
//LOG("swap main");
}
}
if (App::I.redraw)
{
async_lock();
App::I.redraw = true;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
App::I.clear();
App::I.update(frame_timer);
SwapBuffers(hDC);
async_unlock();
frame_timer = 0;
//LOG("swap main");
}
frames++;

View File

@@ -82,7 +82,11 @@ void NodeDialogBrowse::init_controls()
LOG("change working path to %s", path.c_str());
async_start();
App::I.work_path = path;
#ifdef _WIN32
GetFullPathNameA(path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(path.c_str(), path_buffer);
#endif
working_path->set_text_format("Destination dir: %s", path_buffer);
search_path = path;
clear_list();
@@ -92,7 +96,11 @@ void NodeDialogBrowse::init_controls()
});
};
working_path = find<NodeText>("path");
#ifdef _WIN32
GetFullPathNameA(App::I.work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(App::I.work_path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
#endif
// if (auto* first = (NodeDialogBrowseItem*)container->get_child_at(0))

View File

@@ -202,14 +202,22 @@ void NodeDialogSave::init_controls()
LOG("change working path to %s", path.c_str());
async_start();
App::I.work_path = path;
#ifdef _WIN32
GetFullPathNameA(path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
async_update();
async_end();
});
};
working_path = find<NodeText>("path");
#ifdef _WIN32
GetFullPathNameA(App::I.work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(App::I.work_path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
#endif
}
@@ -258,14 +266,22 @@ void NodeDialogNewDoc::init_controls()
LOG("change working path to %s", path.c_str());
async_start();
App::I.work_path = path;
#ifdef _WIN32
GetFullPathNameA(path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
async_update();
async_end();
});
};
working_path = find<NodeText>("path");
#ifdef _WIN32
GetFullPathNameA(App::I.work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(App::I.work_path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
#endif
}