Skip to content

Commit 01526e7

Browse files
committed
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
1 parent a888f9c commit 01526e7

File tree

4 files changed

+105
-73
lines changed

4 files changed

+105
-73
lines changed

src/hello_imgui/internal/backend_impls/backend_window_helper/win32_dpi_awareness.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#ifdef _WIN32
2+
#include <cstdio>
3+
4+
#if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
5+
#define IS_STANDARD_WINDOWS
6+
#else
7+
#define IS_UWP
8+
#endif
9+
210

311
// Adapted from imgui/backends/imgui_impl_win32.cpp
412
#include "imgui.h"
@@ -12,6 +20,13 @@ namespace HelloImGui
1220
{
1321
namespace Internal
1422
{
23+
#ifdef IS_UWP
24+
void ImGui_ImplWin32_EnableDpiAwareness()
25+
{
26+
fprintf(stderr, "ImGui_ImplWin32_EnableDpiAwareness not implemented for __cplusplus_winrt, aka uwp\n");
27+
}
28+
#else
29+
1530

1631
//--------------------------------------------------------------------------------------------------------
1732
// DPI-related helpers (optional)
@@ -167,6 +182,10 @@ namespace Internal
167182
return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor);
168183
}
169184

185+
#endif // IS_UWP
186+
170187
} // namespace Internal
171188
} // namespace HelloImGui
189+
190+
172191
#endif // #ifdef _WIN32

src/hello_imgui/internal/main_screen_resolution.cpp

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/hello_imgui/internal/main_screen_resolution.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/hello_imgui/internal/platform/ini_folder_locations.cpp

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,96 @@
4949
}
5050

5151
#elif defined(_WIN32)
52-
#include <windows.h>
53-
#include <ShlObj.h>
54-
#include <tchar.h>
52+
#if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
53+
#define IS_STANDARD_WINDOWS
54+
#else
55+
#define IS_UWP
56+
#endif
5557

56-
static std::string GetTempPath()
57-
{
58-
TCHAR tempPath[MAX_PATH];
59-
if (GetTempPath(MAX_PATH, tempPath) > 0)
60-
return std::string(tempPath);
61-
return "";
62-
}
58+
#ifdef IS_UWP
59+
// UWP build
60+
61+
#include <winrt/Windows.Storage.h>
62+
#include <locale>
63+
#include <codecvt>
64+
65+
static std::string GetTempPath()
66+
{
67+
auto tempFolder = winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder().Path();
68+
std::wstring tempPathW(tempFolder.begin(), tempFolder.end());
69+
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
70+
return converter.to_bytes(tempPathW);
71+
}
72+
73+
static std::string GetAppUserConfigFolder()
74+
{
75+
auto folder = winrt::Windows::Storage::ApplicationData::Current().RoamingFolder().Path();
76+
std::wstring pathW(folder.begin(), folder.end());
77+
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
78+
return converter.to_bytes(pathW);
79+
}
80+
81+
static std::string GetDocumentsPath()
82+
{
83+
auto folder = winrt::Windows::Storage::KnownFolders::DocumentsLibrary().Path();
84+
std::wstring pathW(folder.begin(), folder.end());
85+
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
86+
return converter.to_bytes(pathW);
87+
}
88+
89+
static std::string GetHomePath()
90+
{
91+
auto folder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder().Path();
92+
std::wstring pathW(folder.begin(), folder.end());
93+
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
94+
return converter.to_bytes(pathW);
95+
}
96+
97+
#else // IS_UWP
98+
// Standard windows build
99+
#include <Windows.h>
100+
#include <ShlObj.h>
101+
#include <tchar.h>
102+
103+
static std::string GetTempPath()
104+
{
105+
// Non-UWP build
106+
TCHAR tempPath[MAX_PATH];
107+
if (::GetTempPath(MAX_PATH, tempPath) > 0)
108+
return std::string(tempPath);
109+
return "";
110+
}
111+
112+
static std::string GetAppUserConfigFolder()
113+
{
114+
TCHAR appDataPath[MAX_PATH];
115+
if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK)
116+
return std::string(appDataPath);
117+
return "";
118+
}
119+
120+
static std::string GetDocumentsPath()
121+
{
122+
TCHAR documentsPath[MAX_PATH];
123+
if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK)
124+
return std::string(documentsPath);
125+
return "";
126+
}
127+
128+
static std::string GetHomePath()
129+
{
130+
// Non-UWP build
131+
TCHAR homePath[MAX_PATH];
132+
if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK)
133+
return std::string(homePath);
134+
return "";
135+
}
136+
137+
138+
#endif // IS_UWP
63139

64-
static std::string GetAppUserConfigFolder()
65-
{
66-
TCHAR appDataPath[MAX_PATH];
67-
if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK)
68-
return std::string(appDataPath);
69-
return "";
70-
}
71140

72-
static std::string GetDocumentsPath()
73-
{
74-
TCHAR documentsPath[MAX_PATH];
75-
if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK)
76-
return std::string(documentsPath);
77-
return "";
78-
}
79141

80-
static std::string GetHomePath()
81-
{
82-
TCHAR homePath[MAX_PATH];
83-
if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK)
84-
return std::string(homePath);
85-
return "";
86-
}
87142

88143
#elif defined(__APPLE__)
89144
#include "hello_imgui/internal/platform/getAppleBundleResourcePath.h"

0 commit comments

Comments
 (0)