diff --git a/Source/Editor/Content/Proxy/ShaderProxy.cs b/Source/Editor/Content/Proxy/ShaderProxy.cs index e6e288318..71350e277 100644 --- a/Source/Editor/Content/Proxy/ShaderProxy.cs +++ b/Source/Editor/Content/Proxy/ShaderProxy.cs @@ -29,7 +29,7 @@ namespace FlaxEditor.Content if (asset) { var source = Editor.GetShaderSourceCode(asset); - Utilities.Utils.ShowSourceCodeWindow(source, "Shader Source"); + Utilities.Utils.ShowSourceCodeWindow(source, "Shader Source", item.RootWindow.Window); } return null; } diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 3aa8346c8..408dddbd6 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1181,7 +1181,7 @@ namespace FlaxEditor var win = Windows.GameWin.Root; if (win != null && win.RootWindow is WindowRootControl root && root.Window.IsFocused) { - pos = Vector2.Round(Windows.GameWin.Viewport.PointFromWindow(root.Window.ScreenToClient(pos))); + pos = Vector2.Round(Windows.GameWin.Viewport.PointFromScreen(pos) * root.DpiScale); } else { @@ -1201,7 +1201,7 @@ namespace FlaxEditor var win = Windows.GameWin.Root; if (win != null && win.RootWindow is WindowRootControl root && root.Window.IsFocused) { - pos = Vector2.Round(root.Window.ClientToScreen(Windows.GameWin.Viewport.PointToWindow(pos))); + pos = Vector2.Round(Windows.GameWin.Viewport.PointToScreen(pos / root.DpiScale)); } else { @@ -1231,13 +1231,18 @@ namespace FlaxEditor var gameWin = Windows.GameWin; if (gameWin != null) { - // Handle case when Game window is not selected in tab view - var dockedTo = gameWin.ParentDockPanel; - if (dockedTo != null && dockedTo.SelectedTab != gameWin && dockedTo.SelectedTab != null) - resultAsRef = dockedTo.SelectedTab.Size; - else - resultAsRef = gameWin.Size; - resultAsRef = Vector2.Round(resultAsRef); + var win = gameWin.Root; + if (win != null && win.RootWindow is WindowRootControl root) + { + // Handle case when Game window is not selected in tab view + var dockedTo = gameWin.ParentDockPanel; + if (dockedTo != null && dockedTo.SelectedTab != gameWin && dockedTo.SelectedTab != null) + resultAsRef = dockedTo.SelectedTab.Size * root.DpiScale; + else + resultAsRef = gameWin.Size * root.DpiScale; + + resultAsRef = Vector2.Round(resultAsRef); + } } } diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs index 6caf7f651..247844659 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs @@ -124,7 +124,7 @@ namespace FlaxEditor.GUI.ContextMenu PerformLayout(); // Calculate popup direction and initial location (fit on a single monitor) - var dpiScale = Platform.DpiScale; + var dpiScale = parentWin.DpiScale; Vector2 dpiSize = Size * dpiScale; Vector2 locationWS = parent.PointToWindow(location); Vector2 locationSS = parentWin.PointToScreen(locationWS); @@ -275,7 +275,7 @@ namespace FlaxEditor.GUI.ContextMenu { if (_window != null) { - _window.ClientSize = Size * Platform.DpiScale; + _window.ClientSize = Size * _window.DpiScale; } } diff --git a/Source/Editor/GUI/Dialogs/Dialog.cs b/Source/Editor/GUI/Dialogs/Dialog.cs index 173dd9128..c33429609 100644 --- a/Source/Editor/GUI/Dialogs/Dialog.cs +++ b/Source/Editor/GUI/Dialogs/Dialog.cs @@ -143,7 +143,7 @@ namespace FlaxEditor.GUI.Dialogs // Setup initial window settings CreateWindowSettings settings = CreateWindowSettings.Default; settings.Title = _title; - settings.Size = _dialogSize * Platform.DpiScale; + settings.Size = _dialogSize * parentWindow.DpiScale; settings.AllowMaximize = false; settings.AllowMinimize = false; settings.HasSizingFrame = false; diff --git a/Source/Editor/GUI/Docking/DockPanel.cs b/Source/Editor/GUI/Docking/DockPanel.cs index 2865515da..b514ae7a2 100644 --- a/Source/Editor/GUI/Docking/DockPanel.cs +++ b/Source/Editor/GUI/Docking/DockPanel.cs @@ -123,9 +123,8 @@ namespace FlaxEditor.GUI.Docking if (parentWin == null) throw new InvalidOperationException("Missing parent window."); var control = _tabsProxy != null ? (Control)_tabsProxy : this; - var dpiScale = Platform.DpiScale; var clientPos = control.PointToWindow(Vector2.Zero); - return new Rectangle(parentWin.PointToScreen(clientPos), control.Size * dpiScale); + return new Rectangle(parentWin.PointToScreen(clientPos), control.Size * RootWindow.DpiScale); } } diff --git a/Source/Editor/GUI/MainMenu.cs b/Source/Editor/GUI/MainMenu.cs index ff4e02c4b..bf375a358 100644 --- a/Source/Editor/GUI/MainMenu.cs +++ b/Source/Editor/GUI/MainMenu.cs @@ -190,15 +190,15 @@ namespace FlaxEditor.GUI private WindowHitCodes OnHitTest(ref Vector2 mouse) { - var pos = _window.ScreenToClient(mouse * Platform.DpiScale); + var dpiScale = _window.DpiScale; if (_window.IsMinimized) return WindowHitCodes.NoWhere; if (!_window.IsMaximized) { - var dpiScale = Platform.DpiScale; - var winSize = RootWindow.Size * dpiScale; + var pos = _window.ScreenToClient(mouse * dpiScale); // pos is not DPI adjusted + var winSize = _window.Size; // Distance from which the mouse is considered to be on the border/corner float distance = 5.0f * dpiScale; @@ -228,11 +228,11 @@ namespace FlaxEditor.GUI return WindowHitCodes.Bottom; } - var menuPos = PointFromWindow(pos); - var controlUnderMouse = GetChildAt(menuPos); + var mousePos = PointFromScreen(mouse * dpiScale); + var controlUnderMouse = GetChildAt(mousePos); var isMouseOverSth = controlUnderMouse != null && controlUnderMouse != _title; var rb = GetRightButton(); - if (rb != null && _minimizeButton != null && new Rectangle(rb.UpperRight * Platform.DpiScale, (_minimizeButton.BottomLeft - rb.UpperRight) * Platform.DpiScale).Contains(ref menuPos) && !isMouseOverSth) + if (rb != null && _minimizeButton != null && new Rectangle(rb.UpperRight, _minimizeButton.BottomLeft - rb.UpperRight).Contains(ref mousePos) && !isMouseOverSth) return WindowHitCodes.Caption; return WindowHitCodes.Client; diff --git a/Source/Editor/Modules/WindowsModule.cs b/Source/Editor/Modules/WindowsModule.cs index f38f6fe3b..5267da01f 100644 --- a/Source/Editor/Modules/WindowsModule.cs +++ b/Source/Editor/Modules/WindowsModule.cs @@ -707,8 +707,9 @@ namespace FlaxEditor.Modules var dpiScale = Platform.DpiScale; var settings = CreateWindowSettings.Default; settings.Title = "Flax Editor"; - settings.Size = new Vector2(1300 * dpiScale, 900 * dpiScale); + settings.Size = Platform.DesktopSize; settings.StartPosition = WindowStartPosition.CenterScreen; + settings.ShowAfterFirstPaint = true; #if PLATFORM_WINDOWS if (!Editor.Instance.Options.Options.Interface.UseNativeWindowSystem) diff --git a/Source/Editor/Surface/ContextMenu/ContentFinder.cs b/Source/Editor/Surface/ContextMenu/ContentFinder.cs index 76e8d2e33..6089c2ca7 100644 --- a/Source/Editor/Surface/ContextMenu/ContentFinder.cs +++ b/Source/Editor/Surface/ContextMenu/ContentFinder.cs @@ -108,11 +108,13 @@ namespace FlaxEditor.Surface.ContextMenu { _resultPanel.DisposeChildren(); + var dpiScale = RootWindow.DpiScale; + if (items.Count == 0) { Height = _searchBox.Height + 1; _resultPanel.ScrollBars = ScrollBars.None; - RootWindow.Window.ClientSize = new Vector2(RootWindow.Window.ClientSize.X, Height * Platform.DpiScale); + RootWindow.Window.ClientSize = new Vector2(RootWindow.Window.ClientSize.X, Height * dpiScale); return; } @@ -146,7 +148,7 @@ namespace FlaxEditor.Surface.ContextMenu MatchedItems.Add(searchItem); } - RootWindow.Window.ClientSize = new Vector2(RootWindow.Window.ClientSize.X, Height * Platform.DpiScale); + RootWindow.Window.ClientSize = new Vector2(RootWindow.Window.ClientSize.X, Height * dpiScale); PerformLayout(); } diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index a13d441d9..b5c835d70 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1646,8 +1646,8 @@ namespace FlaxEditor.Utilities /// /// The source code. /// The window title. - /// The context control used to show source code window popup in a proper location. - public static void ShowSourceCodeWindow(string source, string title, Control control = null) + /// The optional parent window. + public static void ShowSourceCodeWindow(string source, string title, Window parentWindow = null) { if (string.IsNullOrEmpty(source)) { @@ -1661,8 +1661,8 @@ namespace FlaxEditor.Utilities settings.AllowMinimize = false; settings.HasSizingFrame = false; settings.StartPosition = WindowStartPosition.CenterParent; - settings.Size = new Vector2(500, 600) * Platform.DpiScale; - settings.Parent = control?.RootWindow?.Window ?? Editor.Instance.Windows.MainWindow; + settings.Size = new Vector2(500, 600) * (parentWindow?.DpiScale ?? Platform.DpiScale); + settings.Parent = parentWindow; settings.Title = title; var dialog = Platform.CreateWindow(ref settings); diff --git a/Source/Editor/Windows/Assets/MaterialWindow.cs b/Source/Editor/Windows/Assets/MaterialWindow.cs index 53d85f493..3e0ac8fb1 100644 --- a/Source/Editor/Windows/Assets/MaterialWindow.cs +++ b/Source/Editor/Windows/Assets/MaterialWindow.cs @@ -240,7 +240,7 @@ namespace FlaxEditor.Windows.Assets private void ShowSourceCode() { var source = Editor.GetShaderSourceCode(_asset); - Utilities.Utils.ShowSourceCodeWindow(source, "Material Source", this); + Utilities.Utils.ShowSourceCodeWindow(source, "Material Source", RootWindow.Window); } /// diff --git a/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs b/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs index ab61a9d68..21107452f 100644 --- a/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs +++ b/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs @@ -146,7 +146,7 @@ namespace FlaxEditor.Windows.Assets private void ShowSourceCode() { var source = Editor.GetShaderSourceCode(_asset); - Utilities.Utils.ShowSourceCodeWindow(source, "Particle Emitter GPU Simulation Source", this); + Utilities.Utils.ShowSourceCodeWindow(source, "Particle Emitter GPU Simulation Source", RootWindow.Window); } /// diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 350714bb3..cd92bc300 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -371,7 +371,7 @@ namespace FlaxEditor.Windows // Focus content window Focus(); - RootWindow?.Window.Focus(); + RootWindow?.Focus(); } // Refresh database and view now diff --git a/Source/Engine/Platform/Android/AndroidWindow.cpp b/Source/Engine/Platform/Android/AndroidWindow.cpp index abfee9d13..4d3c4ca67 100644 --- a/Source/Engine/Platform/Android/AndroidWindow.cpp +++ b/Source/Engine/Platform/Android/AndroidWindow.cpp @@ -6,10 +6,14 @@ #include "Engine/Graphics/RenderTask.h" #include +#define DefaultDPI 96 + AndroidWindow::AndroidWindow(const CreateWindowSettings& settings) : WindowBase(settings) { _clientSize = settings.Size; + _dpi = DefaultDPI; + _dpiScale = (float)_dpi / (float)DefaultDPI; } AndroidWindow::~AndroidWindow() diff --git a/Source/Engine/Platform/Base/PlatformBase.h b/Source/Engine/Platform/Base/PlatformBase.h index 188bad122..a91b5b690 100644 --- a/Source/Engine/Platform/Base/PlatformBase.h +++ b/Source/Engine/Platform/Base/PlatformBase.h @@ -569,17 +569,17 @@ public: API_PROPERTY() static BatteryInfo GetBatteryInfo(); /// - /// Gets the screen DPI setting. + /// Gets the primary monitor's DPI setting. /// API_PROPERTY() static int32 GetDpi(); /// - /// Gets the screen DPI setting scale factor (1 is default). Includes custom DPI scale. + /// Gets the primary monitor's DPI setting scale factor (1 is default). Includes custom DPI scale. /// API_PROPERTY() static float GetDpiScale(); /// - /// The custom screen DPI scale factor to apply globally. Can be used to adjust the User Interface scale (resolution). + /// The custom DPI scale factor to apply globally. Can be used to adjust the User Interface scale (resolution). /// API_FIELD() static float CustomDpiScale; diff --git a/Source/Engine/Platform/Base/WindowBase.h b/Source/Engine/Platform/Base/WindowBase.h index a8215bc8b..b432a8a4d 100644 --- a/Source/Engine/Platform/Base/WindowBase.h +++ b/Source/Engine/Platform/Base/WindowBase.h @@ -281,6 +281,8 @@ protected: String _title; CursorType _cursor; Vector2 _clientSize; + int _dpi; + float _dpiScale; Vector2 _trackingMouseOffset; bool _isUsingMouseOffset; @@ -542,6 +544,21 @@ public: /// The screen space position. API_FUNCTION() virtual Vector2 ClientToScreen(const Vector2& clientPos) const = 0; + /// + /// Gets the window DPI setting. + /// + API_PROPERTY() int GetDpi() const + { + return _dpi; + } + + /// + /// Gets the window DPI scale factor (1 is default). Includes custom DPI scale + /// + API_PROPERTY() float GetDpiScale() const + { + return Platform::CustomDpiScale * _dpiScale; + } public: /// diff --git a/Source/Engine/Platform/Linux/LinuxWindow.cpp b/Source/Engine/Platform/Linux/LinuxWindow.cpp index 32a511834..8714a130c 100644 --- a/Source/Engine/Platform/Linux/LinuxWindow.cpp +++ b/Source/Engine/Platform/Linux/LinuxWindow.cpp @@ -31,6 +31,7 @@ #define _NET_WM_STATE_REMOVE 0L // remove/unset property #define _NET_WM_STATE_ADD 1L // add/set property #define _NET_WM_STATE_TOGGLE 2L // toggle property +#define DefaultDPI 96 // Window routines function prolog #define LINUX_WINDOW_PROLOG X11::Display* display = (X11::Display*)LinuxPlatform::GetXDisplay(); X11::Window window = (X11::Window)_window @@ -150,7 +151,10 @@ LinuxWindow::LinuxWindow(const CreateWindowSettings& settings) X11::XSetTransientForHint(display, window, (X11::Window)((LinuxWindow*)settings.Parent)->GetNativePtr()); } - // Set events mask + _dpi = Platform::GetDpi(); + _dpiScale = (float)_dpi / (float)DefaultDPI; + + // Set input mask long eventMask = ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask | diff --git a/Source/Engine/Platform/UWP/UWPWindow.h b/Source/Engine/Platform/UWP/UWPWindow.h index e687ba32a..f73a046dc 100644 --- a/Source/Engine/Platform/UWP/UWPWindow.h +++ b/Source/Engine/Platform/UWP/UWPWindow.h @@ -100,7 +100,6 @@ private: UWPWindowImpl* _impl; - float _dpi, _dpiScale; Vector2 _logicalSize; public: diff --git a/Source/Engine/Platform/Window.cs b/Source/Engine/Platform/Window.cs index 8a8a19c01..d000c6f90 100644 --- a/Source/Engine/Platform/Window.cs +++ b/Source/Engine/Platform/Window.cs @@ -7,8 +7,6 @@ namespace FlaxEngine { partial class Window { - internal float _dpiScale; - /// /// Window closing delegate. /// @@ -176,7 +174,6 @@ namespace FlaxEngine private Window() { GUI = new WindowRootControl(this); - _dpiScale = Platform.DpiScale; } internal void Internal_OnShow() @@ -192,7 +189,7 @@ namespace FlaxEngine internal void Internal_OnDraw() { - Matrix3x3.Scaling(_dpiScale, out var scale); + Matrix3x3.Scaling(DpiScale, out var scale); Render2D.PushTransform(ref scale); GUI.Draw(); Render2D.PopTransform(); @@ -200,7 +197,7 @@ namespace FlaxEngine internal void Internal_OnResize(int width, int height) { - GUI.Size = new Vector2(width / _dpiScale, height / _dpiScale); + GUI.Size = new Vector2(width / DpiScale, height / DpiScale); } internal void Internal_OnCharInput(char c) @@ -223,7 +220,7 @@ namespace FlaxEngine internal void Internal_OnMouseDown(ref Vector2 mousePos, MouseButton button) { - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; bool handled = false; MouseDown?.Invoke(ref pos, button, ref handled); @@ -235,7 +232,7 @@ namespace FlaxEngine internal void Internal_OnMouseUp(ref Vector2 mousePos, MouseButton button) { - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; bool handled = false; MouseUp?.Invoke(ref pos, button, ref handled); @@ -247,7 +244,7 @@ namespace FlaxEngine internal void Internal_OnMouseDoubleClick(ref Vector2 mousePos, MouseButton button) { - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; bool handled = false; MouseDoubleClick?.Invoke(ref pos, button, ref handled); @@ -259,7 +256,7 @@ namespace FlaxEngine internal void Internal_OnMouseWheel(ref Vector2 mousePos, float delta) { - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; bool handled = false; MouseWheel?.Invoke(ref pos, delta, ref handled); @@ -271,7 +268,7 @@ namespace FlaxEngine internal void Internal_OnMouseMove(ref Vector2 mousePos) { - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; MouseMove?.Invoke(ref pos); GUI.OnMouseMove(pos); @@ -285,7 +282,7 @@ namespace FlaxEngine internal void Internal_OnTouchDown(ref Vector2 pointerPosition, int pointerId) { - Vector2 pos = pointerPosition / _dpiScale; + Vector2 pos = pointerPosition / DpiScale; bool handled = false; TouchDown?.Invoke(ref pos, pointerId, ref handled); @@ -297,7 +294,7 @@ namespace FlaxEngine internal void Internal_OnTouchMove(ref Vector2 pointerPosition, int pointerId) { - Vector2 pos = pointerPosition / _dpiScale; + Vector2 pos = pointerPosition / DpiScale; bool handled = false; TouchMove?.Invoke(ref pos, pointerId, ref handled); @@ -309,7 +306,7 @@ namespace FlaxEngine internal void Internal_OnTouchUp(ref Vector2 pointerPosition, int pointerId) { - Vector2 pos = pointerPosition / _dpiScale; + Vector2 pos = pointerPosition / DpiScale; bool handled = false; TouchUp?.Invoke(ref pos, pointerId, ref handled); @@ -335,7 +332,7 @@ namespace FlaxEngine { if (HitTest != null) { - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; result = HitTest(ref pos); handled = true; } @@ -356,7 +353,7 @@ namespace FlaxEngine dragData = new DragDataText(data[0]); else dragData = new DragDataFiles(data); - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; return GUI.OnDragEnter(ref pos, dragData); } @@ -367,7 +364,7 @@ namespace FlaxEngine dragData = new DragDataText(data[0]); else dragData = new DragDataFiles(data); - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; return GUI.OnDragMove(ref pos, dragData); } @@ -378,7 +375,7 @@ namespace FlaxEngine dragData = new DragDataText(data[0]); else dragData = new DragDataFiles(data); - Vector2 pos = mousePos / _dpiScale; + Vector2 pos = mousePos / DpiScale; return GUI.OnDragDrop(ref pos, dragData); } diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp index 4dd2164ae..1b8942dec 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp +++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp @@ -673,7 +673,7 @@ void WindowsPlatform::SetHighDpiAwarenessEnabled(bool enable) if (setProcessDpiAwareness) { - setProcessDpiAwareness(enable ? PROCESS_SYSTEM_DPI_AWARE : PROCESS_DPI_UNAWARE); + setProcessDpiAwareness(enable ? PROCESS_PER_MONITOR_DPI_AWARE : PROCESS_DPI_UNAWARE); } SystemDpi = CalculateDpi(shCoreDll); diff --git a/Source/Engine/Platform/Windows/WindowsWindow.cpp b/Source/Engine/Platform/Windows/WindowsWindow.cpp index 3a35d24e9..b3687cf78 100644 --- a/Source/Engine/Platform/Windows/WindowsWindow.cpp +++ b/Source/Engine/Platform/Windows/WindowsWindow.cpp @@ -13,6 +13,8 @@ #include "../Win32/IncludeWindowsHeaders.h" #include +#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; diff --git a/Source/Engine/Render2D/FontManager.cpp b/Source/Engine/Render2D/FontManager.cpp index ec7a61257..8eda2d5ba 100644 --- a/Source/Engine/Render2D/FontManager.cpp +++ b/Source/Engine/Render2D/FontManager.cpp @@ -67,7 +67,7 @@ bool FontManagerService::Init() ASSERT(Library == nullptr); // Scale UI fonts to match the monitor DPI - FontManager::FontScale = (float)Platform::GetDpi() / (float)DefaultDPI; + FontManager::FontScale = (float)Platform::GetDpi() / (float)DefaultDPI; // TODO: Adjust this at runtime // Init Free Type FreeTypeMemory.user = nullptr; diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs index c2ba34f05..1a0ef5995 100644 --- a/Source/Engine/UI/GUI/Control.cs +++ b/Source/Engine/UI/GUI/Control.cs @@ -310,7 +310,7 @@ namespace FlaxEngine.GUI /// /// Gets the GUI window root control which contains that control (or null if not linked to any). /// - public virtual WindowRootControl RootWindow => _parent?.RootWindow; + public virtual WindowRootControl RootWindow => _root?.RootWindow; /// /// Gets screen position of the control (upper left corner). diff --git a/Source/Engine/UI/GUI/RenderOutputControl.cs b/Source/Engine/UI/GUI/RenderOutputControl.cs index b840e0be8..c12b1844e 100644 --- a/Source/Engine/UI/GUI/RenderOutputControl.cs +++ b/Source/Engine/UI/GUI/RenderOutputControl.cs @@ -224,7 +224,7 @@ namespace FlaxEngine.GUI /// public void SyncBackbufferSize() { - float scale = ResolutionScale * Platform.DpiScale; + float scale = ResolutionScale * (RootWindow?.DpiScale ?? Platform.DpiScale); int width = Mathf.CeilToInt(Width * scale); int height = Mathf.CeilToInt(Height * scale); if (_customResolution.HasValue) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index 5d03bf75c..1ccf0a5da 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -68,7 +68,7 @@ namespace FlaxEngine.GUI var parentWin = target.Root; if (parentWin == null) return; - float dpiScale = Platform.DpiScale; + float dpiScale = target.RootWindow.DpiScale; Vector2 dpiSize = Size * dpiScale; Vector2 locationWS = target.PointToWindow(location); Vector2 locationSS = parentWin.PointToScreen(locationWS); @@ -183,7 +183,7 @@ namespace FlaxEngine.GUI { if (_window) { - _window.ClientSize = Size * Platform.DpiScale; + _window.ClientSize = Size * _window.DpiScale; } } diff --git a/Source/Engine/UI/GUI/WindowRootControl.cs b/Source/Engine/UI/GUI/WindowRootControl.cs index 02c996b68..a8028ebe8 100644 --- a/Source/Engine/UI/GUI/WindowRootControl.cs +++ b/Source/Engine/UI/GUI/WindowRootControl.cs @@ -55,6 +55,11 @@ namespace FlaxEngine.GUI /// public bool IsMaximized => _window.IsMaximized; + /// + /// Gets the window DPI scale factor (1 is default). Includes custom DPI scale + /// + public float DpiScale => _window.DpiScale; + internal WindowRootControl(Window window) { _window = window; @@ -151,7 +156,7 @@ namespace FlaxEngine.GUI } /// - public override Vector2 TrackingMouseOffset => _window.TrackingMouseOffset / _window._dpiScale; + public override Vector2 TrackingMouseOffset => _window.TrackingMouseOffset / _window.DpiScale; /// public override WindowRootControl RootWindow => this; @@ -159,8 +164,8 @@ namespace FlaxEngine.GUI /// public override Vector2 MousePosition { - get => _window.MousePosition / _window._dpiScale; - set => _window.MousePosition = value * _window._dpiScale; + get => _window.MousePosition / _window.DpiScale; + set => _window.MousePosition = value * _window.DpiScale; } /// @@ -234,13 +239,13 @@ namespace FlaxEngine.GUI /// public override Vector2 PointFromScreen(Vector2 location) { - return _window.ScreenToClient(location) / _window._dpiScale; + return _window.ScreenToClient(location) / _window.DpiScale; } /// public override Vector2 PointToScreen(Vector2 location) { - return _window.ClientToScreen(location * _window._dpiScale); + return _window.ClientToScreen(location * _window.DpiScale); } ///