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 4b2ecde commit e893258
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ClientGUI/IME/IMEHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using Microsoft.Xna.Framework;

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

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e893258

Please sign in to comment.