public override bool Key(SpecialKey key, bool up, char character) { if (!m_focused) { return(false); } if (up && key == SpecialKey.Back) { //SetFocused(false); if (OnTextEntered != null) { OnTextEntered(this, string.Empty); } return(true); } if (up && (key == SpecialKey.Enter)) { //SetFocused(false); if (OnTextEntered != null) { OnTextEntered(this, m_text); } return(true); } if (up && key == SpecialKey.Tab) { if (WidgetManager.FocusNext(this) && OnFocusLost != null) { OnFocusLost(this, m_text); } return(true); } if ((key == SpecialKey.Letter || key == SpecialKey.Paste) && m_font.HaveSymbol(character)) { m_text = m_text.Insert(m_cursorPosition, character.ToString()); if (OnTextChanged != null) { OnTextChanged(this, m_text); } UpdateCursor(1); return(true); } if (!up) { switch (key) { case SpecialKey.Backspace: if (m_cursorPosition > m_preffix.Length) { m_text = m_text.Substring(0, m_cursorPosition - 1) + m_text.Substring(m_cursorPosition); if (OnTextChanged != null) { OnTextChanged(this, m_text); } UpdateCursor(-1); } break; case SpecialKey.Delete: if (m_cursorPosition <= m_text.Length - 1) { m_text = m_text.Substring(0, m_cursorPosition) + m_text.Substring(m_cursorPosition + 1); if (OnTextChanged != null) { OnTextChanged(this, m_text); } UpdateCursor(0); } break; case SpecialKey.Left: if (m_cursorPosition > m_preffix.Length) { UpdateCursor(-1); } break; case SpecialKey.Right: if (m_cursorPosition <= m_text.Length - 1) { UpdateCursor(1); } break; } } switch (key) { case SpecialKey.Up: case SpecialKey.Down: return(false); } return(true); }
public override bool Key(SpecialKey key, bool up, string keyString) { if (!IsFocused) { return(false); } if (up && key == SpecialKey.Back) { //SetFocused(false); if (OnTextEntered != null) { OnTextEntered(this, string.Empty); } return(true); } if (up && (key == SpecialKey.Enter || key == SpecialKey.Joystick_Start)) { //SetFocused(false); if (OnTextEntered != null) { OnTextEntered(this, m_text); } return(true); } if (up && key == SpecialKey.Tab) { if (WidgetManager.FocusNext(this) && OnFocusLost != null) { OnFocusLost(this, m_text); } return(true); } if ((key == SpecialKey.Letter || key == SpecialKey.Paste) /* && Font.HaveSymbol(character)*/) { StringBuilder stringToAdd = new StringBuilder(keyString.Length); for (int i = 0; i < keyString.Length; i++) { if (Font.HaveSymbol(keyString[i])) { stringToAdd.Append(keyString[i]); } } if (stringToAdd.Length > 0) { string toAdd = stringToAdd.ToString(); if (m_cursorPosition == m_text.Length) { m_text += toAdd; } else { m_text = m_text.Insert(m_cursorPosition, toAdd); } if (OnTextChanged != null) { OnTextChanged(this, m_text); } m_cursorPosition += toAdd.Length; m_cursorLinePosition += toAdd.Length; Relayout(); return(true); } } if (!up) { switch (key) { case SpecialKey.Backspace: if (m_cursorPosition > 0) { m_text = m_text.Substring(0, m_cursorPosition - 1) + m_text.Substring(m_cursorPosition); if (OnTextChanged != null) { OnTextChanged(this, m_text); } m_cursorPosition--; m_cursorLinePosition--; Relayout(); } break; case SpecialKey.Delete: if (m_cursorPosition <= m_text.Length - 1) { m_text = m_text.Substring(0, m_cursorPosition) + m_text.Substring(m_cursorPosition + 1); if (OnTextChanged != null) { OnTextChanged(this, m_text); } Relayout(); } break; case SpecialKey.Enter: { if (m_cursorPosition == m_text.Length) { m_text += "\n"; } else { m_text = m_text.Insert(m_cursorPosition, "\n"); } if (OnTextChanged != null) { OnTextChanged(this, m_text); } m_cursorPosition++; m_cursorLine++; m_cursorLinePosition = 0; Relayout(); } break; case SpecialKey.Left: if (m_cursorPosition > 0) { UpdateCursor(-1, 0); } break; case SpecialKey.Right: if (m_cursorPosition <= m_text.Length - 1) { UpdateCursor(1, 0); } break; case SpecialKey.Home: if (m_cursorLinePosition > 0) { UpdateCursor(-m_cursorLinePosition, 0); } break; case SpecialKey.End: UpdateCursor(int.MaxValue, 0); break; case SpecialKey.Up: if (m_cursorLine > 0) { UpdateCursor(0, -1); } break; case SpecialKey.Down: if (m_cursorLine < m_lines.Length - 1) { UpdateCursor(0, 1); } break; } } return(true); }
public override bool Key(SpecialKey key, bool up, string keyString) { if (!IsFocused) { return(false); } if (!Enabled) { return(false); } if (OnKeyPressed != null && OnKeyPressed(this, key, keyString)) { return(true); } if (up && key == SpecialKey.Back) { if (OnTextEntered != null) { OnTextEntered(this, string.Empty); } return(true); } if (up && (key == SpecialKey.Enter || key == SpecialKey.Joystick_Start)) { if (OnTextEntered != null) { OnTextEntered(this, m_text); } return(true); } if (up && key == SpecialKey.Tab) { if (TabToValidate && OnTextEntered != null) { OnTextEntered(this, m_text); } if (WidgetManager.FocusNext(this) && OnFocusLost != null) { OnFocusLost(this, m_text); } return(true); } if ((key == SpecialKey.Letter || key == SpecialKey.Paste) /* && Font.HaveSymbol(character)*/) { // filter non-printable chars StringBuilder stringToAdd = new StringBuilder(keyString.Length); for (int i = 0; i < keyString.Length; i++) { if (Font.HaveSymbol(keyString[i])) { stringToAdd.Append(keyString[i]); } } if (stringToAdd.Length > 0) { string toAdd = stringToAdd.ToString(); // Input string validation. Only called on paste and input if (OnValidateInput != null && !OnValidateInput(m_text, toAdd)) { return(true); } if (m_cursorPosition == m_text.Length) { m_text += toAdd; } else { m_text = m_text.Insert(m_cursorPosition, toAdd); } if (OnTextChanged != null) { OnTextChanged(this, m_text); } m_cursorPosition += toAdd.Length; Relayout(); return(true); } } if (!up) { switch (key) { case SpecialKey.Backspace: if (m_cursorPosition > m_preffix.Length) { m_text = m_text.Substring(0, m_cursorPosition - 1) + m_text.Substring(m_cursorPosition); if (OnTextChanged != null) { OnTextChanged(this, m_text); } m_cursorPosition--; Relayout(); } break; case SpecialKey.Delete: if (m_cursorPosition <= m_text.Length - 1) { m_text = m_text.Substring(0, m_cursorPosition) + m_text.Substring(m_cursorPosition + 1); if (OnTextChanged != null) { OnTextChanged(this, m_text); } Relayout(); } break; case SpecialKey.Left: if (m_cursorPosition > m_preffix.Length) { UpdateCursor(-1); } break; case SpecialKey.Right: if (m_cursorPosition <= m_text.Length - 1) { UpdateCursor(1); } break; } } switch (key) { case SpecialKey.Up: case SpecialKey.Down: return(false); } return(true); }