public virtual void Clear() { _textList.Clear(); for (int i = 0; i < _keyboardString.Length; i++) { CharBucket.RemoveCharacter(); } _keyboardString = ""; DisplayText = ""; }
protected virtual void CreateText() { ApplyTextOffset(); //Point characterDimensions = TextFont.Font.MeasureString(LastChar).ToPoint(); Point currCharDim = DisplayText.Size(TextFont).ToPoint(); int x = currCharDim.X; int y = currCharDim.Y; Point newPosition = new Point(x, y); CharBucket.AddCharacter(LastChar, newPosition, currCharDim); }
protected override void CreateText() { ApplyTextOffset(); Point textDimensions = DisplayText.Size(TextFont).ToPoint(); //Point characterDimensions = TextFont.Font.MeasureString(LastChar).ToPoint(); int x = (int)textDimensions.X; int y = (int)textDimensions.Y; //y = y <= Top + 2 ? Pointer.Height : y; Point newPosition = new Point(x, y); CharBucket.AddCharacter(LastChar, newPosition, textDimensions); ProcessString(); }
void UpdateCharacters() { int maxSize = Height / (Pointer.Height - 3); int start = NumberOfLines > maxSize ? (NumberOfLines - 1) - maxSize : 0; int end = NumberOfLines; string displayLocalText = ""; for (int i = start; i < end; i++) { displayLocalText += TextLines[i] + (i == end - 1 ? "" : "\n"); } string[] lines = displayLocalText.Split('\n'); for (int i = 0; i < lines.Length - 1; i++) { lines[i] = lines[i].Insert(lines[i].Length, "\n"); } int charIndex = (_keyboardString.Length - displayLocalText.Length); for (int i = 0; i < lines.Length; i++) { int height = 0; int width = 0; string copyLines = lines[i]; for (int j = 0; j < lines[i].Length; j++) { string subStr = copyLines.Substring(0, j + 1); string character = lines[i][j].ToString(); Vector2 dim = subStr.Replace("\n", "").Size(TextFont); Vector2 charSize = character.Size(TextFont); height = (int)(dim.Y * (i + 1)) + 2; width = (int)dim.X + 2; Point location = new Point(width, height); CharBucket.Update(charIndex, location, charSize.ToPoint()); charIndex++; } } }
// Make this more compact and extendable public virtual void OnKeyboardPressed() { _isShift = _myclsinput.isShiftPressed(Keyboard.GetState().GetPressedKeys()); _isControl = _myclsinput.isControlPressed(Keyboard.GetState().GetPressedKeys()); if (Singleton.Input.KeyReleased(Keys.A)) { _keyboardString += _isShift ? "A" : "a"; CreateText(); KeyboardEvents.Released(); } //////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Space)) { _keyboardString += " "; CreateText(); KeyboardEvents.Released(); } if (Singleton.Input.KeyReleased(Keys.B)) { _keyboardString += _isShift ? "B" : "b"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Z)) { _keyboardString += _isShift ? "Z" : "z"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.C)) { _keyboardString += _isShift ? "C" : "c"; CreateText(); KeyboardEvents.Released(); } //////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D)) { _keyboardString += _isShift ? "D" : "d"; CreateText(); KeyboardEvents.Released(); } //////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.E)) { _keyboardString += _isShift ? "E" : "e"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.F)) { _keyboardString += _isShift ? "F" : "f"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.G)) { _keyboardString += _isShift ? "G" : "g"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.H)) { _keyboardString += _isShift ? "H" : "h"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.I)) { _keyboardString += _isShift ? "I" : "i"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.J)) { _keyboardString += _isShift ? "J" : "j"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.K)) { _keyboardString += _isShift ? "K" : "k"; CreateText(); KeyboardEvents.Released(); } if (Singleton.Input.KeyReleased(Keys.L)) { _keyboardString += _isShift ? "L" : "l"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.M)) { _keyboardString += _isShift ? "M" : "m"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.N)) { _keyboardString += _isShift ? "N" : "n"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.O)) { _keyboardString += _isShift ? "O" : "o"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.P)) { _keyboardString += _isShift ? "P" : "p"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Q)) { _keyboardString += _isShift ? "Q" : "q"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.R)) { _keyboardString += _isShift ? "R" : "r"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.S)) { _keyboardString += _isShift ? "S" : "s"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.T)) { _keyboardString += _isShift ? "T" : "t"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.U)) { _keyboardString += _isShift ? "U" : "u"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.V)) { _keyboardString += _isShift ? "V" : "v"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.W)) { _keyboardString += _isShift ? "W" : "w"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Y)) { _keyboardString += _isShift ? "Y" : "y"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.X)) { _keyboardString += _isShift ? "X" : "x"; CreateText(); KeyboardEvents.Released(); } ///////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemSemicolon)) { _keyboardString += _isShift ? ":" : ";"; CreateText(); KeyboardEvents.Released(); } ///////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemQuotes)) { _keyboardString += _isShift ? "\"" : "'"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemComma)) { _keyboardString += _isShift ? "<" : ","; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemPeriod)) { _keyboardString += _isShift ? ">" : "."; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemQuestion)) { _keyboardString += _isShift ? "?" : "/"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemOpenBrackets)) { _keyboardString += _isShift ? "{" : "["; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemCloseBrackets)) { _keyboardString += _isShift ? "}" : "]"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemPipe)) { _keyboardString += _isShift ? "|" : "\\"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D1)) { _keyboardString += _isShift ? "!" : "1"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D2)) { _keyboardString += _isShift ? "@" : "2"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D3)) { _keyboardString += _isShift ? "#" : "3"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D4)) { _keyboardString += _isShift ? "$" : "4"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D5)) { _keyboardString += _isShift ? "%" : "5"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D6)) { _keyboardString += _isShift ? "^" : "6"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D7)) { _keyboardString += _isShift ? "&" : "7"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D8)) { _keyboardString += _isShift ? "*" : "8"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D9)) { _keyboardString += _isShift ? "(" : "9"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D0)) { _keyboardString += _isShift ? ")" : "0"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemTilde)) { _keyboardString += _isShift ? "~" : "`"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemMinus)) { _keyboardString += _isShift ? "_" : "-"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemPlus)) { _keyboardString += _isShift ? "+" : "="; CreateText(); KeyboardEvents.Released(); } if (Singleton.Input.CurrentKey != Keys.None) { // ToDo } if (Singleton.Input.KeyReleased(Keys.Enter)) { if (_myclsinput.EnterKeyState == "down") { _myclsinput.EnterKeyState = "none"; } } if (Singleton.Input.KeyReleased(Keys.Back)) { if (!string.IsNullOrEmpty(_keyboardString)) { CurrItemRect = CharBucket.CurrentItemRectangle; _keyboardString = _keyboardString.Remove(_keyboardString.Length - 1, 1); int startIndex = _keyboardString.Length - DisplayText.Length; if (IsOutOfBounds(TextSize.X) && startIndex >= 0) { string newChar = _keyboardString.Substring(startIndex, 1); DisplayText = DisplayText.Insert(0, newChar); DisplayText = DisplayText.Remove(DisplayText.Length - 1, 1); startIndex--; if (startIndex >= 0) { string extraChar = _keyboardString.Substring(startIndex, 1); string tmp = DisplayText.Insert(0, newChar); float newSize = tmp.Size(TextFont).X - extraChar.Size(TextFont).X; if (!IsOutOfBounds(newSize)) { DisplayText = tmp; } } RearrangeBox(); } else { DisplayText = DisplayText.Remove(DisplayText.Length - 1, 1); } CharBucket.RemoveCharacter(); } KeyboardEvents.Released(); } }
public override void OnKeyboardPressed() { _isShift = _myclsinput.isShiftPressed(Keyboard.GetState().GetPressedKeys()); _isControl = _myclsinput.isControlPressed(Keyboard.GetState().GetPressedKeys()); if (Singleton.Input.KeyReleased(Keys.A)) { _keyboardString += _isShift ? "A" : "a"; CreateText(); KeyboardEvents.Released(); } //////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Space)) { _keyboardString += " "; CreateText(); KeyboardEvents.Released(); } if (Singleton.Input.KeyReleased(Keys.B)) { _keyboardString += _isShift ? "B" : "b"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Z)) { _keyboardString += _isShift ? "Z" : "z"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.C)) { _keyboardString += _isShift ? "C" : "c"; CreateText(); KeyboardEvents.Released(); } //////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D)) { _keyboardString += _isShift ? "D" : "d"; CreateText(); KeyboardEvents.Released(); } //////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.E)) { _keyboardString += _isShift ? "E" : "e"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.F)) { _keyboardString += _isShift ? "F" : "f"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.G)) { _keyboardString += _isShift ? "G" : "g"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.H)) { _keyboardString += _isShift ? "H" : "h"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.I)) { _keyboardString += _isShift ? "I" : "i"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.J)) { _keyboardString += _isShift ? "J" : "j"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.K)) { _keyboardString += _isShift ? "K" : "k"; CreateText(); KeyboardEvents.Released(); } if (Singleton.Input.KeyReleased(Keys.L)) { _keyboardString += _isShift ? "L" : "l"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.M)) { _keyboardString += _isShift ? "M" : "m"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.N)) { _keyboardString += _isShift ? "N" : "n"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.O)) { _keyboardString += _isShift ? "O" : "o"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.P)) { _keyboardString += _isShift ? "P" : "p"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Q)) { _keyboardString += _isShift ? "Q" : "q"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.R)) { _keyboardString += _isShift ? "R" : "r"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.S)) { _keyboardString += _isShift ? "S" : "s"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.T)) { _keyboardString += _isShift ? "T" : "t"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.U)) { _keyboardString += _isShift ? "U" : "u"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.V)) { _keyboardString += _isShift ? "V" : "v"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.W)) { _keyboardString += _isShift ? "W" : "w"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.Y)) { _keyboardString += _isShift ? "Y" : "y"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.X)) { _keyboardString += _isShift ? "X" : "x"; CreateText(); KeyboardEvents.Released(); } ///////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemSemicolon)) { _keyboardString += _isShift ? ":" : ";"; CreateText(); KeyboardEvents.Released(); } ///////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemQuotes)) { _keyboardString += _isShift ? "\"" : "'"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemComma)) { _keyboardString += _isShift ? "<" : ","; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemPeriod)) { _keyboardString += _isShift ? ">" : "."; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemQuestion)) { _keyboardString += _isShift ? "?" : "/"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemOpenBrackets)) { _keyboardString += _isShift ? "{" : "["; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemCloseBrackets)) { _keyboardString += _isShift ? "}" : "]"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemPipe)) { _keyboardString += _isShift ? "|" : "\\"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D1)) { _keyboardString += _isShift ? "!" : "1"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D2)) { _keyboardString += _isShift ? "@" : "2"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D3)) { _keyboardString += _isShift ? "#" : "3"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D4)) { _keyboardString += _isShift ? "$" : "4"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D5)) { _keyboardString += _isShift ? "%" : "5"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D6)) { _keyboardString += _isShift ? "^" : "6"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D7)) { _keyboardString += _isShift ? "&" : "7"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D8)) { _keyboardString += _isShift ? "*" : "8"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D9)) { _keyboardString += _isShift ? "(" : "9"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.D0)) { _keyboardString += _isShift ? ")" : "0"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemTilde)) { _keyboardString += _isShift ? "~" : "`"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemMinus)) { _keyboardString += _isShift ? "_" : "-"; CreateText(); KeyboardEvents.Released(); } /////////////////////////////////////////////////////////// if (Singleton.Input.KeyReleased(Keys.OemPlus)) { _keyboardString += _isShift ? "+" : "="; CreateText(); KeyboardEvents.Released(); } if (Singleton.Input.CurrentKey != Keys.None) { // ToDo } if (Singleton.Input.KeyReleased(Keys.Enter)) { if (_myclsinput.EnterKeyState == "down") { _myclsinput.EnterKeyState = "none"; //DrawTextsOnWindow(_spriteBatch, _chatGlobalList); // Clear(); //enter = true; } } if (Singleton.Input.KeyReleased(Keys.Back)) { // textList.Remove(textList.LastOrDefault()); if (!string.IsNullOrEmpty(_keyboardString)) { bool isNewLine = LastChar == "\n"; MaxLinesLength = Height / (Pointer.Height - 3); if (isNewLine) { CharBucket.RemoveCharacter(); CharBucket.RemoveCharacter(); _keyboardString = _keyboardString.Remove(_keyboardString.Length - 2, 2); if (NumberOfLines > MaxLinesLength && (NumberOfLines - (MaxLinesLength + 1)) < _scrollBar.CurrentScrollValue / 2) { _scrollBar.CurrentScrollValue = (NumberOfLines - (MaxLinesLength + 1)); } } else { CurrItemRect = CharBucket.CurrentItemRectangle; CharBucket.RemoveCharacter(); _keyboardString = _keyboardString.Remove(_keyboardString.Length - 1, 1); } } KeyboardEvents.Released(); } }