mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Use bindings for DalamudIme
This commit is contained in:
parent
ad3b0f0194
commit
1bc216ccd6
1 changed files with 17 additions and 24 deletions
|
|
@ -11,6 +11,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Text;
|
||||
using System.Text.Unicode;
|
||||
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Hooking.WndProcHook;
|
||||
|
|
@ -19,8 +20,6 @@ using Dalamud.Interface.GameFonts;
|
|||
using Dalamud.Interface.ManagedFontAtlas.Internals;
|
||||
using Dalamud.Interface.Utility;
|
||||
|
||||
using Dalamud.Bindings.ImGui;
|
||||
|
||||
#if IMEDEBUG
|
||||
using Serilog;
|
||||
#endif
|
||||
|
|
@ -170,7 +169,7 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
return true;
|
||||
if (!ImGui.GetIO().ConfigInputTextCursorBlink)
|
||||
return true;
|
||||
var textState = CustomNativeFunctions.igCustom_GetInputTextState();
|
||||
var textState = GetInputTextState();
|
||||
if (textState->Id == 0 || (textState->Flags & ImGuiInputTextFlags.ReadOnly) != 0)
|
||||
return true;
|
||||
if (textState->CursorAnim <= 0)
|
||||
|
|
@ -228,6 +227,12 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
}
|
||||
}
|
||||
|
||||
private static ImGuiInputTextStateWrapper* GetInputTextState()
|
||||
{
|
||||
var ctx = ImGui.GetCurrentContext();
|
||||
return (ImGuiInputTextStateWrapper*)&ctx.Handle->InputTextState;
|
||||
}
|
||||
|
||||
private static (string String, bool Supported) ToUcs2(char* data, int nc = -1)
|
||||
{
|
||||
if (nc == -1)
|
||||
|
|
@ -326,7 +331,7 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
|
||||
try
|
||||
{
|
||||
var textState = CustomNativeFunctions.igCustom_GetInputTextState();
|
||||
var textState = GetInputTextState();
|
||||
var invalidTarget = textState->Id == 0 || (textState->Flags & ImGuiInputTextFlags.ReadOnly) != 0;
|
||||
|
||||
#if IMEDEBUG
|
||||
|
|
@ -556,7 +561,7 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
|
||||
this.ReflectCharacterEncounters(newString);
|
||||
|
||||
var textState = CustomNativeFunctions.igCustom_GetInputTextState();
|
||||
var textState = GetInputTextState();
|
||||
if (this.temporaryUndoSelection is not null)
|
||||
{
|
||||
textState->Undo();
|
||||
|
|
@ -615,7 +620,7 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
this.compositionCursorOffset = 0;
|
||||
this.temporaryUndoSelection = null;
|
||||
|
||||
var textState = CustomNativeFunctions.igCustom_GetInputTextState();
|
||||
var textState = GetInputTextState();
|
||||
textState->Stb.SelectStart = textState->Stb.Cursor = textState->Stb.SelectEnd;
|
||||
|
||||
this.candidateStrings.Clear();
|
||||
|
|
@ -967,7 +972,7 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct ImGuiInputTextState
|
||||
private struct ImGuiInputTextStateWrapper
|
||||
{
|
||||
public uint Id;
|
||||
public int CurLenW;
|
||||
|
|
@ -985,7 +990,7 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
public bool Edited;
|
||||
public ImGuiInputTextFlags Flags;
|
||||
|
||||
public ImVectorWrapper<char> TextW => new((ImVector*)&this.ThisPtr->TextWRaw);
|
||||
public ImVectorWrapper<char> TextW => new((ImVector*)&this.ThisWrapperPtr->TextWRaw);
|
||||
|
||||
public (int Start, int End, int Cursor) SelectionTuple
|
||||
{
|
||||
|
|
@ -993,6 +998,8 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
set => (this.Stb.SelectStart, this.Stb.SelectEnd, this.Stb.Cursor) = value;
|
||||
}
|
||||
|
||||
private ImGuiInputTextStateWrapper* ThisWrapperPtr => (ImGuiInputTextStateWrapper*)Unsafe.AsPointer(ref this);
|
||||
|
||||
private ImGuiInputTextState* ThisPtr => (ImGuiInputTextState*)Unsafe.AsPointer(ref this);
|
||||
|
||||
public void SetSelectionRange(int offset, int length, int relativeCursorOffset)
|
||||
|
|
@ -1020,14 +1027,14 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
(s, e) = (e, s);
|
||||
}
|
||||
|
||||
public void Undo() => CustomNativeFunctions.igCustom_StbTextUndo(this.ThisPtr);
|
||||
public void Undo() => ImGuiP.Custom_StbTextUndo(this.ThisPtr);
|
||||
|
||||
public bool MakeUndoReplace(int offset, int oldLength, int newLength)
|
||||
{
|
||||
if (oldLength == 0 && newLength == 0)
|
||||
return false;
|
||||
|
||||
CustomNativeFunctions.igCustom_StbTextMakeUndoReplace(this.ThisPtr, offset, oldLength, newLength);
|
||||
ImGuiP.Custom_StbTextMakeUndoReplace(this.ThisPtr, offset, oldLength, newLength);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1103,20 +1110,6 @@ internal sealed unsafe class DalamudIme : IInternalDisposableService
|
|||
}
|
||||
}
|
||||
|
||||
private static class CustomNativeFunctions
|
||||
{
|
||||
#pragma warning disable SA1300
|
||||
[DllImport("cimgui")]
|
||||
public static extern ImGuiInputTextState* igCustom_GetInputTextState();
|
||||
|
||||
[DllImport("cimgui")]
|
||||
public static extern void igCustom_StbTextMakeUndoReplace(ImGuiInputTextState* str, int where, int old_length, int new_length);
|
||||
|
||||
[DllImport("cimgui")]
|
||||
public static extern void igCustom_StbTextUndo(ImGuiInputTextState* str);
|
||||
#pragma warning restore SA1300
|
||||
}
|
||||
|
||||
#if IMEDEBUG
|
||||
private static class ImeDebug
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue