Merge branch 'fix-per-window-dpi' of git://github.com/stefnotch/FlaxEngine into stefnotch-fix-per-window-dpi
# Conflicts: # Source/Editor/Utilities/Utils.cs # Source/Editor/Windows/Assets/MaterialWindow.cs # Source/Editor/Windows/Assets/ParticleEmitterWindow.cs # Source/Engine/Platform/Linux/LinuxWindow.cpp # Source/Engine/Platform/Windows/WindowsWindow.cpp
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
#include "../Win32/IncludeWindowsHeaders.h"
|
||||
#include <propidl.h>
|
||||
|
||||
#define DefaultDPI 96
|
||||
|
||||
// Use improved borderless window support for Editor
|
||||
#define WINDOWS_USE_NEW_BORDER_LESS USE_EDITOR && 0
|
||||
#if WINDOWS_USE_NEW_BORDER_LESS
|
||||
@@ -123,6 +125,21 @@ WindowsWindow::WindowsWindow(const CreateWindowSettings& settings)
|
||||
(HINSTANCE)Platform::Instance,
|
||||
nullptr);
|
||||
|
||||
// Query DPI
|
||||
_dpi = Platform::GetDpi();
|
||||
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())
|
||||
{
|
||||
@@ -1021,6 +1038,22 @@ 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