Skip to content

Commit

Permalink
Fixed: hidpi modes
Browse files Browse the repository at this point in the history
  • Loading branch information
EqUiNoX-Labs committed Sep 7, 2023
1 parent 32a86e9 commit 7e79cbb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Pandora.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Team Resurgent


[ Program .......................................... Pandora V1.0.0 ]
[ Program .......................................... Pandora V1.0.7 ]
[ Type .................................................... Utiliyy ]
[ Platform .................................... Windows, Linux, OSX ]
[ OS Architecture ............................................. X64 ]
Expand Down
6 changes: 3 additions & 3 deletions Pandora/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

try
{
var version = "V1.0.6";
var application = new ApplicationUI();
application.Start(version);
var version = "V1.0.7";
var application = new ApplicationUI(version);
application.Run();
}
catch (Exception ex)
{
Expand Down
52 changes: 29 additions & 23 deletions Pandora/UI/ApplicationUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Numerics;
using System.Runtime.InteropServices;
using OpenTK.Windowing.GraphicsLibraryFramework;
using System;

namespace Pandora
{
Expand All @@ -24,8 +25,7 @@ public LogDetail(string logType, string message)
}
}

private Window? m_window;
private ImGuiController? m_controller;
private Window m_window;
private RemoteContextDialog m_remoteContextDialog = new();
private FileContextDialog m_fileContextDialog = new();
private InputDialog m_inputDialog = new();
Expand All @@ -40,6 +40,7 @@ public LogDetail(string logType, string message)
private bool m_showSplash = true;
private int m_dialupHandle;
private int m_disconnectHandle;
private string m_version;

public string LocalSelectedFolder { get; set; } = Utility.GetApplicationPath() ?? string.Empty;

Expand All @@ -48,12 +49,23 @@ public LogDetail(string logType, string message)
[DllImport("dwmapi.dll", PreserveSig = true)]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, uint attr, ref int attrValue, int attrSize);

public void Start(string version)
public ApplicationUI(string version)
{
m_window = new Window();
m_version = version;
}

private Vector2 GetScaledWindowSize()
{
return new Vector2(m_window.Size.X, m_window.Size.Y) / m_window.Controller.GetScaleFactor();
}

public void Run()
{
var admin = Utility.IsAdmin() ? " ADMIN" : string.Empty;

m_window = new Window();
m_window.Title = $"Pandora - {version}{admin}";
m_window.Title = $"Pandora - {m_version}{admin}";
m_window.Size = new OpenTK.Mathematics.Vector2i(1280, 720);
m_window.VSync = OpenTK.Windowing.Common.VSyncMode.On;

Expand All @@ -65,8 +77,6 @@ public void Start(string version)
var iconImage = new OpenTK.Windowing.Common.Input.Image(resourceImage.Width, resourceImage.Height, byteSpan.ToArray());
m_window.Icon = new OpenTK.Windowing.Common.Input.WindowIcon(iconImage);

m_controller = new ImGuiController(m_window.Width, m_window.Height);

if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000, 0))
{
int value = -1;
Expand Down Expand Up @@ -169,12 +179,6 @@ private void LocalProcessChildFiles(string path, int width)

private void RenderUI()
{
if (m_window == null ||
m_controller == null)
{
return;
}

if (m_remoteContextDialog.Render() == RemoteContextDialog.RemoteContextAction.Download)
{
var remotePath = m_remoteContextDialog.RemotePath;
Expand Down Expand Up @@ -237,17 +241,19 @@ private void RenderUI()
if (m_showSplash)
{
m_showSplash = false;
m_splashDialog.ShowdDialog(m_controller.SplashTexture);
m_splashDialog.ShowdDialog(m_window.Controller.SplashTexture);
}

ImGui.Begin("Main", ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize);
ImGui.SetWindowSize(new Vector2(m_window.Width, m_window.Height));
ImGui.SetWindowSize(GetScaledWindowSize());
ImGui.SetWindowPos(new Vector2(0, 0), ImGuiCond.Always);

ImGui.Text("Log:");

var windowSize = ImGui.GetWindowSize();

ImGuiTableFlags flags = ImGuiTableFlags.Resizable | ImGuiTableFlags.ScrollX | ImGuiTableFlags.ScrollY | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.RowBg;
if (ImGui.BeginTable("tableLog", 2, flags, new Vector2(m_window.Width - 16, 170), 0.0f))
if (ImGui.BeginTable("tableLog", 2, flags, new Vector2(windowSize.X - 16, 170), 0.0f))
{
ImGui.TableSetupColumn("Log Type", ImGuiTableColumnFlags.WidthFixed, 75.0f, 0);
ImGui.TableSetupColumn("Message", ImGuiTableColumnFlags.WidthStretch, 300.0f, 1);
Expand Down Expand Up @@ -290,7 +296,7 @@ private void RenderUI()

ImGui.Spacing();

var halfWidth = m_window.Width / 2;
var halfWidth = (int)(windowSize.X / 2);

ImGui.Text("Local:");
ImGui.SameLine();
Expand All @@ -311,7 +317,7 @@ private void RenderUI()

var lineHeight = ImGui.GetTextLineHeight() + 4;

if (ImGui.BeginChildFrame(1, new Vector2(200, m_window.Height - (358 + 88)), ImGuiWindowFlags.None))
if (ImGui.BeginChildFrame(1, new Vector2(200, windowSize.Y - (358 + 88)), ImGuiWindowFlags.None))
{
var specialFolders = Utility.GetSpecialFolders();
foreach (var specialFolder in specialFolders)
Expand All @@ -328,7 +334,7 @@ private void RenderUI()

ImGui.SameLine();

if (ImGui.BeginChildFrame(2, new Vector2(halfWidth - 222, m_window.Height - (358 + 88)), ImGuiWindowFlags.None))
if (ImGui.BeginChildFrame(2, new Vector2(halfWidth - 222, windowSize.Y - (358 + 88)), ImGuiWindowFlags.None))
{
var directoryInfo = new DirectoryInfo(LocalSelectedFolder);
if (directoryInfo.Parent != null)
Expand Down Expand Up @@ -359,7 +365,7 @@ private void RenderUI()
{
ImGui.BeginDisabled();
}
if (ImGui.BeginChildFrame(3, new Vector2(halfWidth - 14, m_window.Height - (358 + 88)), ImGuiWindowFlags.None))
if (ImGui.BeginChildFrame(3, new Vector2(halfWidth - 14, windowSize.Y - (358 + 88)), ImGuiWindowFlags.None))
{
if (m_client != null)
{
Expand Down Expand Up @@ -451,7 +457,7 @@ private void RenderUI()

ImGui.Text("Downloads:");

if (ImGui.BeginTable("tableDownloads", 4, flags, new Vector2(m_window.Width - 16, 100), 0.0f))
if (ImGui.BeginTable("tableDownloads", 4, flags, new Vector2(windowSize.X - 16, 100), 0.0f))
{
ImGui.TableSetupColumn("Progress", ImGuiTableColumnFlags.WidthFixed, 75.0f, 0);
ImGui.TableSetupColumn("Remote Path", ImGuiTableColumnFlags.WidthFixed, 300.0f, 1);
Expand Down Expand Up @@ -507,7 +513,7 @@ private void RenderUI()
ImGui.EndTable();
}

ImGui.SetCursorPosY(m_window.Height - 40);
ImGui.SetCursorPosY(windowSize.Y - 40);

if (m_client != null)
{
Expand Down Expand Up @@ -567,7 +573,7 @@ private void RenderUI()

ImGui.SameLine();

ImGui.SetCursorPosX(m_window.Width - 133);
ImGui.SetCursorPosX(windowSize.X - 133);

if (ImGui.Button("Visit Patreon", new Vector2(125, 30)))
{
Expand All @@ -593,7 +599,7 @@ private void RenderUI()
}
}

ImGui.SetCursorPos(new Vector2(m_window.Width - 273, m_window.Height - 32));
ImGui.SetCursorPos(new Vector2(windowSize.X - 273, windowSize.Y - 32));
ImGui.Text("Coded by EqUiNoX");

ImGui.End();
Expand Down
29 changes: 21 additions & 8 deletions Pandora/UI/ImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public class ImGuiController : IDisposable

private int _windowWidth;
private int _windowHeight;
private Vector2 _scaleFactor = Vector2.One;
private Vector2 _hdpiScale = Vector2.One;
private Vector2 _retinaScale = Vector2.One;

public Vector2 GetScaleFactor()
{
return _hdpiScale / _retinaScale;
}

public int SplashTexture => _splashTexture;

Expand Down Expand Up @@ -180,10 +186,18 @@ private static void SetXboxTheme()
style.PopupRounding = 6;
}

public unsafe ImGuiController(int width, int height)
public unsafe ImGuiController(Window window)
{
_windowWidth = width;
_windowHeight = height;
_windowWidth = window.ClientSize.X;
_windowHeight = window.ClientSize.Y;

_hdpiScale = Vector2.One;
if (window.TryGetCurrentMonitorScale(out var scaleX, out var scaleY))
{
_hdpiScale = new Vector2(scaleX, scaleY);
}

_retinaScale = new Vector2(window.Width / (float)window.Size.X, window.Height / (float)window.Size.Y);

int major = GL.GetInteger(GetPName.MajorVersion);
int minor = GL.GetInteger(GetPName.MinorVersion);
Expand Down Expand Up @@ -326,8 +340,7 @@ public void Update(float deltaSeconds, GameWindow wnd)
private void SetPerFrameImGuiData(float deltaSeconds)
{
ImGuiIOPtr io = ImGui.GetIO();
io.DisplaySize = new Vector2(_windowWidth / _scaleFactor.X, _windowHeight / _scaleFactor.Y);
io.DisplayFramebufferScale = _scaleFactor;
io.DisplaySize = new Vector2(_windowWidth, _windowHeight) / _hdpiScale;
io.DeltaTime = deltaSeconds;
}

Expand Down Expand Up @@ -357,7 +370,7 @@ private void UpdateImGuiInput(GameWindow wnd)
io.MouseDown[1] = MouseState[MouseButton.Right];
io.MouseDown[2] = MouseState[MouseButton.Middle];

io.MousePos = new Vector2((int)MouseState.X, (int)MouseState.Y);
io.MousePos = new Vector2((int)MouseState.X, (int)MouseState.Y) / GetScaleFactor();

foreach (Keys key in Enum.GetValues(typeof(Keys)))
{
Expand Down Expand Up @@ -479,7 +492,7 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
GL.BindVertexArray(_vertexArray);
CheckGLError("VAO");

draw_data.ScaleClipRects(io.DisplayFramebufferScale);
draw_data.ScaleClipRects(_hdpiScale);

GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.ScissorTest);
Expand Down
16 changes: 5 additions & 11 deletions Pandora/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using Pandora.UI;

namespace Pandora
{
public class Window : GameWindow
{
public Window() : base(GameWindowSettings.Default, new NativeWindowSettings() { Size = new Vector2i(1600, 900), APIVersion = new Version(3, 3) })
{ }
{
Controller = new ImGuiController(this);
}

public int Width => ClientSize.X;

public int Height => ClientSize.Y;

public Action? RenderUI { get; set; }

public ImGuiController? Controller { get; set; }

protected override void OnLoad()
{
base.OnLoad();

Title += " - OpenGL Version: " + GL.GetString(StringName.Version);

Controller = new ImGuiController(ClientSize.X, ClientSize.Y);
}
public ImGuiController Controller { get; set; }

protected override void OnResize(ResizeEventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Get ready to open that box up nice and wide :)

</div>

[ Program .......................................... Pandora V1.0.4 ]
[ Program .......................................... Pandora V1.0.7 ]
[ Type .............................................. Xbins Manager ]
[ Patreon ....................https://www.patreon.com/teamresurgent ]

Expand Down

0 comments on commit 7e79cbb

Please sign in to comment.