Use RenderChar instead of AddText

This commit is contained in:
Soreepeong 2023-12-08 15:48:20 +09:00
parent 2c3139d8b7
commit 806ecc0faf
2 changed files with 32 additions and 17 deletions

View file

@ -105,7 +105,7 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
/// <summary> /// <summary>
/// Gets the input mode icon from <see cref="SeIconChar"/>. /// Gets the input mode icon from <see cref="SeIconChar"/>.
/// </summary> /// </summary>
internal string? InputModeIcon { get; private set; } internal char InputModeIcon { get; private set; }
private static ref ImGuiInputTextState TextState => ref *(ImGuiInputTextState*)(ImGui.GetCurrentContext() + 0x4588); private static ref ImGuiInputTextState TextState => ref *(ImGuiInputTextState*)(ImGui.GetCurrentContext() + 0x4588);
@ -251,37 +251,37 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
{ {
case LANG.LANG_KOREAN: case LANG.LANG_KOREAN:
if (native) if (native)
this.InputModeIcon = $"{(char)SeIconChar.ImeKoreanHangul}"; this.InputModeIcon = (char)SeIconChar.ImeKoreanHangul;
else if (fullwidth) else if (fullwidth)
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumeric}"; this.InputModeIcon = (char)SeIconChar.ImeAlphanumeric;
else else
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumericHalfWidth}"; this.InputModeIcon = (char)SeIconChar.ImeAlphanumericHalfWidth;
break; break;
case LANG.LANG_JAPANESE: case LANG.LANG_JAPANESE:
// wtf // wtf
// see the function called from: 48 8b 0d ?? ?? ?? ?? e8 ?? ?? ?? ?? 8b d8 e9 ?? 00 00 0 // see the function called from: 48 8b 0d ?? ?? ?? ?? e8 ?? ?? ?? ?? 8b d8 e9 ?? 00 00 0
if (open && native && katakana && fullwidth) if (open && native && katakana && fullwidth)
this.InputModeIcon = $"{(char)SeIconChar.ImeKatakana}"; this.InputModeIcon = (char)SeIconChar.ImeKatakana;
else if (open && native && katakana) else if (open && native && katakana)
this.InputModeIcon = $"{(char)SeIconChar.ImeKatakanaHalfWidth}"; this.InputModeIcon = (char)SeIconChar.ImeKatakanaHalfWidth;
else if (open && native) else if (open && native)
this.InputModeIcon = $"{(char)SeIconChar.ImeHiragana}"; this.InputModeIcon = (char)SeIconChar.ImeHiragana;
else if (open && fullwidth) else if (open && fullwidth)
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumeric}"; this.InputModeIcon = (char)SeIconChar.ImeAlphanumeric;
else else
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumericHalfWidth}"; this.InputModeIcon = (char)SeIconChar.ImeAlphanumericHalfWidth;
break; break;
case LANG.LANG_CHINESE: case LANG.LANG_CHINESE:
if (native) if (native)
this.InputModeIcon = $"{(char)SeIconChar.ImeChineseHan}"; this.InputModeIcon = (char)SeIconChar.ImeChineseHan;
else else
this.InputModeIcon = $"{(char)SeIconChar.ImeChineseLatin}"; this.InputModeIcon = (char)SeIconChar.ImeChineseLatin;
break; break;
default: default:
this.InputModeIcon = null; this.InputModeIcon = default;
break; break;
} }

View file

@ -43,7 +43,8 @@ internal unsafe class DalamudImeWindow : Window
var drawCand = ime.ImmCand.Count != 0; var drawCand = ime.ImmCand.Count != 0;
var drawConv = drawCand || ime.ShowPartialConversion; var drawConv = drawCand || ime.ShowPartialConversion;
var drawIme = ime.InputModeIcon != null; var drawIme = ime.InputModeIcon != 0;
var imeIconFont = InterfaceManager.DefaultFont;
var pad = ImGui.GetStyle().WindowPadding; var pad = ImGui.GetStyle().WindowPadding;
var candTextSize = ImGui.CalcTextSize(ime.ImmComp == string.Empty ? " " : ime.ImmComp); var candTextSize = ImGui.CalcTextSize(ime.ImmComp == string.Empty ? " " : ime.ImmComp);
@ -139,7 +140,9 @@ internal unsafe class DalamudImeWindow : Window
{ {
if (dx != 0 || dy != 0) if (dx != 0 || dy != 0)
{ {
drawList.AddText( imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor + new Vector2(dx, dy), cursor + new Vector2(dx, dy),
ImGui.GetColorU32(ImGuiCol.WindowBg), ImGui.GetColorU32(ImGuiCol.WindowBg),
ime.InputModeIcon); ime.InputModeIcon);
@ -147,7 +150,12 @@ internal unsafe class DalamudImeWindow : Window
} }
} }
drawList.AddText(cursor, ImGui.GetColorU32(ImGuiCol.Text), ime.InputModeIcon); imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor,
ImGui.GetColorU32(ImGuiCol.Text),
ime.InputModeIcon);
cursor.Y += candTextSize.Y + spaceY; cursor.Y += candTextSize.Y + spaceY;
} }
@ -199,7 +207,9 @@ internal unsafe class DalamudImeWindow : Window
{ {
if (dx != 0 || dy != 0) if (dx != 0 || dy != 0)
{ {
drawList.AddText( imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor + new Vector2(dx, dy), cursor + new Vector2(dx, dy),
ImGui.GetColorU32(ImGuiCol.WindowBg), ImGui.GetColorU32(ImGuiCol.WindowBg),
ime.InputModeIcon); ime.InputModeIcon);
@ -207,7 +217,12 @@ internal unsafe class DalamudImeWindow : Window
} }
} }
drawList.AddText(cursor, ImGui.GetColorU32(ImGuiCol.Text), ime.InputModeIcon); imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor,
ImGui.GetColorU32(ImGuiCol.Text),
ime.InputModeIcon);
} }
return; return;