Skip to content

Commit

Permalink
fix API Size/ClientSize inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MV10 committed Oct 15, 2023
1 parent bc9c634 commit 9c6300d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
26 changes: 13 additions & 13 deletions src/OpenTK.Windowing.Desktop/NativeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ public unsafe Vector2i ClientLocation
}
}

private Vector2i? _minimumSize;
private Vector2i? _maximumSize;
private Vector2i? _minimumClientSize;
private Vector2i? _maximumClientize;

/// <summary>
/// Gets or sets a <see cref="OpenTK.Mathematics.Vector2i" /> structure that contains the external size of this window.
Expand Down Expand Up @@ -537,11 +537,11 @@ public unsafe Vector2i ClientSize
/// </remarks>
public unsafe Vector2i? MinimumSize
{
get => _minimumSize;
get => _minimumClientSize;
set
{
_minimumSize = value;
GLFW.SetWindowSizeLimits(WindowPtr, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare, _maximumSize?.X ?? GLFW.DontCare, _maximumSize?.Y ?? GLFW.DontCare);
_minimumClientSize = value;
GLFW.SetWindowSizeLimits(WindowPtr, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare, _maximumClientize?.X ?? GLFW.DontCare, _maximumClientize?.Y ?? GLFW.DontCare);
}
}

Expand All @@ -554,11 +554,11 @@ public unsafe Vector2i? MinimumSize
/// </remarks>
public unsafe Vector2i? MaximumSize
{
get => _maximumSize;
get => _maximumClientize;
set
{
_maximumSize = value;
GLFW.SetWindowSizeLimits(WindowPtr, _minimumSize?.X ?? GLFW.DontCare, _minimumSize?.Y ?? GLFW.DontCare, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare);
_maximumClientize = value;
GLFW.SetWindowSizeLimits(WindowPtr, _minimumClientSize?.X ?? GLFW.DontCare, _minimumClientSize?.Y ?? GLFW.DontCare, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare);
}
}

Expand Down Expand Up @@ -846,7 +846,7 @@ public unsafe NativeWindow(NativeWindowSettings settings)
GLFW.WindowHint(WindowHintInt.RefreshRate, modePtr->RefreshRate);

_cachedWindowLocation = settings.Location ?? new Vector2i(32, 32); // Better than nothing.
_cachedWindowClientSize = settings.Size;
_cachedWindowClientSize = settings.ClientSize;

if (settings.WindowState == WindowState.Fullscreen && _isVisible)
{
Expand All @@ -855,7 +855,7 @@ public unsafe NativeWindow(NativeWindowSettings settings)
}
else
{
WindowPtr = GLFW.CreateWindow(settings.Size.X, settings.Size.Y, _title, null, (Window*)(settings.SharedContext?.WindowPtr ?? IntPtr.Zero));
WindowPtr = GLFW.CreateWindow(settings.ClientSize.X, settings.ClientSize.Y, _title, null, (Window*)(settings.SharedContext?.WindowPtr ?? IntPtr.Zero));

if (settings.StartVisible)
{
Expand Down Expand Up @@ -916,10 +916,10 @@ public unsafe NativeWindow(NativeWindowSettings settings)
GLFW.GetWindowSize(WindowPtr, out var width, out var height);

AspectRatio = settings.AspectRatio;
_minimumSize = settings.MinimumSize;
_maximumSize = settings.MaximumSize;
_minimumClientSize = settings.MinimumClientSize;
_maximumClientize = settings.MaximumClientSize;

GLFW.SetWindowSizeLimits(WindowPtr, _minimumSize?.X ?? GLFW.DontCare, _minimumSize?.Y ?? GLFW.DontCare, _maximumSize?.X ?? GLFW.DontCare, _maximumSize?.Y ?? GLFW.DontCare);
GLFW.SetWindowSizeLimits(WindowPtr, _minimumClientSize?.X ?? GLFW.DontCare, _minimumClientSize?.Y ?? GLFW.DontCare, _maximumClientize?.X ?? GLFW.DontCare, _maximumClientize?.Y ?? GLFW.DontCare);

GLFW.GetWindowPos(WindowPtr, out var x, out var y);

Expand Down
17 changes: 15 additions & 2 deletions src/OpenTK.Windowing.Desktop/NativeWindowSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public NativeWindowSettings()
/// <summary>
/// Gets or sets the initial size of the contents of the window.
/// </summary>
public Vector2i Size { get; set; } = new Vector2i(640, 360);
public Vector2i ClientSize { get; set; } = new Vector2i(640, 360);

/// <summary>
/// Gets or sets the minimum size of the contents of the window.
Expand All @@ -166,7 +166,7 @@ public NativeWindowSettings()
/// Set to <c>null</c> to remove the minimum size constraint.
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
/// </remarks>
public Vector2i? MinimumSize { get; set; } = null;
public Vector2i? MinimumClientSize { get; set; } = null;

/// <summary>
/// Gets or sets the maximum size of the contents of the window.
Expand All @@ -175,6 +175,19 @@ public NativeWindowSettings()
/// Set to <c>null</c> to remove the minimum size constraint.
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
/// </remarks>
public Vector2i? MaximumClientSize { get; set; } = null;

[Obsolete("Use the ClientSize property to get or set the initial size of the contents of the window.")]
public Vector2i Size
{
get => ClientSize;
set { ClientSize = value; }
}

[Obsolete("Use the MinimumClientSize property to get or set the minimum size of the contents of the window.")]
public Vector2i? MinimumSize { get; set; } = null;

[Obsolete("Use the MaximumClientSize property to get or set the minimum size of the contents of the window.")]
public Vector2i? MaximumSize { get; set; } = null;

/// <summary>
Expand Down
31 changes: 21 additions & 10 deletions tests/LocalTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Linq;

namespace LocalTest
{
Expand All @@ -17,7 +14,7 @@ static void Main(string[] args)
GameWindowSettings gwSettings = new GameWindowSettings()
{
UpdateFrequency = 250,
//RenderFrequency = 10,
//RenderFrequency = 10, Obsolete as of 4.8.1
};

NativeWindowSettings nwSettings = new NativeWindowSettings()
Expand All @@ -28,22 +25,36 @@ static void Main(string[] args)
Flags = ContextFlags.Debug | ContextFlags.ForwardCompatible,
IsEventDriven = false,
Profile = ContextProfile.Core,
Size = (800, 600),
ClientSize = (800, 600),
//Size = (800, 600), Obsolete as of 4.8.2
StartFocused = true,
StartVisible = true,
Title = "Local OpenTK Test",
WindowBorder = WindowBorder.Resizable,
WindowState = WindowState.Normal,
};

using (Window window = new Window(gwSettings, nwSettings))
{
window.Run();
}
using Window window = new Window(gwSettings, nwSettings);
window.Run();
}

public Window(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings)
{
Console.WriteLine("\nGameWindowSettings:");
DumpProperties(gwSettings);
Console.WriteLine("\nNativeWindowSettings:");
DumpProperties(nwSettings);

void DumpProperties(object o)
{
var properties = o.GetType().GetProperties().OrderBy(p => p.Name).ToList();
foreach(var prop in properties)
{
var attribs = prop.GetCustomAttributes(typeof(ObsoleteAttribute), true);
if(attribs.Length == 0) // ignore obsolete properties, including inherited ones
Console.WriteLine($" {prop.Name} = {prop.GetValue(o)}");
}
}
}

protected override void OnLoad()
Expand Down

0 comments on commit 9c6300d

Please sign in to comment.