Skip to content

Commit

Permalink
Adaptations for uwp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pthom committed Feb 3, 2024
1 parent a888f9c commit 01526e7
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#ifdef _WIN32
#include <cstdio>

#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"
Expand All @@ -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)
Expand Down Expand Up @@ -167,6 +182,10 @@ namespace Internal
return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor);
}

#endif // IS_UWP

} // namespace Internal
} // namespace HelloImGui


#endif // #ifdef _WIN32
37 changes: 0 additions & 37 deletions src/hello_imgui/internal/main_screen_resolution.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions src/hello_imgui/internal/main_screen_resolution.h

This file was deleted.

117 changes: 86 additions & 31 deletions src/hello_imgui/internal/platform/ini_folder_locations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,96 @@
}

#elif defined(_WIN32)
#include <windows.h>
#include <ShlObj.h>
#include <tchar.h>
#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 <winrt/Windows.Storage.h>
#include <locale>
#include <codecvt>

static std::string GetTempPath()
{
auto tempFolder = winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder().Path();
std::wstring tempPathW(tempFolder.begin(), tempFolder.end());
std::wstring_convert<std::codecvt_utf8<wchar_t> > 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<std::codecvt_utf8<wchar_t> > 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<std::codecvt_utf8<wchar_t> > 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<std::codecvt_utf8<wchar_t> > converter;
return converter.to_bytes(pathW);
}

#else // IS_UWP
// Standard windows build
#include <Windows.h>
#include <ShlObj.h>
#include <tchar.h>

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"
Expand Down

0 comments on commit 01526e7

Please sign in to comment.