Skip to content

Commit

Permalink
Better Native Window Creation (MonoGame#8523)
Browse files Browse the repository at this point in the history
Changed the native API to allow console platforms to control the window
client size.

Also fixed a misspelling in the native API.
  • Loading branch information
tomspilman authored Oct 8, 2024
1 parent af25f42 commit 97c029b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions MonoGame.Framework/Platform/Native/GameWindow.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ public unsafe NativeGameWindow(NativeGamePlatform platform, bool primaryWindow)

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

// Create the window which size may be changed by the platform.
_handle = MGP.Window_Create(
platform.Handle,
_width,
_height,
ref _width,
ref _height,
title);

_windows[(nint)_handle] = this;
Expand Down
8 changes: 4 additions & 4 deletions MonoGame.Framework/Platform/Native/Platform.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ internal static unsafe partial class MGP
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_Create", StringMarshalling = StringMarshalling.Utf8)]
public static partial MGP_Window* Window_Create(
MGP_Platform* platform,
int width,
int height,
ref int width,
ref int height,
string title);

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

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

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

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGP_Window_SetTitle", StringMarshalling = StringMarshalling.Utf8)]
Expand Down
6 changes: 3 additions & 3 deletions native/monogame/include/api_MGP.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ MG_EXPORT mgbool MGP_Platform_BeforeDraw(MGP_Platform* platform);
MG_EXPORT const char* MGP_Platform_MakePath(const char* location, const char* path);
MG_EXPORT MGMonoGamePlatform MGP_Platform_GetPlatform();
MG_EXPORT MGGraphicsBackend MGP_Platform_GetGraphicsBackend();
MG_EXPORT MGP_Window* MGP_Window_Create(MGP_Platform* platform, mgint width, mgint height, const char* title);
MG_EXPORT MGP_Window* MGP_Window_Create(MGP_Platform* platform, mgint& width, mgint& height, const char* title);
MG_EXPORT void MGP_Window_Destroy(MGP_Window* window);
MG_EXPORT void MGP_Window_SetIconBitmap(MGP_Window* window, mgbyte* icon, mgint length);
MG_EXPORT void* MGP_Window_GetNativeHandle(MGP_Window* window);
MG_EXPORT mgbool MGP_Window_GetAllowUserResizing(MGP_Window* window);
MG_EXPORT void MGP_Window_SetAllowUserResizing(MGP_Window* window, mgbool allow);
MG_EXPORT mgbool MGP_Window_GetIsBoderless(MGP_Window* window);
MG_EXPORT void MGP_Window_SetIsBoderless(MGP_Window* window, mgbool borderless);
MG_EXPORT mgbool MGP_Window_GetIsBorderless(MGP_Window* window);
MG_EXPORT void MGP_Window_SetIsBorderless(MGP_Window* window, mgbool borderless);
MG_EXPORT void MGP_Window_SetTitle(MGP_Window* window, const char* title);
MG_EXPORT void MGP_Window_Show(MGP_Window* window, mgbool show);
MG_EXPORT void MGP_Window_GetPosition(MGP_Window* window, mgint& x, mgint& y);
Expand Down
4 changes: 2 additions & 2 deletions native/monogame/sdl/MGP_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ mgbool MGP_Platform_BeforeDraw(MGP_Platform* platform)

MGP_Window* MGP_Window_Create(
MGP_Platform* platform,
mgint width,
mgint height,
mgint& width,
mgint& height,
const char* title)
{
assert(platform != nullptr);
Expand Down

0 comments on commit 97c029b

Please sign in to comment.