From b389d895ab2b8adcd118354e1bdda627068f5d3e Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 19 Dec 2017 00:20:48 +0000 Subject: [PATCH] add import dialog on windows --- engine/app_events.cpp | 6 ++++++ engine/main.cpp | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/engine/app_events.cpp b/engine/app_events.cpp index 682213c..84c8620 100644 --- a/engine/app_events.cpp +++ b/engine/app_events.cpp @@ -3,6 +3,8 @@ #ifdef __ANDROID__ void displayKeyboard(android_app* mApplication, bool pShow); +#elif _WIN32 +std::string win32_open_file(); #endif @@ -51,6 +53,10 @@ void App::pick_image(std::function callback) callback(path); #elif __ANDROID__ //displayKeyboard(and_app, false); +#elif _WIN32 + std::string path = win32_open_file(); + if (!path.empty()) + callback(path); #endif } diff --git a/engine/main.cpp b/engine/main.cpp index f8323dc..a1df199 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -81,6 +81,26 @@ void async_unlock() } } +std::string win32_open_file() +{ + 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.lpstrFile = fileName; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + ofn.lpstrDefExt = ""; + ofn.lpstrInitialDir = "Missions\\"; + if (GetOpenFileNameA(&ofn) != NULL) + { + return fileName; + } + return ""; +} + struct async_locker { async_locker() { async_lock(); }