@@ -23,9 +23,20 @@ public static class RlImGui
2323 internal static bool IsAltDown ( ) => Raylib . IsKeyDown ( ( int ) KeyboardKey . KEY_LEFT_ALT ) || Raylib . IsKeyDown ( ( int ) KeyboardKey . KEY_RIGHT_ALT ) ;
2424 internal static bool IsSuperDown ( ) => Raylib . IsKeyDown ( ( int ) KeyboardKey . KEY_LEFT_SUPER ) || Raylib . IsKeyDown ( ( int ) KeyboardKey . KEY_RIGHT_SUPER ) ;
2525
26- public static void Setup ( bool darkTheme = true , bool enableDocking = false )
26+ public static void Setup ( bool darkTheme = true , bool enableDocking = false , bool addDefaultFont = true )
2727 {
28- BeginInitImGui ( ) ;
28+ LastFrameFocused = Raylib . IsWindowFocused ( ) ;
29+ LastControlPressed = false ;
30+ LastShiftPressed = false ;
31+ LastAltPressed = false ;
32+ LastSuperPressed = false ;
33+
34+ FontTexture . Id = 0 ;
35+
36+ SetupKeymap ( ) ;
37+ SetupMouseCursors ( ) ;
38+
39+ ImGuiContext = ImGui . CreateContext ( ) ;
2940
3041 if ( darkTheme )
3142 ImGui . StyleColorsDark ( ) ;
@@ -35,22 +46,30 @@ public static void Setup(bool darkTheme = true, bool enableDocking = false)
3546 if ( enableDocking )
3647 ImGui . GetIO ( ) . ConfigFlags |= ImGuiConfigFlags . DockingEnable ;
3748
38- EndInitImGui ( ) ;
39- }
49+ ImGui . SetCurrentContext ( ImGuiContext ) ;
4050
41- public static void BeginInitImGui ( )
42- {
43- LastFrameFocused = Raylib . IsWindowFocused ( ) ;
44- LastControlPressed = false ;
45- LastShiftPressed = false ;
46- LastAltPressed = false ;
47- LastSuperPressed = false ;
51+ var fonts = ImGui . GetIO ( ) . Fonts ;
52+ var io = ImGui . GetIO ( ) ;
53+ var platformIO = ImGui . GetPlatformIO ( ) ;
4854
49- FontTexture . Id = 0 ;
55+ if ( addDefaultFont )
56+ fonts . AddFontDefault ( ) ;
5057
51- SetupKeymap ( ) ;
58+ io . BackendFlags |= ImGuiBackendFlags . HasMouseCursors | ImGuiBackendFlags . HasSetMousePos | ImGuiBackendFlags . HasGamepad ;
59+ io . MousePos . X = 0 ;
60+ io . MousePos . Y = 0 ;
5261
53- ImGuiContext = ImGui . CreateContext ( ) ;
62+ unsafe
63+ {
64+ SetClipCallback = new SetClipTextCallback ( rlImGuiSetClipText ) ;
65+ platformIO . Platform_SetClipboardTextFn = Marshal . GetFunctionPointerForDelegate ( SetClipCallback ) ;
66+
67+ GetClipCallback = new GetClipTextCallback ( rImGuiGetClipText ) ;
68+ platformIO . Platform_GetClipboardTextFn = Marshal . GetFunctionPointerForDelegate ( GetClipCallback ) ;
69+ }
70+
71+ platformIO . Platform_ClipboardUserData = IntPtr . Zero ;
72+ ReloadFonts ( ) ;
5473 }
5574
5675 private static void SetupKeymap ( )
@@ -185,7 +204,7 @@ private static void SetupMouseCursors()
185204 public static unsafe void ReloadFonts ( )
186205 {
187206 ImGui . SetCurrentContext ( ImGuiContext ) ;
188- ImGuiIOPtr io = ImGui . GetIO ( ) ;
207+ var io = ImGui . GetIO ( ) ;
189208
190209 io . Fonts . GetTexDataAsRGBA32 (
191210 out byte * pixels ,
@@ -194,7 +213,7 @@ public static unsafe void ReloadFonts()
194213 out int bytesPerPixel
195214 ) ;
196215
197- Image image = new ( )
216+ var image = new Image ( )
198217 {
199218 Data = pixels ,
200219 Width = width ,
@@ -207,7 +226,6 @@ out int bytesPerPixel
207226 Raylib . UnloadTexture ( FontTexture ) ;
208227
209228 FontTexture = Raylib . LoadTextureFromImage ( image ) ;
210-
211229 io . Fonts . SetTexID ( new IntPtr ( FontTexture . Id ) ) ;
212230 }
213231
@@ -227,35 +245,6 @@ unsafe internal static void rlImGuiSetClipText(IntPtr userData, sbyte* text)
227245 private static GetClipTextCallback ? GetClipCallback ;
228246 private static SetClipTextCallback ? SetClipCallback ;
229247
230- public static void EndInitImGui ( )
231- {
232- SetupMouseCursors ( ) ;
233-
234- ImGui . SetCurrentContext ( ImGuiContext ) ;
235-
236- var fonts = ImGui . GetIO ( ) . Fonts ;
237- fonts . AddFontDefault ( ) ;
238-
239- ImGuiIOPtr io = ImGui . GetIO ( ) ;
240- ImGuiPlatformIOPtr platformIO = ImGui . GetPlatformIO ( ) ;
241-
242- io . BackendFlags |= ImGuiBackendFlags . HasMouseCursors | ImGuiBackendFlags . HasSetMousePos | ImGuiBackendFlags . HasGamepad ;
243- io . MousePos . X = 0 ;
244- io . MousePos . Y = 0 ;
245-
246- unsafe
247- {
248- SetClipCallback = new SetClipTextCallback ( rlImGuiSetClipText ) ;
249- platformIO . Platform_SetClipboardTextFn = Marshal . GetFunctionPointerForDelegate ( SetClipCallback ) ;
250-
251- GetClipCallback = new GetClipTextCallback ( rImGuiGetClipText ) ;
252- platformIO . Platform_GetClipboardTextFn = Marshal . GetFunctionPointerForDelegate ( GetClipCallback ) ;
253- }
254-
255- platformIO . Platform_ClipboardUserData = IntPtr . Zero ;
256- ReloadFonts ( ) ;
257- }
258-
259248 private static void SetMouseEvent ( ImGuiIOPtr io , int rayMouse , ImGuiMouseButton imGuiMouse )
260249 {
261250 if ( Raylib . IsMouseButtonPressed ( rayMouse ) )
0 commit comments