Skip to content

Commit 97c029b

Browse files
authored
Better Native Window Creation (MonoGame#8523)
Changed the native API to allow console platforms to control the window client size. Also fixed a misspelling in the native API.
1 parent af25f42 commit 97c029b

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

MonoGame.Framework/Platform/Native/GameWindow.Native.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ public unsafe NativeGameWindow(NativeGamePlatform platform, bool primaryWindow)
105105

106106
var title = Title == null ? AssemblyHelper.GetDefaultWindowTitle() : Title;
107107

108+
// Create the window which size may be changed by the platform.
108109
_handle = MGP.Window_Create(
109110
platform.Handle,
110-
_width,
111-
_height,
111+
ref _width,
112+
ref _height,
112113
title);
113114

114115
_windows[(nint)_handle] = this;

MonoGame.Framework/Platform/Native/Platform.Interop.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ internal static unsafe partial class MGP
269269
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_Create", StringMarshalling = StringMarshalling.Utf8)]
270270
public static partial MGP_Window* Window_Create(
271271
MGP_Platform* platform,
272-
int width,
273-
int height,
272+
ref int width,
273+
ref int height,
274274
string title);
275275

276276
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_Destroy", StringMarshalling = StringMarshalling.Utf8)]
@@ -289,11 +289,11 @@ internal static unsafe partial class MGP
289289
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_SetAllowUserResizing", StringMarshalling = StringMarshalling.Utf8)]
290290
public static partial void Window_SetAllowUserResizing(MGP_Window* window, [MarshalAs(UnmanagedType.U1)] bool allow);
291291

292-
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_GetIsBoderless", StringMarshalling = StringMarshalling.Utf8)]
292+
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_GetIsBorderless", StringMarshalling = StringMarshalling.Utf8)]
293293
[return: MarshalAs(UnmanagedType.U1)]
294294
public static partial bool Window_GetIsBorderless(MGP_Window* window);
295295

296-
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_SetIsBoderless", StringMarshalling = StringMarshalling.Utf8)]
296+
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_SetIsBorderless", StringMarshalling = StringMarshalling.Utf8)]
297297
public static partial void Window_SetIsBorderless(MGP_Window* window, [MarshalAs(UnmanagedType.U1)] bool borderless);
298298

299299
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_SetTitle", StringMarshalling = StringMarshalling.Utf8)]

native/monogame/include/api_MGP.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ MG_EXPORT mgbool MGP_Platform_BeforeDraw(MGP_Platform* platform);
2727
MG_EXPORT const char* MGP_Platform_MakePath(const char* location, const char* path);
2828
MG_EXPORT MGMonoGamePlatform MGP_Platform_GetPlatform();
2929
MG_EXPORT MGGraphicsBackend MGP_Platform_GetGraphicsBackend();
30-
MG_EXPORT MGP_Window* MGP_Window_Create(MGP_Platform* platform, mgint width, mgint height, const char* title);
30+
MG_EXPORT MGP_Window* MGP_Window_Create(MGP_Platform* platform, mgint& width, mgint& height, const char* title);
3131
MG_EXPORT void MGP_Window_Destroy(MGP_Window* window);
3232
MG_EXPORT void MGP_Window_SetIconBitmap(MGP_Window* window, mgbyte* icon, mgint length);
3333
MG_EXPORT void* MGP_Window_GetNativeHandle(MGP_Window* window);
3434
MG_EXPORT mgbool MGP_Window_GetAllowUserResizing(MGP_Window* window);
3535
MG_EXPORT void MGP_Window_SetAllowUserResizing(MGP_Window* window, mgbool allow);
36-
MG_EXPORT mgbool MGP_Window_GetIsBoderless(MGP_Window* window);
37-
MG_EXPORT void MGP_Window_SetIsBoderless(MGP_Window* window, mgbool borderless);
36+
MG_EXPORT mgbool MGP_Window_GetIsBorderless(MGP_Window* window);
37+
MG_EXPORT void MGP_Window_SetIsBorderless(MGP_Window* window, mgbool borderless);
3838
MG_EXPORT void MGP_Window_SetTitle(MGP_Window* window, const char* title);
3939
MG_EXPORT void MGP_Window_Show(MGP_Window* window, mgbool show);
4040
MG_EXPORT void MGP_Window_GetPosition(MGP_Window* window, mgint& x, mgint& y);

native/monogame/sdl/MGP_sdl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ mgbool MGP_Platform_BeforeDraw(MGP_Platform* platform)
662662

663663
MGP_Window* MGP_Window_Create(
664664
MGP_Platform* platform,
665-
mgint width,
666-
mgint height,
665+
mgint& width,
666+
mgint& height,
667667
const char* title)
668668
{
669669
assert(platform != nullptr);

0 commit comments

Comments
 (0)