/// <summary> /// Allows the screen to handle user input. Unlike Update, this method /// is only called when the screen is active, and not when some other /// screen has taken the focus. /// </summary> public virtual void HandleInput(InputState input) { }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> /// public override void HandleInput(InputState input) { TouchCollection touchState = TouchPanel.GetState(); bool touchDetected = false; Vector2 touchPosition = new Vector2(); //interpert touch screen presses foreach (TouchLocation location in touchState) { switch (location.State) { case TouchLocationState.Pressed: touchDetected = true; touchPosition = location.Position; break; case TouchLocationState.Moved: break; case TouchLocationState.Released: break; } } if (touchDetected) { foreach (MenuEntry menuEntry in menuEntries) { Rectangle touchRect = new Rectangle((int)touchPosition.X - 5, (int)touchPosition.Y - 5, 10, 10); if (menuEntry.EntryPosition.Intersects(touchRect)) menuEntry.OnSelectEntry(); } } // Move to the previous menu entry? if (input.MenuUp) { selectedEntry--; if (selectedEntry < 0) selectedEntry = menuEntries.Count - 1; } // Move to the next menu entry? if (input.MenuDown) { selectedEntry++; if (selectedEntry >= menuEntries.Count) selectedEntry = 0; } // Accept or cancel the menu? if (input.MenuSelect) { OnSelectEntry(selectedEntry); } else if (input.MenuCancel) { OnCancel(); } }