a
This commit is contained in:
+22
-31
@@ -28,8 +28,6 @@ public unsafe static class ImGuiSDL3Platform
|
||||
|
||||
// IME Handling
|
||||
public nint ImeWindow;
|
||||
public ImGuiPlatformImeData ImeData;
|
||||
public bool ImeDirty;
|
||||
|
||||
// Mouse Handling
|
||||
public uint MouseWindowID;
|
||||
@@ -177,8 +175,6 @@ public unsafe static class ImGuiSDL3Platform
|
||||
|
||||
UpdateMouseData();
|
||||
UpdateMouseCursor();
|
||||
UpdateIme();
|
||||
|
||||
UpdateGamepads();
|
||||
}
|
||||
|
||||
@@ -752,43 +748,41 @@ public unsafe static class ImGuiSDL3Platform
|
||||
return ImGuiKey.None;
|
||||
}
|
||||
|
||||
public static void UpdateIme()
|
||||
private static void UpdateIme(ImGuiViewportPtr viewport, ImGuiPlatformImeDataPtr imeData)
|
||||
{
|
||||
PlatformData data = GetPlatformData();
|
||||
ImGuiPlatformImeData imeData = data.ImeData;
|
||||
nint window = SDL.GetKeyboardFocus();
|
||||
if (imeData.IsNull) return;
|
||||
|
||||
nint window = GetSDLWindowFromViewport(viewport);
|
||||
bool wantTextInput = imeData.WantVisible || imeData.WantTextInput;
|
||||
|
||||
// Stop previous input
|
||||
if ((!(imeData.WantVisible == 1 || imeData.WantTextInput == 1) || data.ImeWindow != window) && data.ImeWindow != nint.Zero)
|
||||
if ((!wantTextInput || data.ImeWindow != window) && data.ImeWindow != nint.Zero)
|
||||
{
|
||||
SDL.StopTextInput(data.ImeWindow);
|
||||
data.ImeWindow = nint.Zero;
|
||||
}
|
||||
if (!data.ImeDirty && data.ImeWindow == window || window == nint.Zero)
|
||||
|
||||
if (!wantTextInput || window == nint.Zero)
|
||||
return;
|
||||
|
||||
// Start/update current input
|
||||
data.ImeDirty = false;
|
||||
if (imeData.WantVisible == 1)
|
||||
if (imeData.WantVisible)
|
||||
{
|
||||
// Offset the IME input area by the viewport position so it tracks the correct screen location
|
||||
// when multiple viewports are in use.
|
||||
Vector2 viewportPos = Vector2.Zero;
|
||||
ImGuiViewportPtr? viewport = GetViewportForWindowId(SDL.GetWindowID(window));
|
||||
if (viewport != null && !viewport.Value.IsNull)
|
||||
viewportPos = viewport.Value.Pos;
|
||||
|
||||
SDL.Rect r = new SDL.Rect
|
||||
{
|
||||
X = (int)(imeData.InputPos.X - viewportPos.X),
|
||||
Y = (int)(imeData.InputPos.Y - viewportPos.Y),
|
||||
X = (int)(imeData.InputPos.X - viewport.Pos.X),
|
||||
Y = (int)(imeData.InputPos.Y - viewport.Pos.Y),
|
||||
W = 1,
|
||||
H = (int)imeData.InputLineHeight
|
||||
};
|
||||
SDL.SetTextInputArea(window, r, 0);
|
||||
data.ImeWindow = window;
|
||||
}
|
||||
if (!SDL.TextInputActive(window) && (imeData.WantVisible == 1 || imeData.WantTextInput == 1))
|
||||
|
||||
data.ImeWindow = window;
|
||||
if (!SDL.TextInputActive(window))
|
||||
SDL.StartTextInput(window);
|
||||
}
|
||||
|
||||
@@ -915,9 +909,9 @@ public unsafe static class ImGuiSDL3Platform
|
||||
public static class DelegateStorage
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate nint PlatformGetClipboardTextFn(nint ctx);
|
||||
internal delegate nint PlatformGetClipboardTextFn(ImGuiContextPtr ctx);
|
||||
internal static readonly PlatformGetClipboardTextFn GetClipboardDelegate = GetClipboardText;
|
||||
private static nint GetClipboardText(nint ctx)
|
||||
private static nint GetClipboardText(ImGuiContextPtr ctx)
|
||||
{
|
||||
PlatformData data = GetPlatformData();
|
||||
if (data.ClipboardTextData != nint.Zero)
|
||||
@@ -934,9 +928,9 @@ public unsafe static class ImGuiSDL3Platform
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void PlatformSetClipboardTextFn(nint ctx, nint text);
|
||||
internal delegate void PlatformSetClipboardTextFn(ImGuiContextPtr ctx, nint text);
|
||||
internal static readonly PlatformSetClipboardTextFn SetClipboardDelegate = SetClipboardText;
|
||||
private static void SetClipboardText(nint ctx, nint text)
|
||||
private static void SetClipboardText(ImGuiContextPtr ctx, nint text)
|
||||
{
|
||||
string? managedText = Marshal.PtrToStringAnsi(text);
|
||||
if (managedText != null)
|
||||
@@ -944,14 +938,11 @@ public unsafe static class ImGuiSDL3Platform
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void PlatformSetImeDataFn(nint ctx, nint userData, nint imeData);
|
||||
internal delegate void PlatformSetImeDataFn(ImGuiContextPtr ctx, ImGuiViewportPtr userData, ImGuiPlatformImeDataPtr imeData);
|
||||
internal static readonly PlatformSetImeDataFn SetImeDataDelegate = SetImeData;
|
||||
private static void SetImeData(nint ctx, nint userData, nint imeData)
|
||||
private static void SetImeData(ImGuiContextPtr ctx, ImGuiViewportPtr viewport, ImGuiPlatformImeDataPtr imeData)
|
||||
{
|
||||
PlatformData data = GetPlatformData();
|
||||
data.ImeData = Marshal.PtrToStructure<ImGuiPlatformImeData>(imeData);
|
||||
data.ImeDirty = true;
|
||||
UpdateIme();
|
||||
UpdateIme(viewport, imeData);
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
@@ -1202,4 +1193,4 @@ public enum MouseCaptureMode
|
||||
Enabled,
|
||||
EnabledAfterDrag,
|
||||
Disabled
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user