コード例 #1
0
ファイル: Help.cs プロジェクト: Ben-Cortina/Times-Table
 /// <summary>
 /// Checks whether or not the mouse is over a button
 /// </summary>
 /// <returns>returns the row and column of the focused button</returns>
 public Vector2 CheckFocus(List<ButtonMenu> buttons, InputState input)
 {
     Vector2 focus = new Vector2(-1, -1);
     foreach (Button b in buttons)
     {
         b.IsPressed = false;
         if (b.CheckFocus(input.MouseState.X, input.MouseState.Y))
         {
             focus.Y = b.Row;
             focus.X = b.Col;
             if (input.IsNewMouseReleased())
             {
                 b.IsPressed = true;
             }
         }
     }
     return focus;
 }
コード例 #2
0
ファイル: Test.cs プロジェクト: Ben-Cortina/Times-Table
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public void HandleInput(InputState input)
        {
            Vector2 mouseFocus = new Vector2(-1, -1);

            // Check NumPad and Number Keys for manual number entering
            String keyString;
            Keys key = new Keys();
            int keyboardInt = -1;
            for (int i = 0; i < 10; i++)
            {
                keyString = "D" + i.ToString();
                key = (Keys)Enum.Parse(typeof(Keys), keyString);
                if (input.IsNewKeyPress(key))
                    keyboardInt = i;
                keyString = "NumPad" + i.ToString();
                key = (Keys)Enum.Parse(typeof(Keys), keyString);
                if (input.IsNewKeyPress(key))
                    keyboardInt = i;
            }

            if (keyboardInt != -1)
                AddToAnswer(keyboardInt.ToString());

            if ( input.IsMouseChanged() ||input.IsMousePressed())
                mouseFocus = buttonTable.CheckFocus(input);

            if (mouseFocus.X != -1)
            {
                focus = mouseFocus;
                if (input.IsNewMouseReleased())
                    HandleButtonInput();
            }
            else
            {
                buttonTable.SetPressed(focus, false);
                buttonTable.SetFocus(focus, false);
                // Move up?
                if (input.IsMenuUp())
                {
                    focus = new Vector2(focus.X, focus.Y - 1);

                    if (focus.Y < 1)
                        focus.Y = buttonTable.Rows;
                }

                // Move down?
                if (input.IsMenuDown())
                {
                    focus = new Vector2(focus.X, focus.Y + 1);

                    if (focus.Y > buttonTable.Rows)
                        focus.Y = 1;
                }

                // Move left?
                if (input.IsMenuLeft())
                {
                    focus = new Vector2(focus.X - 1, focus.Y);

                    if (focus.X < 1)
                        focus.X = buttonTable.Cols;
                }

                // Move right?
                if (input.IsMenuRight())
                {
                    focus = new Vector2(focus.X + 1, focus.Y);

                    if (focus.X > buttonTable.Cols)
                        focus.X = 1;
                }
                buttonTable.SetFocus(focus, true);
            }

            // Check if the button is being pressed or if the user
            // is asking to exit the screen.

            if (input.IsMenuSelect())
            {
                HandleButtonInput();
                buttonTable.SetPressed(focus, true);
            }
            else if (input.IsMenuCancel())
            {
                Exiting = true;
            }
        }