diff --git a/Nez.ImGui/Core/ImGuiRenderer.cs b/Nez.ImGui/Core/ImGuiRenderer.cs index 9eefae720..fba04d1a0 100644 --- a/Nez.ImGui/Core/ImGuiRenderer.cs +++ b/Nez.ImGui/Core/ImGuiRenderer.cs @@ -43,7 +43,6 @@ public class ImGuiRenderer List _keys = new List(); - public ImGuiRenderer(Game game) { unsafe @@ -143,6 +142,7 @@ public void BeforeLayout(float deltaTime) { ImGui.GetIO().DeltaTime = deltaTime; UpdateInput(); + UpdateTextInput(); ImGui.NewFrame(); } @@ -167,9 +167,29 @@ public void AfterLayout() delegate string GetClipboardTextDelegate(); delegate void SetClipboardTextDelegate(IntPtr userData, string txt); - static void SetClipboardText(IntPtr userData, string txt) => SDL2.SDL.SDL_SetClipboardText(txt); + static void SetClipboardText(IntPtr userData, string txt) + { + try + { + SDL3.SDL.SDL_SetClipboardText(txt); + } + catch (DllNotFoundException) + { + SDL2.SDL.SDL_SetClipboardText(txt); + } + } - static string GetClipboardText() => SDL2.SDL.SDL_GetClipboardText(); + static string GetClipboardText() + { + try + { + return SDL3.SDL.SDL_GetClipboardText(); + } + catch (DllNotFoundException) + { + return SDL2.SDL.SDL_GetClipboardText(); + } + } #endif /// @@ -182,7 +202,14 @@ void SetupInput() #if FNA // forward clipboard methods to SDL io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(SetClipboardText); - io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(SDL2.SDL.SDL_GetClipboardText); + try + { + io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(SDL3.SDL.SDL_GetClipboardText); + } + catch (DllNotFoundException) + { + io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(SDL2.SDL.SDL_GetClipboardText); + } #endif _keys.Add(io.KeyMap[(int)ImGuiKey.Tab] = (int)Keys.Tab); @@ -279,6 +306,16 @@ void UpdateInput() _scrollWheelValue = mouse.ScrollWheelValue; } + void UpdateTextInput() + { +#if FNA + if (ImGui.GetIO().WantTextInput && !TextInputEXT.IsTextInputActive()) + TextInputEXT.StartTextInput(); + else if (!ImGui.GetIO().WantTextInput && TextInputEXT.IsTextInputActive()) + TextInputEXT.StopTextInput(); +#endif + } + #endregion