Per window DPI
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
// TODO: finish better borderless window on windows (fix mouse pos offset when maximized and fix white flicker on window show)
|
||||
#define WINDOWS_USE_NEW_BORDER_LESS 0
|
||||
|
||||
#define DefaultDPI 96
|
||||
|
||||
#if WINDOWS_USE_NEW_BORDER_LESS
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
#endif
|
||||
@@ -95,6 +97,23 @@ WindowsWindow::WindowsWindow(const CreateWindowSettings& settings)
|
||||
nullptr,
|
||||
(HINSTANCE)Platform::Instance,
|
||||
nullptr);
|
||||
|
||||
_dpi = DefaultDPI;
|
||||
// TODO: Is this the correct way of doing this?
|
||||
const HMODULE user32Dll = LoadLibraryW(L"user32.dll");
|
||||
if (user32Dll)
|
||||
{
|
||||
typedef UINT(STDAPICALLTYPE* GetDpiForWindowProc)(HWND hwnd);
|
||||
const GetDpiForWindowProc getDpiForWindowProc = (GetDpiForWindowProc)GetProcAddress(user32Dll, "GetDpiForWindow");
|
||||
|
||||
if (getDpiForWindowProc)
|
||||
{
|
||||
_dpi = getDpiForWindowProc(_handle);
|
||||
}
|
||||
FreeLibrary(user32Dll);
|
||||
}
|
||||
|
||||
_dpiScale = (float)_dpi / (float)DefaultDPI;
|
||||
|
||||
// Validate result
|
||||
if (!HasHWND())
|
||||
@@ -966,6 +985,28 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_DPICHANGED:
|
||||
{
|
||||
// Maybe https://stackoverflow.com/a/45110656
|
||||
_dpi = HIWORD(wParam);
|
||||
_dpiScale = (float)_dpi / (float)DefaultDPI;
|
||||
|
||||
|
||||
RECT* windowRect = (RECT*)lParam;
|
||||
SetWindowPos(_handle,
|
||||
nullptr,
|
||||
windowRect->left,
|
||||
windowRect->top,
|
||||
windowRect->right - windowRect->left,
|
||||
windowRect->bottom - windowRect->top,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
|
||||
|
||||
// Todo: Recalculate fonts
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_ENTERSIZEMOVE:
|
||||
{
|
||||
_isResizing = true;
|
||||
|
||||
Reference in New Issue
Block a user