From 01526e7d6b88de5fe4d7c023d4f87ec3daa86402 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Fri, 2 Feb 2024 23:42:17 +0100 Subject: [PATCH] Adaptations for uwp Try fix vcpkg issue on uwp if uwp, no ImGui_ImplWin32_EnableDpiAwareness() if uwp, no ImGui_ImplWin32_EnableDpiAwareness() Win uwp code uwp again uwp again uwp again --- .../win32_dpi_awareness.cpp | 19 +++ .../internal/main_screen_resolution.cpp | 37 ------ .../internal/main_screen_resolution.h | 5 - .../platform/ini_folder_locations.cpp | 117 +++++++++++++----- 4 files changed, 105 insertions(+), 73 deletions(-) delete mode 100644 src/hello_imgui/internal/main_screen_resolution.cpp delete mode 100644 src/hello_imgui/internal/main_screen_resolution.h diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/win32_dpi_awareness.cpp b/src/hello_imgui/internal/backend_impls/backend_window_helper/win32_dpi_awareness.cpp index cd162ee8..1ffa4f45 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/win32_dpi_awareness.cpp +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/win32_dpi_awareness.cpp @@ -1,4 +1,12 @@ #ifdef _WIN32 +#include + +#if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) +#define IS_STANDARD_WINDOWS +#else +#define IS_UWP +#endif + // Adapted from imgui/backends/imgui_impl_win32.cpp #include "imgui.h" @@ -12,6 +20,13 @@ namespace HelloImGui { namespace Internal { + #ifdef IS_UWP + void ImGui_ImplWin32_EnableDpiAwareness() + { + fprintf(stderr, "ImGui_ImplWin32_EnableDpiAwareness not implemented for __cplusplus_winrt, aka uwp\n"); + } + #else + //-------------------------------------------------------------------------------------------------------- // DPI-related helpers (optional) @@ -167,6 +182,10 @@ namespace Internal return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); } + #endif // IS_UWP + } // namespace Internal } // namespace HelloImGui + + #endif // #ifdef _WIN32 diff --git a/src/hello_imgui/internal/main_screen_resolution.cpp b/src/hello_imgui/internal/main_screen_resolution.cpp deleted file mode 100644 index 83429c15..00000000 --- a/src/hello_imgui/internal/main_screen_resolution.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "main_screen_resolution.h" - -ImVec2 MainScreenResolution_Vec2() -{ - auto res = MainScreenResolution(); - return { (float)res[0], (float)res[1] }; -} - -#if defined(_WIN32) -#undef APIENTRY -#include -std::array MainScreenResolution() -{ - return { - GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN) - }; -} -#elif defined(__ANDROID__) -std::array MainScreenResolution() -{ - return { 1024, 768 }; -} -#elif defined(__linux__) -#include -std::array MainScreenResolution() -{ - Display* d = XOpenDisplay(NULL); - Screen* s = DefaultScreenOfDisplay(d); - return { s->width, s->height }; -} -#else -std::array MainScreenResolution() -{ - return { 1280, 720 }; -} -#endif diff --git a/src/hello_imgui/internal/main_screen_resolution.h b/src/hello_imgui/internal/main_screen_resolution.h deleted file mode 100644 index 6577531f..00000000 --- a/src/hello_imgui/internal/main_screen_resolution.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include "imgui.h" -#include -std::array MainScreenResolution(); -ImVec2 MainScreenResolution_Vec2(); \ No newline at end of file diff --git a/src/hello_imgui/internal/platform/ini_folder_locations.cpp b/src/hello_imgui/internal/platform/ini_folder_locations.cpp index 4cfe80d7..ca4940b6 100644 --- a/src/hello_imgui/internal/platform/ini_folder_locations.cpp +++ b/src/hello_imgui/internal/platform/ini_folder_locations.cpp @@ -49,41 +49,96 @@ } #elif defined(_WIN32) - #include - #include - #include + #if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) + #define IS_STANDARD_WINDOWS + #else + #define IS_UWP + #endif - static std::string GetTempPath() - { - TCHAR tempPath[MAX_PATH]; - if (GetTempPath(MAX_PATH, tempPath) > 0) - return std::string(tempPath); - return ""; - } + #ifdef IS_UWP + // UWP build + + #include + #include + #include + + static std::string GetTempPath() + { + auto tempFolder = winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder().Path(); + std::wstring tempPathW(tempFolder.begin(), tempFolder.end()); + std::wstring_convert > converter; + return converter.to_bytes(tempPathW); + } + + static std::string GetAppUserConfigFolder() + { + auto folder = winrt::Windows::Storage::ApplicationData::Current().RoamingFolder().Path(); + std::wstring pathW(folder.begin(), folder.end()); + std::wstring_convert > converter; + return converter.to_bytes(pathW); + } + + static std::string GetDocumentsPath() + { + auto folder = winrt::Windows::Storage::KnownFolders::DocumentsLibrary().Path(); + std::wstring pathW(folder.begin(), folder.end()); + std::wstring_convert > converter; + return converter.to_bytes(pathW); + } + + static std::string GetHomePath() + { + auto folder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder().Path(); + std::wstring pathW(folder.begin(), folder.end()); + std::wstring_convert > converter; + return converter.to_bytes(pathW); + } + + #else // IS_UWP + // Standard windows build + #include + #include + #include + + static std::string GetTempPath() + { + // Non-UWP build + TCHAR tempPath[MAX_PATH]; + if (::GetTempPath(MAX_PATH, tempPath) > 0) + return std::string(tempPath); + return ""; + } + + static std::string GetAppUserConfigFolder() + { + TCHAR appDataPath[MAX_PATH]; + if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) + return std::string(appDataPath); + return ""; + } + + static std::string GetDocumentsPath() + { + TCHAR documentsPath[MAX_PATH]; + if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK) + return std::string(documentsPath); + return ""; + } + + static std::string GetHomePath() + { + // Non-UWP build + TCHAR homePath[MAX_PATH]; + if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK) + return std::string(homePath); + return ""; + } + + + #endif // IS_UWP - static std::string GetAppUserConfigFolder() - { - TCHAR appDataPath[MAX_PATH]; - if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) - return std::string(appDataPath); - return ""; - } - static std::string GetDocumentsPath() - { - TCHAR documentsPath[MAX_PATH]; - if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK) - return std::string(documentsPath); - return ""; - } - static std::string GetHomePath() - { - TCHAR homePath[MAX_PATH]; - if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK) - return std::string(homePath); - return ""; - } #elif defined(__APPLE__) #include "hello_imgui/internal/platform/getAppleBundleResourcePath.h"