Skip to content

Commit

Permalink
Update IMEHandler.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SadPencil committed Jan 24, 2025
1 parent 3edd6e9 commit 852d474
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ClientGUI/IME/IMEHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;

using Microsoft.Xna.Framework;

using Rampastring.XNAUI;
using Rampastring.XNAUI.Input;
using Rampastring.XNAUI.XNAControls;

Expand Down Expand Up @@ -52,7 +54,7 @@ private void OnCompositionChanged(string oldValue, string newValue)
LastActionIMEChatInput = false;
}

protected Dictionary<XNATextBox, Action<char>?> TextBoxHandleChatInputCallbacks = [];
protected ConcurrentDictionary<XNATextBox, Action<char>?> TextBoxHandleChatInputCallbacks = [];

public virtual int CompositionCursorPosition { get; set; }

Expand Down Expand Up @@ -92,6 +94,15 @@ private void SetIMETextInputRectangle(XNATextBox sender)
var rect = sender.RenderRectangle();
rect.X += sender.WindowManager.SceneXPosition;
rect.Y += sender.WindowManager.SceneYPosition;

// Following the input cursor
// This requires SetIMETextInputRectangle() be called whenever InputPosition is changed.

//var vec = Renderer.GetTextDimensions(
// sender.Text.Substring(sender.TextStartPosition, sender.TextEndPosition - sender.InputPosition),
// sender.FontIndex);
//rect.X += (int)vec.X;

SetTextInputRectangle(rect);
}

Expand Down Expand Up @@ -128,10 +139,10 @@ void IIMEHandler.OnSelectedChanged(XNATextBox sender)
}

void IIMEHandler.RegisterXNATextBox(XNATextBox sender, Action<char>? handleCharInput) =>
TextBoxHandleChatInputCallbacks.Add(sender, handleCharInput);
TextBoxHandleChatInputCallbacks[sender] = handleCharInput;

void IIMEHandler.KillXNATextBox(XNATextBox sender) =>
TextBoxHandleChatInputCallbacks.Remove(sender);
TextBoxHandleChatInputCallbacks.TryRemove(sender, out _);

bool IIMEHandler.HandleScrollLeftKey(XNATextBox sender) => !CompositionEmpty;

Expand Down

0 comments on commit 852d474

Please sign in to comment.