diff --git a/src/ImGui.NET/ImGui.cs b/src/ImGui.NET/ImGui.cs index b6b2268..90b10bd 100644 --- a/src/ImGui.NET/ImGui.cs +++ b/src/ImGui.NET/ImGui.cs @@ -520,30 +520,41 @@ namespace ImGuiNET public static bool BeginWindow(string windowTitle) => BeginWindow(windowTitle, WindowFlags.Default); - public static bool BeginWindow(string windowTitle, WindowFlags flags) + public static unsafe bool BeginWindow(string windowTitle, WindowFlags flags) { - bool opened = true; - return ImGuiNative.igBegin(windowTitle, ref opened, flags); + return ImGuiNative.igBegin(windowTitle, null, flags); } - public static bool BeginWindow(string windowTitle, ref bool opened, WindowFlags flags) + public static unsafe bool BeginWindow(string windowTitle, ref bool opened, WindowFlags flags) { - return ImGuiNative.igBegin(windowTitle, ref opened, flags); + byte openedLocal = opened ? (byte)1 : (byte)0; + bool ret = ImGuiNative.igBegin(windowTitle, &openedLocal, flags); + opened = openedLocal != 0; + return ret; } - public static bool BeginWindow(string windowTitle, ref bool opened, float backgroundAlpha, WindowFlags flags) + public static unsafe bool BeginWindow(string windowTitle, ref bool opened, float backgroundAlpha, WindowFlags flags) { - return ImGuiNative.igBegin2(windowTitle, ref opened, new Vector2(), backgroundAlpha, flags); + byte openedLocal = opened ? (byte)1 : (byte)0; + bool ret = ImGuiNative.igBegin2(windowTitle, &openedLocal, new Vector2(), backgroundAlpha, flags); + opened = openedLocal != 0; + return ret; } - public static bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, WindowFlags flags) + public static unsafe bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, WindowFlags flags) { - return ImGuiNative.igBegin2(windowTitle, ref opened, startingSize, 1f, flags); + byte openedLocal = opened ? (byte)1 : (byte)0; + bool ret = ImGuiNative.igBegin2(windowTitle, &openedLocal, startingSize, 1f, flags); + opened = openedLocal != 0; + return ret; } - public static bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, float backgroundAlpha, WindowFlags flags) + public static unsafe bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, float backgroundAlpha, WindowFlags flags) { - return ImGuiNative.igBegin2(windowTitle, ref opened, startingSize, backgroundAlpha, flags); + byte openedLocal = opened ? (byte)1 : (byte)0; + bool ret = ImGuiNative.igBegin2(windowTitle, &openedLocal, startingSize, backgroundAlpha, flags); + opened = openedLocal != 0; + return ret; } public static bool BeginMenu(string label) diff --git a/src/ImGui.NET/ImGuiNative.cs b/src/ImGui.NET/ImGuiNative.cs index 647ce36..b393ee5 100644 --- a/src/ImGui.NET/ImGuiNative.cs +++ b/src/ImGui.NET/ImGuiNative.cs @@ -47,10 +47,10 @@ namespace ImGuiNET // Window [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igBegin(string name, ref bool p_opened, WindowFlags flags); + public static extern bool igBegin(string name, byte* p_opened, WindowFlags flags); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igBegin2(string name, ref bool p_opened, Vector2 size_on_first_use, float bg_alpha, WindowFlags flags); + public static extern bool igBegin2(string name, byte* p_opened, Vector2 size_on_first_use, float bg_alpha, WindowFlags flags); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern void igEnd(); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)]