Skip to content

Commit

Permalink
dpi scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
MinshuG committed Mar 4, 2023
1 parent 0343ee3 commit e44a6a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions FModel/Framework/ImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
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;

Expand Down Expand Up @@ -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;

Expand All @@ -57,9 +61,9 @@ public ImGuiController(int width, int height)
// 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;
Expand Down Expand Up @@ -634,4 +638,9 @@ public static void CheckGLError(string title)
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));
}
}
8 changes: 6 additions & 2 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using AdonisUI.Controls;
using CUE4Parse.Encryption.Aes;
using CUE4Parse.FileProvider;
Expand Down Expand Up @@ -40,12 +41,14 @@
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;

Expand Down Expand Up @@ -87,13 +90,14 @@ public Snooper SnooperViewer
{
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,
Expand Down

0 comments on commit e44a6a0

Please sign in to comment.