private void InputManager_KeyPressedCallback(Microsoft.Xna.Framework.Input.Keys key) { if (HasKeyboardFocus && IsEditable) { if (key == Keys.Back || key == Keys.Delete) { if (Text.Length > 0) { Text = Text.Remove(Carat - 1, 1); Carat = MathFunctions.Clamp(Carat - 1, 0, Text.Length); } } else if (key == Keys.Left) { Carat = MathFunctions.Clamp(Carat - 1, 0, Text.Length); } else if (key == Keys.Right) { Carat = MathFunctions.Clamp(Carat + 1, 0, Text.Length); } else { char k = ' '; if (InputManager.TryConvertKeyboardInput(key, Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift), out k)) { Text = Text.Insert(Carat, k.ToString()); Carat = MathFunctions.Clamp(Carat + 1, 0, Text.Length); } } OnTextModified.Invoke(Text); } }
private void InputManager_KeyPressedCallback(Microsoft.Xna.Framework.Input.Keys key) { if (!HasKeyboardFocus || !IsEditable) { return; } Keys prevKey = Key; Key = key; Text = key.ToString(); OnTextModified.Invoke(Text); OnKeyModified.Invoke(prevKey, Key, this); }
private void InputManager_KeyPressedCallback(Microsoft.Xna.Framework.Input.Keys key) { if (HasKeyboardFocus && IsEditable) { if (key == Keys.Back || key == Keys.Delete) { if (Text.Length > 0 && Carat > 0) { Carat = MathFunctions.Clamp(Carat - 1, 0, Text.Length); Text = Text.Remove(Carat, 1); } } else if (key == Keys.Left) { Carat = MathFunctions.Clamp(Carat - 1, 0, Text.Length); } else if (key == Keys.Right) { Carat = MathFunctions.Clamp(Carat + 1, 0, Text.Length); } else if (TextMode == Mode.Numeric && (key == Keys.Up || key == Keys.OemPlus)) { int value; if (int.TryParse(Text, out value)) { value++; Text = value.ToString("D"); } } else if (TextMode == Mode.Numeric && (key == Keys.Down || key == Keys.OemMinus)) { int value; if (int.TryParse(Text, out value)) { value--; Text = value.ToString("D"); } } else { char k = ' '; if (InputManager.TryConvertKeyboardInput(key, Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift), out k)) { if (TextMode != Mode.Text && !char.IsDigit(k)) { return; } if (TextMode == Mode.Numeric && Text == "0") { Text = ""; Carat = 0; } Text = Text.Insert(Carat, k.ToString()); Carat = MathFunctions.Clamp(Carat + 1, 0, Text.Length); } } if (TextMode == Mode.Numeric && string.IsNullOrEmpty(Text)) { Text = "0"; Carat = Text.Length; } OnTextModified.Invoke(Text); } }