From e44a6a032f21775de0f328f484c42fcdde952223 Mon Sep 17 00:00:00 2001 From: MountainFlash <65584814+MinshuG@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:59:06 +0530 Subject: [PATCH] dpi scaling --- FModel/Framework/ImGuiController.cs | 15 ++++++++++++--- FModel/ViewModels/CUE4ParseViewModel.cs | 8 ++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/FModel/Framework/ImGuiController.cs b/FModel/Framework/ImGuiController.cs index a51b1b27..16864be4 100644 --- a/FModel/Framework/ImGuiController.cs +++ b/FModel/Framework/ImGuiController.cs @@ -3,11 +3,14 @@ using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; +using System.Windows; +using System.Windows.Forms; using ImGuiNET; using OpenTK.Graphics.OpenGL4; using OpenTK.Windowing.Desktop; using OpenTK.Windowing.GraphicsLibraryFramework; using ErrorCode = OpenTK.Graphics.OpenGL4.ErrorCode; +using Keys = OpenTK.Windowing.GraphicsLibraryFramework.Keys; namespace FModel.Framework; @@ -38,6 +41,7 @@ public class ImGuiController : IDisposable public ImFontPtr FontSemiBold; private readonly Vector2 _scaleFactor = Vector2.One; + public readonly float DpiScale = GetDpiScale(); private static bool KHRDebugAvailable = false; @@ -57,9 +61,9 @@ public class ImGuiController : IDisposable // ImGui.LoadIniSettingsFromDisk(_iniPath); var io = ImGui.GetIO(); - FontNormal = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 16); - FontBold = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeuib.ttf", 16); - FontSemiBold = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\seguisb.ttf", 16); + FontNormal = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 16*DpiScale); + FontBold = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeuib.ttf", 16*DpiScale); + FontSemiBold = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\seguisb.ttf", 16*DpiScale); io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; @@ -634,4 +638,9 @@ outputColor = color * texture(in_fontTexture, texCoord); Debug.Print($"{title} ({i++}): {error}"); } } + + public static float GetDpiScale() + { + return Math.Max((float)(Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth), (float)(Screen.PrimaryScreen.Bounds.Height / SystemParameters.PrimaryScreenHeight)); + } } diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index 41041e3e..19df0297 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows; +using System.Windows.Forms; using AdonisUI.Controls; using CUE4Parse.Encryption.Aes; using CUE4Parse.FileProvider; @@ -40,12 +41,14 @@ using FModel.Settings; using FModel.Views; using FModel.Views.Resources.Controls; using FModel.Views.Snooper; +using ImGuiNET; using Newtonsoft.Json; using Ookii.Dialogs.Wpf; using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; using Serilog; using SkiaSharp; +using Application = System.Windows.Application; namespace FModel.ViewModels; @@ -87,13 +90,14 @@ public class CUE4ParseViewModel : ViewModel { return Application.Current.Dispatcher.Invoke(delegate { + float dpiScale = ImGuiController.GetDpiScale(); return _snooper ??= new Snooper( new GameWindowSettings { RenderFrequency = Snooper.GetMaxRefreshFrequency() }, new NativeWindowSettings { Size = new OpenTK.Mathematics.Vector2i( - Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenWidth * .75), - Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenHeight * .85)), + Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenWidth * .75 * dpiScale), + Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenHeight * .85 * dpiScale)), NumberOfSamples = Constants.SAMPLES_COUNT, WindowBorder = WindowBorder.Resizable, Flags = ContextFlags.ForwardCompatible,