Skip to content

Commit e893258

Browse files
committed
Update IMEHandler.cs
1 parent 4b2ecde commit e893258

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ClientGUI/IME/IMEHandler.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using Microsoft.Xna.Framework;
77

8+
using Rampastring.XNAUI;
89
using Rampastring.XNAUI.Input;
910
using Rampastring.XNAUI.XNAControls;
1011

@@ -89,17 +90,26 @@ protected virtual void OnIMETextInput(char character)
8990

9091
private void SetIMETextInputRectangle(XNATextBox sender)
9192
{
92-
var rect = sender.RenderRectangle();
93-
rect.X += sender.WindowManager.SceneXPosition;
94-
rect.Y += sender.WindowManager.SceneYPosition;
93+
WindowManager windowManager = sender.WindowManager;
9594

96-
// Following the input cursor
97-
// This requires SetIMETextInputRectangle() be called whenever InputPosition is changed.
95+
Rectangle textBoxRect = sender.RenderRectangle();
96+
double scaleRatio = windowManager.ScaleRatio;
9897

98+
Rectangle rect = new()
99+
{
100+
X = (int)(textBoxRect.X * scaleRatio + windowManager.SceneXPosition),
101+
Y = (int)(textBoxRect.Y * scaleRatio + windowManager.SceneYPosition),
102+
Width = (int)(textBoxRect.Width * scaleRatio),
103+
Height = (int)(textBoxRect.Height * scaleRatio)
104+
};
105+
106+
// The following code returns a more accurate location, aware of the input cursor
107+
// However, it requires SetIMETextInputRectangle() be called whenever InputPosition is changed.
108+
// And therefore, it's commented out for now.
99109
//var vec = Renderer.GetTextDimensions(
100110
// sender.Text.Substring(sender.TextStartPosition, sender.TextEndPosition - sender.InputPosition),
101111
// sender.FontIndex);
102-
//rect.X += (int)vec.X;
112+
//rect.X += (int)(vec.X * scaleRatio);
103113

104114
SetTextInputRectangle(rect);
105115
}

0 commit comments

Comments
 (0)