From e893258b335d9f4d5eaa9707b9d67c3ca2566bda Mon Sep 17 00:00:00 2001 From: SadPencil Date: Fri, 24 Jan 2025 18:24:22 +0800 Subject: [PATCH] Update IMEHandler.cs --- ClientGUI/IME/IMEHandler.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ClientGUI/IME/IMEHandler.cs b/ClientGUI/IME/IMEHandler.cs index 7c1eb54ff..c7c8c8a84 100644 --- a/ClientGUI/IME/IMEHandler.cs +++ b/ClientGUI/IME/IMEHandler.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework; +using Rampastring.XNAUI; using Rampastring.XNAUI.Input; using Rampastring.XNAUI.XNAControls; @@ -89,17 +90,26 @@ protected virtual void OnIMETextInput(char character) private void SetIMETextInputRectangle(XNATextBox sender) { - var rect = sender.RenderRectangle(); - rect.X += sender.WindowManager.SceneXPosition; - rect.Y += sender.WindowManager.SceneYPosition; + WindowManager windowManager = sender.WindowManager; - // Following the input cursor - // This requires SetIMETextInputRectangle() be called whenever InputPosition is changed. + Rectangle textBoxRect = sender.RenderRectangle(); + double scaleRatio = windowManager.ScaleRatio; + Rectangle rect = new() + { + X = (int)(textBoxRect.X * scaleRatio + windowManager.SceneXPosition), + Y = (int)(textBoxRect.Y * scaleRatio + windowManager.SceneYPosition), + Width = (int)(textBoxRect.Width * scaleRatio), + Height = (int)(textBoxRect.Height * scaleRatio) + }; + + // The following code returns a more accurate location, aware of the input cursor + // However, it requires SetIMETextInputRectangle() be called whenever InputPosition is changed. + // And therefore, it's commented out for now. //var vec = Renderer.GetTextDimensions( // sender.Text.Substring(sender.TextStartPosition, sender.TextEndPosition - sender.InputPosition), // sender.FontIndex); - //rect.X += (int)vec.X; + //rect.X += (int)(vec.X * scaleRatio); SetTextInputRectangle(rect); }