|
1 | 1 | #nullable enable |
2 | 2 | using System; |
| 3 | +using System.Collections.Concurrent; |
3 | 4 | using System.Collections.Generic; |
4 | 5 | using System.Diagnostics; |
5 | 6 |
|
6 | 7 | using Microsoft.Xna.Framework; |
7 | 8 |
|
| 9 | +using Rampastring.XNAUI; |
8 | 10 | using Rampastring.XNAUI.Input; |
9 | 11 | using Rampastring.XNAUI.XNAControls; |
10 | 12 |
|
@@ -52,7 +54,7 @@ private void OnCompositionChanged(string oldValue, string newValue) |
52 | 54 | LastActionIMEChatInput = false; |
53 | 55 | } |
54 | 56 |
|
55 | | - protected Dictionary<XNATextBox, Action<char>?> TextBoxHandleChatInputCallbacks = []; |
| 57 | + protected ConcurrentDictionary<XNATextBox, Action<char>?> TextBoxHandleChatInputCallbacks = []; |
56 | 58 |
|
57 | 59 | public virtual int CompositionCursorPosition { get; set; } |
58 | 60 |
|
@@ -92,6 +94,15 @@ private void SetIMETextInputRectangle(XNATextBox sender) |
92 | 94 | var rect = sender.RenderRectangle(); |
93 | 95 | rect.X += sender.WindowManager.SceneXPosition; |
94 | 96 | rect.Y += sender.WindowManager.SceneYPosition; |
| 97 | + |
| 98 | + // Following the input cursor |
| 99 | + // This requires SetIMETextInputRectangle() be called whenever InputPosition is changed. |
| 100 | + |
| 101 | + //var vec = Renderer.GetTextDimensions( |
| 102 | + // sender.Text.Substring(sender.TextStartPosition, sender.TextEndPosition - sender.InputPosition), |
| 103 | + // sender.FontIndex); |
| 104 | + //rect.X += (int)vec.X; |
| 105 | + |
95 | 106 | SetTextInputRectangle(rect); |
96 | 107 | } |
97 | 108 |
|
@@ -128,10 +139,10 @@ void IIMEHandler.OnSelectedChanged(XNATextBox sender) |
128 | 139 | } |
129 | 140 |
|
130 | 141 | void IIMEHandler.RegisterXNATextBox(XNATextBox sender, Action<char>? handleCharInput) => |
131 | | - TextBoxHandleChatInputCallbacks.Add(sender, handleCharInput); |
| 142 | + TextBoxHandleChatInputCallbacks[sender] = handleCharInput; |
132 | 143 |
|
133 | 144 | void IIMEHandler.KillXNATextBox(XNATextBox sender) => |
134 | | - TextBoxHandleChatInputCallbacks.Remove(sender); |
| 145 | + TextBoxHandleChatInputCallbacks.TryRemove(sender, out _); |
135 | 146 |
|
136 | 147 | bool IIMEHandler.HandleScrollLeftKey(XNATextBox sender) => !CompositionEmpty; |
137 | 148 |
|
|
0 commit comments