2020-07-07 07:15:45 +12:00
|
|
|
|
// <copyright file="Scaling.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
2020-03-28 08:43:16 +13:00
|
|
|
|
|
2020-03-28 12:42:32 +13:00
|
|
|
|
namespace SystemTrayMenu.Utilities
|
2020-03-28 08:43:16 +13:00
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
2020-07-07 09:37:55 +12:00
|
|
|
|
|
2020-03-28 08:43:16 +13:00
|
|
|
|
internal static class Scaling
|
|
|
|
|
{
|
|
|
|
|
private enum DeviceCap
|
|
|
|
|
{
|
|
|
|
|
VERTRES = 10,
|
|
|
|
|
DESKTOPVERTRES = 117,
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 03:05:19 +12:00
|
|
|
|
public static float Factor { get; private set; } = 1;
|
|
|
|
|
|
2020-03-28 08:43:16 +13:00
|
|
|
|
internal static void Initialize()
|
|
|
|
|
{
|
2021-06-27 01:23:39 +12:00
|
|
|
|
#warning [Feature(s)] High resolution compatibility #188
|
|
|
|
|
Factor = 1f; // todo put factor to options
|
|
|
|
|
|
|
|
|
|
// Not more necesssary, i think since upgrade to .net core
|
|
|
|
|
// CalculateScalingFactor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static int Scale(int width)
|
|
|
|
|
{
|
|
|
|
|
return (int)Math.Round(width * Factor, 0, MidpointRounding.AwayFromZero);
|
2020-03-28 08:43:16 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void CalculateScalingFactor()
|
|
|
|
|
{
|
|
|
|
|
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
|
|
|
|
|
IntPtr desktop = g.GetHdc();
|
2020-07-07 09:37:55 +12:00
|
|
|
|
int logicalScreenHeight = DllImports.NativeMethods.Gdi32GetDeviceCaps(
|
2020-03-28 08:43:16 +13:00
|
|
|
|
desktop, (int)DeviceCap.VERTRES);
|
2020-07-07 09:37:55 +12:00
|
|
|
|
int physicalScreenHeight = DllImports.NativeMethods.Gdi32GetDeviceCaps(
|
2020-03-28 08:43:16 +13:00
|
|
|
|
desktop, (int)DeviceCap.DESKTOPVERTRES);
|
2020-07-07 09:37:55 +12:00
|
|
|
|
Factor = physicalScreenHeight / (float)logicalScreenHeight;
|
2020-03-28 08:43:16 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|