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 21:35:07 +12:00
|
|
|
|
Factor = Properties.Settings.Default.SizeInPercentage / 100f;
|
2021-06-27 01:23:39 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static int Scale(int width)
|
|
|
|
|
{
|
|
|
|
|
return (int)Math.Round(width * Factor, 0, MidpointRounding.AwayFromZero);
|
2020-03-28 08:43:16 +13:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-27 21:35:07 +12:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// https://stackoverflow.com/questions/5977445/how-to-get-windows-display-settings
|
|
|
|
|
/// Since .net core 3.1 not more necessary / always returns 1.
|
|
|
|
|
/// </summary>
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|