Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions Nez.ImGui/Core/ImGuiRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class ImGuiRenderer

List<int> _keys = new List<int>();


public ImGuiRenderer(Game game)
{
unsafe
Expand Down Expand Up @@ -143,6 +142,7 @@ public void BeforeLayout(float deltaTime)
{
ImGui.GetIO().DeltaTime = deltaTime;
UpdateInput();
UpdateTextInput();
ImGui.NewFrame();
}

Expand All @@ -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

/// <summary>
Expand All @@ -182,7 +202,14 @@ void SetupInput()
#if FNA
// forward clipboard methods to SDL
io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate<SetClipboardTextDelegate>(SetClipboardText);
io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate<GetClipboardTextDelegate>(SDL2.SDL.SDL_GetClipboardText);
try
{
io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate<GetClipboardTextDelegate>(SDL3.SDL.SDL_GetClipboardText);
}
catch (DllNotFoundException)
{
io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate<GetClipboardTextDelegate>(SDL2.SDL.SDL_GetClipboardText);
}
#endif

_keys.Add(io.KeyMap[(int)ImGuiKey.Tab] = (int)Keys.Tab);
Expand Down Expand Up @@ -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


Expand Down