Calculate screen size using DPI aware routeins (#545)

This commit is contained in:
Timothy Baldridge 2020-02-20 16:08:12 -07:00
parent 6f80a40dc9
commit 5b41e2d311
3 changed files with 44 additions and 3 deletions

View File

@ -6,6 +6,7 @@
* Don't print API keys in logs (#533)
* Store xxHash caches in binary format (#530)
* Added support for Morrowind BSA creation/unpacking
* Calculate screen size using DPI aware routines (#545)
#### Version - 0.9.19.0

View File

@ -1,16 +1,53 @@
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using MahApps.Metro.Controls;
using Microsoft.VisualBasic;
using PInvoke;
using Wabbajack.Lib;
using static PInvoke.User32;
using static PInvoke.Gdi32;
namespace Wabbajack.Util
{
// Much of the GDI code here is taken from : https://github.com/ModOrganizer2/modorganizer/blob/master/src/envmetrics.cpp
// Thanks to MO2 for being good citizens and supporting OSS code
public static class SystemParametersConstructor
{
private static List<(int Width, int Height, bool IsPrimary)> GetDisplays()
{
// Needed to make sure we get the right values from this call
SetProcessDPIAware();
unsafe
{
var col = new List<(int Width, int Height, bool IsPrimary)>();
EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
delegate(IntPtr hMonitor, IntPtr hdcMonitor, RECT* lprcMonitor, void *dwData)
{
MONITORINFOEX mi = new MONITORINFOEX();
mi.cbSize = Marshal.SizeOf(mi);
bool success = GetMonitorInfo(hMonitor, (MONITORINFO*)&mi);
if (success)
{
col.Add(((mi.Monitor.right - mi.Monitor.left), (mi.Monitor.bottom - mi.Monitor.top), mi.Flags == 1));
}
return true;
}, IntPtr.Zero);
return col;
}
}
public static SystemParameters Create()
{
var (width, height, _) = GetDisplays().First(d => d.IsPrimary);
return new SystemParameters
{
ScreenWidth = (int)System.Windows.SystemParameters.PrimaryScreenWidth,
ScreenHeight = (int)System.Windows.SystemParameters.PrimaryScreenHeight
ScreenWidth = width,
ScreenHeight = height
};
}
}

View File

@ -12,6 +12,7 @@
<Description>An automated ModList installer</Description>
<PublishReadyToRun>true</PublishReadyToRun>
<StartupObject></StartupObject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
@ -65,6 +66,8 @@
</PackageReference>
<PackageReference Include="MahApps.Metro" Version="2.0.0-alpha0660" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="3.2.0" />
<PackageReference Include="PInvoke.Gdi32" Version="0.6.6" />
<PackageReference Include="PInvoke.User32" Version="0.6.6" />
<PackageReference Include="ReactiveUI" Version="11.1.23" />
<PackageReference Include="ReactiveUI.Fody" Version="11.1.23" />
<PackageReference Include="ReactiveUI.WPF" Version="11.1.23" />