public override void HandleInput(InputControl input, bool inFocus) { if (inFocus) { if (input.MousePressed(1)) { if (input.MouseX() > Position.X && input.MouseX() < (Position.X + width) && input.MouseY() > Position.Y && input.MouseY() < (Position.Y + height)) { isSelected = true; } else { isSelected = false; } } if (isSelected) { foreach (Keys key in keysToCheck) { if (input.KeyPressed(key) && (OnKeyPressed == null || !OnKeyPressed(this, key))) { switch (key) { case (Keys.Back): if (textValue.Length > 0 && index > 0) { textValue = textValue.Remove(index - 1, 1); index--; } break; case (Keys.Enter): if(Submitted != null) Submitted(this); index = 0; break; case (Keys.Space): textValue += " "; break; case (Keys.Left): if (index > 0) index--; break; case (Keys.Right): if (index < textValue.Count()) index++; break; default: string charToAdd = key.ToString(); if (!input.KeyDown(Keys.RightShift) && !input.KeyDown(Keys.LeftShift)) { charToAdd = charToAdd.ToLower(); } if (textValue.Length < this.max) { textValue += charToAdd; index++; } break; } } } } } }
/// <summary> /// Handles the input provided by the ScreenManager's InputControl. You should not need to override this - use the specialized input methods instead! /// </summary> /// <param name="input">The InputControl object passed in from the ScreenManager.</param> public override void HandleInput(InputControl input) { base.HandleInput(input); //store mouse pos Point mousePos = input.CurrentMouse; //check for a widget at mouse point Widget widgetAtPoint = baseWidget.ChildAtPoint(mousePos, HitFlags.Mouse); //handle mouse movement bool cascade = true; if (input.MouseMoved()) { //check for mouse enter/leave events if (widgetAtPoint != mouseHoverWidget) { if (mouseHoverWidget != null) cascade = !mouseHoverWidget.MouseLeave(mousePos); mouseHoverWidget = widgetAtPoint; if (mouseHoverWidget != null) cascade &= !mouseHoverWidget.MouseEnter(mousePos); } if (cascade) MouseMove(mousePos,input.PreviousMouse); } //handle mouse clicks for (int i = 1; i <= 5; i++) { ButtonState current; if (input.MouseChanged(i,out current)) { cascade = true; if (current == ButtonState.Pressed) { mouseDownWidgets[i-1] = widgetAtPoint; if (widgetAtPoint != null) cascade = !widgetAtPoint.MouseDown(mousePos, i); if (cascade) MouseDown(mousePos, i); } else { if (mouseDownWidgets[i-1] != null) cascade = !mouseDownWidgets[i - 1].MouseUp(mousePos, i); mouseDownWidgets[i-1] = null; if (cascade) MouseUp(mousePos, i); } } } //check keyboard events for (int i = 0; i < watchedKeys.Length; i++) { if (input.KeyReleased(watchedKeys[i])) { cascade = true; if (selectedWidget != null) cascade = !selectedWidget.KeyUp(watchedKeys[i]); if (cascade) KeyUp(watchedKeys[i]); } if (input.KeyPressed(watchedKeys[i])) { cascade = true; if (selectedWidget != null) cascade = !selectedWidget.KeyDown(watchedKeys[i]); if (cascade) KeyDown(watchedKeys[i]); } } }