Skip to content

Commit

Permalink
Use RenderChar instead of AddText
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Dec 10, 2023
1 parent 9fa6cd3 commit 193e25d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
24 changes: 12 additions & 12 deletions Dalamud/Interface/Internal/DalamudIme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal static bool ShowCursorInInputText
/// <summary>
/// Gets the input mode icon from <see cref="SeIconChar"/>.
/// </summary>
internal string? InputModeIcon { get; private set; }
internal char InputModeIcon { get; private set; }

private static ref ImGuiInputTextState TextState => ref *(ImGuiInputTextState*)(ImGui.GetCurrentContext() + 0x4588);

Expand Down Expand Up @@ -251,37 +251,37 @@ private void UpdateInputLanguage(HIMC hImc)
{
case LANG.LANG_KOREAN:
if (native)
this.InputModeIcon = $"{(char)SeIconChar.ImeKoreanHangul}";
this.InputModeIcon = (char)SeIconChar.ImeKoreanHangul;
else if (fullwidth)
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumeric}";
this.InputModeIcon = (char)SeIconChar.ImeAlphanumeric;
else
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumericHalfWidth}";
this.InputModeIcon = (char)SeIconChar.ImeAlphanumericHalfWidth;
break;

case LANG.LANG_JAPANESE:
// wtf
// see the function called from: 48 8b 0d ?? ?? ?? ?? e8 ?? ?? ?? ?? 8b d8 e9 ?? 00 00 0
if (open && native && katakana && fullwidth)
this.InputModeIcon = $"{(char)SeIconChar.ImeKatakana}";
this.InputModeIcon = (char)SeIconChar.ImeKatakana;
else if (open && native && katakana)
this.InputModeIcon = $"{(char)SeIconChar.ImeKatakanaHalfWidth}";
this.InputModeIcon = (char)SeIconChar.ImeKatakanaHalfWidth;
else if (open && native)
this.InputModeIcon = $"{(char)SeIconChar.ImeHiragana}";
this.InputModeIcon = (char)SeIconChar.ImeHiragana;
else if (open && fullwidth)
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumeric}";
this.InputModeIcon = (char)SeIconChar.ImeAlphanumeric;
else
this.InputModeIcon = $"{(char)SeIconChar.ImeAlphanumericHalfWidth}";
this.InputModeIcon = (char)SeIconChar.ImeAlphanumericHalfWidth;
break;

case LANG.LANG_CHINESE:
if (native)
this.InputModeIcon = $"{(char)SeIconChar.ImeChineseHan}";
this.InputModeIcon = (char)SeIconChar.ImeChineseHan;
else
this.InputModeIcon = $"{(char)SeIconChar.ImeChineseLatin}";
this.InputModeIcon = (char)SeIconChar.ImeChineseLatin;
break;

default:
this.InputModeIcon = null;
this.InputModeIcon = default;
break;
}

Expand Down
25 changes: 20 additions & 5 deletions Dalamud/Interface/Internal/Windows/DalamudImeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public override void PostDraw()

var drawCand = ime.ImmCand.Count != 0;
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 candTextSize = ImGui.CalcTextSize(ime.ImmComp == string.Empty ? " " : ime.ImmComp);
Expand Down Expand Up @@ -139,15 +140,22 @@ public override void PostDraw()
{
if (dx != 0 || dy != 0)
{
drawList.AddText(
imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor + new Vector2(dx, dy),
ImGui.GetColorU32(ImGuiCol.WindowBg),
ime.InputModeIcon);
}
}
}

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;
}

Expand Down Expand Up @@ -199,15 +207,22 @@ public override void PostDraw()
{
if (dx != 0 || dy != 0)
{
drawList.AddText(
imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor + new Vector2(dx, dy),
ImGui.GetColorU32(ImGuiCol.WindowBg),
ime.InputModeIcon);
}
}
}

drawList.AddText(cursor, ImGui.GetColorU32(ImGuiCol.Text), ime.InputModeIcon);
imeIconFont.RenderChar(
drawList,
imeIconFont.FontSize,
cursor,
ImGui.GetColorU32(ImGuiCol.Text),
ime.InputModeIcon);
}

return;
Expand Down

0 comments on commit 193e25d

Please sign in to comment.