Skip to content

Commit 6814c26

Browse files
authored
Merge pull request opentk#1660 from MV10/SizeProperties
Fix API Size/ClientSize inconsistencies
2 parents de22589 + e644dd5 commit 6814c26

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

src/OpenTK.Windowing.Desktop/NativeWindow.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ public unsafe Vector2i ClientLocation
504504
}
505505
}
506506

507-
private Vector2i? _minimumSize;
508-
private Vector2i? _maximumSize;
507+
private Vector2i? _minimumClientSize;
508+
private Vector2i? _maximumClientize;
509509

510510
/// <summary>
511511
/// Gets or sets a <see cref="Vector2i" /> structure that contains the external size of this window.
@@ -570,11 +570,11 @@ public unsafe Vector2i FramebufferSize
570570
/// </remarks>
571571
public unsafe Vector2i? MinimumSize
572572
{
573-
get => _minimumSize;
573+
get => _minimumClientSize;
574574
set
575575
{
576-
_minimumSize = value;
577-
GLFW.SetWindowSizeLimits(WindowPtr, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare, _maximumSize?.X ?? GLFW.DontCare, _maximumSize?.Y ?? GLFW.DontCare);
576+
_minimumClientSize = value;
577+
GLFW.SetWindowSizeLimits(WindowPtr, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare, _maximumClientize?.X ?? GLFW.DontCare, _maximumClientize?.Y ?? GLFW.DontCare);
578578
}
579579
}
580580

@@ -587,11 +587,11 @@ public unsafe Vector2i? MinimumSize
587587
/// </remarks>
588588
public unsafe Vector2i? MaximumSize
589589
{
590-
get => _maximumSize;
590+
get => _maximumClientize;
591591
set
592592
{
593-
_maximumSize = value;
594-
GLFW.SetWindowSizeLimits(WindowPtr, _minimumSize?.X ?? GLFW.DontCare, _minimumSize?.Y ?? GLFW.DontCare, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare);
593+
_maximumClientize = value;
594+
GLFW.SetWindowSizeLimits(WindowPtr, _minimumClientSize?.X ?? GLFW.DontCare, _minimumClientSize?.Y ?? GLFW.DontCare, value?.X ?? GLFW.DontCare, value?.Y ?? GLFW.DontCare);
595595
}
596596
}
597597

@@ -882,7 +882,7 @@ public unsafe NativeWindow(NativeWindowSettings settings)
882882
GLFW.WindowHint(WindowHintInt.RefreshRate, modePtr->RefreshRate);
883883

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

887887
if (settings.WindowState == WindowState.Fullscreen && _isVisible)
888888
{
@@ -891,7 +891,7 @@ public unsafe NativeWindow(NativeWindowSettings settings)
891891
}
892892
else
893893
{
894-
WindowPtr = GLFW.CreateWindow(settings.Size.X, settings.Size.Y, _title, null, (Window*)(settings.SharedContext?.WindowPtr ?? IntPtr.Zero));
894+
WindowPtr = GLFW.CreateWindow(settings.ClientSize.X, settings.ClientSize.Y, _title, null, (Window*)(settings.SharedContext?.WindowPtr ?? IntPtr.Zero));
895895
}
896896

897897
// For Vulkan, we need to pass ContextAPI.NoAPI, otherwise we will get an exception.
@@ -954,10 +954,10 @@ public unsafe NativeWindow(NativeWindowSettings settings)
954954
GLFW.GetWindowSize(WindowPtr, out var width, out var height);
955955

956956
AspectRatio = settings.AspectRatio;
957-
_minimumSize = settings.MinimumSize;
958-
_maximumSize = settings.MaximumSize;
957+
_minimumClientSize = settings.MinimumClientSize;
958+
_maximumClientize = settings.MaximumClientSize;
959959

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

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

src/OpenTK.Windowing.Desktop/NativeWindowSettings.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public NativeWindowSettings()
157157
/// <summary>
158158
/// Gets or sets the initial size of the contents of the window.
159159
/// </summary>
160-
public Vector2i Size { get; set; } = new Vector2i(640, 360);
160+
public Vector2i ClientSize { get; set; } = new Vector2i(640, 360);
161161

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

171171
/// <summary>
172172
/// Gets or sets the maximum size of the contents of the window.
@@ -175,7 +175,45 @@ public NativeWindowSettings()
175175
/// Set to <c>null</c> to remove the minimum size constraint.
176176
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
177177
/// </remarks>
178-
public Vector2i? MaximumSize { get; set; } = null;
178+
public Vector2i? MaximumClientSize { get; set; } = null;
179+
180+
/// <summary>
181+
/// Gets or sets the initial size of the contents of the window.
182+
/// </summary>
183+
[Obsolete("Use the " + nameof(ClientSize) + " property to get or set the initial size of the contents of the window.")]
184+
public Vector2i Size
185+
{
186+
get => ClientSize;
187+
set { ClientSize = value; }
188+
}
189+
190+
/// <summary>
191+
/// Gets or sets the minimum size of the contents of the window.
192+
/// </summary>
193+
/// <remarks>
194+
/// Set to <c>null</c> to remove the minimum size constraint.
195+
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
196+
/// </remarks>
197+
[Obsolete("Use the " + nameof(MinimumClientSize) + " property to get or set the minimum size of the contents of the window.")]
198+
public Vector2i? MinimumSize
199+
{
200+
get => MinimumClientSize;
201+
set { MinimumClientSize = value; }
202+
}
203+
204+
/// <summary>
205+
/// Gets or sets the maximum size of the contents of the window.
206+
/// </summary>
207+
/// <remarks>
208+
/// Set to <c>null</c> to remove the minimum size constraint.
209+
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
210+
/// </remarks>
211+
[Obsolete("Use the " + nameof(MaximumClientSize) + " property to get or set the minimum size of the contents of the window.")]
212+
public Vector2i? MaximumSize
213+
{
214+
get => MaximumClientSize;
215+
set { MaximumClientSize = value; }
216+
}
179217

180218
/// <summary>
181219
/// Gets or sets the aspect ratio the window is locked to until changed.

tests/LocalTest/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static void Main(string[] args)
1717
GameWindowSettings gwSettings = new GameWindowSettings()
1818
{
1919
UpdateFrequency = 250,
20-
//RenderFrequency = 10,
2120
};
2221

2322
NativeWindowSettings nwSettings = new NativeWindowSettings()
@@ -28,7 +27,7 @@ static void Main(string[] args)
2827
Flags = ContextFlags.Debug | ContextFlags.ForwardCompatible,
2928
IsEventDriven = false,
3029
Profile = ContextProfile.Core,
31-
Size = (800, 600),
30+
ClientSize = (800, 600),
3231
StartFocused = true,
3332
StartVisible = true,
3433
Title = "Local OpenTK Test",

0 commit comments

Comments
 (0)