} // end of TextInput() // TODO (****) Clean this up. We're mixing text as input with text as control here. // Probably the right thing to do would be to push/pop the text input callbacks // dynamically to mirror the state we're in. public void KeyInput(Keys key) { if (EditingCreator || EditingPin) { KeyboardInput.ClearAllWasPressedState(key); TextBlob curBlob = EditingCreator ? creatorBlob : pinBlob; //string curString = EditingCreator ? curCreator : curPin; //int curLength = curString.Length; switch (key) { case Keys.Enter: Foley.PlayClickDown(); OnAccept(); break; case Keys.Escape: Foley.PlayClickDown(); OnCancel(); break; case Keys.Left: curBlob.CursorLeft(); Foley.PlayClickDown(); break; case Keys.Right: curBlob.CursorRight(); Foley.PlayClickDown(); break; case Keys.Home: Foley.PlayClickDown(); creatorBlob.Home(); break; case Keys.End: Foley.PlayClickDown(); curBlob.End(); break; case Keys.Back: curBlob.Backspace(); Foley.PlayClickDown(); break; case Keys.Delete: curBlob.Delete(); break; case Keys.Tab: ToggleEditTarget(); break; } // end of switch on special characters. } } // end of KeyInput()
public void TextInput(char c) { // Handle special character input. if (KeyboardInput.AltWasPressed) { specialChar = null; } if (KeyboardInput.AltIsPressed) { // accumulate keystrokes specialChar += c; return; } // Grab the tab and use it for cycling through the focus options. if (c == '\t') { ToggleEditTarget(); KeyboardInput.ClearAllWasPressedState(Keys.Tab); return; } if (EditingCreator || EditingPin) { // Ignore enter. if (c == 13) { return; } string str = new string(c, 1); str = TextHelper.FilterInvalidCharacters(str); if (!string.IsNullOrEmpty(str)) { // Check if we've gotten too long. if (EditingCreator) { creatorBlob.InsertString(str); int width = creatorBlob.GetLineWidth(0); if (width >= creatorBox.Width) { // Bzzzt! Foley.PlayNoBudget(); for (int i = 0; i < str.Length; i++) { creatorBlob.Backspace(); } } else { Foley.PlayClickDown(); } } else if (EditingPin) { // With the pin, max out at 4 digits and only allow digits. if (pinBlob.ScrubbedText.Length > 3 || !char.IsDigit(str[0])) { Foley.PlayNoBudget(); } else { pinBlob.InsertString(str); } } } } } // end of TextInput()