From c48091184327cb5a4d12e0e62bac49e24be30bb0 Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Mon, 2 Dec 2013 23:37:00 +0100 Subject: [PATCH] DPI-scaling should affect resolution The correct resolution will now be reported depending on whether the application is DPI-aware. --- Source/OpenTK/Platform/Windows/API.cs | 1 + .../Platform/Windows/WinDisplayDevice.cs | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index 8ad95548..e9b998af 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -1625,6 +1625,7 @@ namespace OpenTK.Platform.Windows internal const byte PFD_UNDERLAY_PLANE = unchecked((byte)-1); // Device mode types (found in wingdi.h) + internal const int DM_LOGPIXELS = 0x00020000; internal const int DM_BITSPERPEL = 0x00040000; internal const int DM_PELSWIDTH = 0x00080000; internal const int DM_PELSHEIGHT = 0x00100000; diff --git a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs index a42b16d1..2ff578f7 100644 --- a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -124,10 +124,12 @@ namespace OpenTK.Platform.Windows { VerifyMode(dev1, monitor_mode); + float scale = GetScale(ref monitor_mode); opentk_dev_current_res = new DisplayResolution( - monitor_mode.Position.X, monitor_mode.Position.Y, - monitor_mode.PelsWidth, monitor_mode.PelsHeight, + (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale), + (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale), monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency); + opentk_dev_primary = (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None; } @@ -138,9 +140,10 @@ namespace OpenTK.Platform.Windows { VerifyMode(dev1, monitor_mode); + float scale = GetScale(ref monitor_mode); DisplayResolution res = new DisplayResolution( - monitor_mode.Position.X, monitor_mode.Position.Y, - monitor_mode.PelsWidth, monitor_mode.PelsHeight, + (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale), + (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale), monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency); opentk_dev_available_res.Add(res); @@ -167,6 +170,15 @@ namespace OpenTK.Platform.Windows } } + private float GetScale(ref DeviceMode monitor_mode) + { + float scale = 1.0f; + if ((monitor_mode.Fields & Constants.DM_LOGPIXELS) != 0) + { + scale = monitor_mode.LogPixels / 96.0f; + } + return scale; + } static void VerifyMode(WindowsDisplayDevice device, DeviceMode mode) {