Example #1
0
        ////////////////////////////////////////////////////////////////////////////
        void GamePadDownProcess(object sender, GamePadEventArgs e)
        {
            Control c = FocusedControl;

            if (c != null && CheckState(c))
            {
                if (states.Click == -1)
                {
                    states.Click = (int)e.Button;
                }
                states.Buttons[(int)e.Button] = c;
                c.SendMessage(Message.GamePadDown, e);

                if (e.Button == c.GamePadActions.Click)
                {
                    c.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
                }
            }
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        void GamePadUpProcess(object sender, GamePadEventArgs e)
        {
            Control c = states.Buttons[(int)e.Button];

            if (c != null)
            {
                if (e.Button == c.GamePadActions.Press)
                {
                    c.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
                }
                states.Click = -1;
                states.Buttons[(int)e.Button] = null;
                c.SendMessage(Message.GamePadUp, e);
            }
        }
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    private void BuildGamePadEvent(GamePadState state, GamePadButton button, ref GamePadEventArgs e)
    {      
      e.State = state;
      e.Button = button;   
      e.Vectors.LeftStick = new Vector2(state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y);
      e.Vectors.RightStick = new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y);
      e.Vectors.LeftTrigger = state.Triggers.Left;
      e.Vectors.RightTrigger = state.Triggers.Right;
    }
		////////////////////////////////////////////////////////////////////////////

		////////////////////////////////////////////////////////////////////////////
		protected override void OnGamePadDown(GamePadEventArgs e)
		{
			base.OnGamePadDown(e);
		}
Example #5
0
    ////////////////////////////////////////////////////////////////////////////     

    ////////////////////////////////////////////////////////////////////////////
    protected override void OnGamePadDown(GamePadEventArgs e)
    {
      if (!e.Handled)
      {        
        if (e.Button == GamePadActions.Click || e.Button == GamePadActions.Press || e.Button == GamePadActions.Down)
        {
          e.Handled = true;
          btnDown_Click(this, new MouseEventArgs());
        }
      }
      base.OnGamePadDown(e);
    }
Example #6
0
        /// <summary>
        /// Handles gamepad button down events for the text box.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGamePadDown(GamePadEventArgs e)
        {
            // Guide visible?
            if (Manager.UseGuide && Guide.IsVisible) return;

            if (!e.Handled)
            {
                // Clicking a text box with a gamepad?
                if (e.Button == GamePadActions.Click)
                {
                    // Display the on-screen keyboard.
                    e.Handled = true;
                    HandleGuide(e.PlayerIndex);
                }
            }
            base.OnGamePadDown(e);
        }
Example #7
0
        /// <summary>
        /// Handles gamepad button presses for the manager.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void GamePadPressProcess(object sender, GamePadEventArgs e)
        {
            Control c = states.Buttons[(int)e.Button];

            if (c != null)
            {
                // Send the gamepad button press message to the control.
                c.SendMessage(Message.GamePadPress, e);

                // Convert DPad buttons?
                if ((e.Button == c.GamePadActions.Right ||
                     e.Button == c.GamePadActions.Left ||
                     e.Button == c.GamePadActions.Up ||
                     e.Button == c.GamePadActions.Down) && !e.Handled && CheckButtons((int)e.Button))
                {
                    ProcessArrows(c, new KeyEventArgs(), e);
                    GamePadDownProcess(sender, e);
                }

                // Switch to next control if RightTrigger is pressed.
                else if (e.Button == c.GamePadActions.NextControl && !e.Handled && CheckButtons((int)e.Button))
                {
                    TabNextControl(c);
                    GamePadDownProcess(sender, e);
                }

                // Switch to previous control if LeftTrigger is pressed.
                else if (e.Button == c.GamePadActions.PrevControl && !e.Handled && CheckButtons((int)e.Button))
                {
                    TabPrevControl(c);
                    GamePadDownProcess(sender, e);
                }
            }
        }
Example #8
0
		protected virtual void OnGamePadPress(GamePadEventArgs e) {
			if (GamePadPress != null)
				GamePadPress.Invoke(this, e);
		}
Example #9
0
 /// <summary>
 /// Raises the Disconnected event. This is automatically raised by an appropriately configured
 /// GamePadEvents object, but this allows for programmatic raising of events.
 /// </summary>
 public void OnDisconnected(object sender, GamePadEventArgs args)
 {
     if (Disconnected != null) { Disconnected(sender, args); }
 }
Example #10
0
        /// <summary>
        /// Handles gamepad button down events for the manager.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void GamePadDownProcess(object sender, GamePadEventArgs e)
        {
            Control c = FocusedControl;

            // Is there a focused control?
            if (c != null && CheckState(c))
            {
                if (states.Click == -1)
                {
                    states.Click = (int)e.Button;
                }

                // Send the gamepad down message to the control.
                states.Buttons[(int)e.Button] = c;
                c.SendMessage(Message.GamePadDown, e);

                // Need to send a click event message if the click button was pressed.
                if (e.Button == c.GamePadActions.Click)
                {
                    c.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
                }
            }
        }
Example #11
0
        /// <summary>
        /// Handles gamepad button presses for the list box. Specifically, the up and down buttons.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGamePadPress(GamePadEventArgs e)
        {
            // Move selection down?
            if (e.Button == GamePadActions.Down)
            {
                e.Handled = true;
                itemIndex += sbVert.StepSize / 10;
            }

            // Move selection up?
            else if (e.Button == GamePadActions.Up)
            {
                e.Handled = true;
                itemIndex -= sbVert.StepSize / 10;
            }

            // Wrap index in collection range.
            if (itemIndex < 0) itemIndex = 0;
            else if (itemIndex >= Items.Count) itemIndex = Items.Count - 1;

            ItemIndex = itemIndex;
            base.OnGamePadPress(e);
        }
Example #12
0
 private void OnControllerDisconnected(object sender, GamePadEventArgs args)
 {
     if (ControllerDisconnected != null) ControllerDisconnected(sender, args);
 }
Example #13
0
 void ButtonUp(object sender, GamePadEventArgs e)
 {
 }
Example #14
0
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        protected override void OnGamePadPress(GamePadEventArgs e)
        {
            if (e.Button == GamePadActions.Down)
            {
                e.Handled = true;
                itemIndex += sbVert.StepSize / 10;
            }
            else if (e.Button == GamePadActions.Up)
            {
                e.Handled = true;
                itemIndex -= sbVert.StepSize / 10;
            }

            if (itemIndex < 0) itemIndex = 0;
            else if (itemIndex >= Items.Count) itemIndex = Items.Count - 1;

            ItemIndex = itemIndex;
            base.OnGamePadPress(e);
        }
Example #15
0
        /// <summary>
        /// Handles gamepad button up events for the manager.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void GamePadUpProcess(object sender, GamePadEventArgs e)
        {
            Control c = states.Buttons[(int)e.Button];

            if (c != null)
            {
                // Send click event message to the control if the gamepad X button pressed?
                if (e.Button == c.GamePadActions.Press)
                {
                    c.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
                }

                states.Click = -1;
                states.Buttons[(int)e.Button] = null;

                // Send gamepad button up message to the control.
                c.SendMessage(Message.GamePadUp, e);
            }
        }
Example #16
0
 private void GamePadListener_ButtonUp(object sender, GamePadEventArgs e)
 {
     _inputReceiver.InjectButtonRelease(e.Button);
 }
Example #17
0
        /// <summary>
        /// Processes up/down/left/right inputs for the manager.
        /// </summary>
        /// <param name="control">Control to process arrow keys for.</param>
        /// <param name="kbe">Key event arguments.</param>
        /// <param name="gpe">Gamepad event arguments.</param>
        private void ProcessArrows(Control control, KeyEventArgs kbe, GamePadEventArgs gpe)
        {
            Control c = control;

            // Control has siblings?
            if (c.Parent != null && c.Parent.Controls != null)
            {
                int index = -1;

                // Unhandled left arrow key or DPad left button press received?
                if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Left && !kbe.Handled) ||
                    (gpe.Button == c.GamePadActions.Left && !gpe.Handled))
                {
                    int miny = int.MaxValue;
                    int minx = int.MinValue;

                    // Check sibling controls to find the closest control to this one.
                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];

                        // Skip if this control is the same control, not visible, disabled, or cannot receive focus.
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        // Control vertical center.
                        int cay = (int)(c.Top + (c.Height / 2));

                        // Child control vertical center.
                        int cby = (int)(cx.Top + (cx.Height / 2));

                        // Difference between center points is the new minimum value and is the closest control to the left of the control?
                        if (Math.Abs(cay - cby) <= miny && (cx.Left + cx.Width) >= minx && (cx.Left + cx.Width) <= c.Left)
                        {
                            // Update minimum values and update index to the new closest control.
                            miny = Math.Abs(cay - cby);
                            minx = cx.Left + cx.Width;
                            index = i;
                        }
                    }
                }

                // Unhandled right arrow key or DPad right button press received?
                else if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Right && !kbe.Handled) ||
                         (gpe.Button == c.GamePadActions.Right && !gpe.Handled))
                {
                    int miny = int.MaxValue;
                    int minx = int.MaxValue;

                    // Check sibling controls to find the closest control to this one.
                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];

                        // Control is different, enabled, and can focus?
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        // Control vertical center.
                        int cay = (int)(c.Top + (c.Height / 2));

                        // Child control vertical center.
                        int cby = (int)(cx.Top + (cx.Height / 2));

                        // Difference between center points is the new minimum value and is the closest control to the right of the control?
                        if (Math.Abs(cay - cby) <= miny && cx.Left <= minx && cx.Left >= (c.Left + c.Width))
                        {
                            // Update minimum values and update index to the new closest control.
                            miny = Math.Abs(cay - cby);
                            minx = cx.Left;
                            index = i;
                        }
                    }
                }

                // Unhandled up arrow key or DPad up button press received?
                else if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Up && !kbe.Handled) ||
                         (gpe.Button == c.GamePadActions.Up && !gpe.Handled))
                {
                    int miny = int.MinValue;
                    int minx = int.MaxValue;

                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        int cax = (int)(c.Left + (c.Width / 2));
                        int cbx = (int)(cx.Left + (cx.Width / 2));

                        if (Math.Abs(cax - cbx) <= minx && (cx.Top + cx.Height) >= miny && (cx.Top + cx.Height) <= c.Top)
                        {
                            minx = Math.Abs(cax - cbx);
                            miny = cx.Top + cx.Height;
                            index = i;
                        }
                    }
                }

                // Unhandled down arrow key or DPad down button press received?
                else if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Down && !kbe.Handled) ||
                         (gpe.Button == c.GamePadActions.Down && !gpe.Handled))
                {
                    int miny = int.MaxValue;
                    int minx = int.MaxValue;

                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        int cax = (int)(c.Left + (c.Width / 2));
                        int cbx = (int)(cx.Left + (cx.Width / 2));

                        if (Math.Abs(cax - cbx) <= minx && cx.Top <= miny && cx.Top >= (c.Top + c.Height))
                        {
                            minx = Math.Abs(cax - cbx);
                            miny = cx.Top;
                            index = i;
                        }
                    }
                }

                // Index changed?
                if (index != -1)
                {
                    // Focus the new control and handle the input events.
                    (c.Parent.Controls as ControlsList)[index].Focused = true;
                    kbe.Handled = true;
                    gpe.Handled = true;
                }
            }
        }
		////////////////////////////////////////////////////////////////////////////

		////////////////////////////////////////////////////////////////////////////
		protected override void OnGamePadPress(GamePadEventArgs e)
		{
			base.OnGamePadPress(e);

			if (e.Button == GamePadActions.Right)
			{
				ItemIndex += 1;
				e.Handled = true;
			}
			if (e.Button == GamePadActions.Left)
			{
				ItemIndex -= 1;
				e.Handled = true;
			}

			if (ItemIndex > Items.Count - 1) ItemIndex = 0;
			if (ItemIndex < 0) ItemIndex = Items.Count - 1;

			if (e.Button == GamePadActions.Down && Items[ItemIndex].Items.Count > 0)
			{
				e.Handled = true;
				OnClick(new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
			}
		}
Example #19
0
        ////////////////////////////////////////////////////////////////////////////        
        ////////////////////////////////////////////////////////////////////////////        
        protected override void OnGamePadDown(GamePadEventArgs e)
        {
            if (Manager.UseGuide && Guide.IsVisible) return;

              if (!e.Handled)
              {
            if (e.Button == GamePadActions.Click)
            {
              e.Handled = true;
              HandleGuide(e.PlayerIndex);
            }
              }
              base.OnGamePadDown(e);
        }
Example #20
0
        /// <summary>
        /// Handles game pad button press events for the main menu.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGamePadPress(GamePadEventArgs e)
        {
            base.OnGamePadPress(e);

            // Left and right DPad buttons navigate through menus.
            if (e.Button == GamePadActions.Right)
            {
                ItemIndex += 1;
                e.Handled = true;
            }

            if (e.Button == GamePadActions.Left)
            {
                ItemIndex -= 1;
                e.Handled = true;
            }

            // Wrap selected index.
            if (ItemIndex > Items.Count - 1) ItemIndex = 0;
            if (ItemIndex < 0) ItemIndex = Items.Count - 1;

            // Open the selected menu on DPad Down.
            if (e.Button == GamePadActions.Down && Items[ItemIndex].Items.Count > 0)
            {
                e.Handled = true;
                OnClick(new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
            }
        }
Example #21
0
        /// <summary>
        /// Updates the state of the gamepad with the specified player index and raises 
        /// applicable gamepad events as needed.
        /// </summary>
        /// <param name="playerIndex">PlayerIndex of the gamepad to update the state of.</param>
        /// <param name="state">The new state to assign to the gamepad.</param>
        /// <param name="gameTime">Snapshot of the application's timing values.</param>
        private void UpdateGamePad(PlayerIndex playerIndex, GamePadState state, GameTime gameTime)
        {
            GamePadEventArgs e = new GamePadEventArgs(playerIndex);

            // Check for changes in stick and trigger values.
            if (state.ThumbSticks.Left != gamePadState.ThumbSticks.Left ||
                state.ThumbSticks.Right != gamePadState.ThumbSticks.Right ||
                state.Triggers.Left != gamePadState.Triggers.Left ||
                state.Triggers.Right != gamePadState.Triggers.Right)
            {
                BuildGamePadEvent(state, GamePadButton.None, ref e);
                if (GamePadMove != null) GamePadMove.Invoke(this, e);
            }

            // Update the states of the gamepad buttons in the list.
            foreach (InputGamePadButton btn in gamePadButtons)
            {
                // Current button state of the current gamepad button.
                ButtonState bs = ButtonState.Released;

                if (btn.Button == GamePadButton.None) continue;
                else if (btn.Button == GamePadButton.A) bs = state.Buttons.A;
                else if (btn.Button == GamePadButton.B) bs = state.Buttons.B;
                else if (btn.Button == GamePadButton.Back) bs = state.Buttons.Back;
                else if (btn.Button == GamePadButton.Down) bs = state.DPad.Down;
                else if (btn.Button == GamePadButton.Left) bs = state.DPad.Left;
                else if (btn.Button == GamePadButton.Right) bs = state.DPad.Right;
                else if (btn.Button == GamePadButton.Start) bs = state.Buttons.Start;
                else if (btn.Button == GamePadButton.Up) bs = state.DPad.Up;
                else if (btn.Button == GamePadButton.X) bs = state.Buttons.X;
                else if (btn.Button == GamePadButton.Y) bs = state.Buttons.Y;
                else if (btn.Button == GamePadButton.BigButton) bs = state.Buttons.BigButton;
                else if (btn.Button == GamePadButton.LeftShoulder) bs = state.Buttons.LeftShoulder;
                else if (btn.Button == GamePadButton.RightShoulder) bs = state.Buttons.RightShoulder;
                else if (btn.Button == GamePadButton.LeftStick) bs = state.Buttons.LeftStick;
                else if (btn.Button == GamePadButton.RightStick) bs = state.Buttons.RightStick;
                else bs = GetVectorState(btn.Button, state);

                // Current state button pressed?
                bool pressed = (bs == ButtonState.Pressed);

                if (pressed)
                {
                    // Update the repeat delay timer for the associated button.
                    double ms = gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (pressed) btn.Countdown -= ms;
                }

                // Button was just pressed?
                if ((pressed) && (!btn.Pressed))
                {
                    // "Press" the associated button.
                    btn.Pressed = true;
                    BuildGamePadEvent(state, btn.Button, ref e);

                    // Fire the GamePadDown event and the initial GamePadPress event.
                    if (GamePadDown != null) GamePadDown.Invoke(this, e);
                    if (GamePadPress != null) GamePadPress.Invoke(this, e);
                }

                // Button was just released?
                else if ((!pressed) && (btn.Pressed))
                {
                    // "Release" the associated button and reset the repeat delay timer.
                    btn.Pressed = false;
                    btn.Countdown = RepeatDelay;
                    BuildGamePadEvent(state, btn.Button, ref e);

                    // Fire the GamePadUp event.
                    if (GamePadUp != null) GamePadUp.Invoke(this, e);
                }

                // Button is held down and it's time to fire a repeat press event?
                else if (btn.Pressed && btn.Countdown < 0)
                {
                    // Update event args and reset timer.
                    e.Button = btn.Button;
                    btn.Countdown = RepeatRate;
                    BuildGamePadEvent(state, btn.Button, ref e);

                    // Fire the repeated GamePadPress event.
                    if (GamePadPress != null) GamePadPress.Invoke(this, e);
                }
            }
            gamePadState = state;
        }
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    private void UpdateGamePad(PlayerIndex playerIndex, GamePadState state, GameTime gameTime)
    {          
      GamePadEventArgs e = new GamePadEventArgs(playerIndex);      
      
      if (state.ThumbSticks.Left != gamePadState.ThumbSticks.Left ||
          state.ThumbSticks.Right != gamePadState.ThumbSticks.Right ||
          state.Triggers.Left != gamePadState.Triggers.Left ||
          state.Triggers.Right != gamePadState.Triggers.Right)
      {
        BuildGamePadEvent(state, GamePadButton.None, ref e);
        if (GamePadMove != null) GamePadMove.Invoke(this, e);        
      }           

      foreach (InputGamePadButton btn in gamePadButtons)
      {
        ButtonState bs = ButtonState.Released;

        if (btn.Button == GamePadButton.None) continue;
        else if (btn.Button == GamePadButton.A) bs = state.Buttons.A;
        else if (btn.Button == GamePadButton.B) bs = state.Buttons.B;
        else if (btn.Button == GamePadButton.Back) bs = state.Buttons.Back;
        else if (btn.Button == GamePadButton.Down) bs = state.DPad.Down;
        else if (btn.Button == GamePadButton.Left) bs = state.DPad.Left;
        else if (btn.Button == GamePadButton.Right) bs = state.DPad.Right;
        else if (btn.Button == GamePadButton.Start) bs = state.Buttons.Start;
        else if (btn.Button == GamePadButton.Up) bs = state.DPad.Up;
        else if (btn.Button == GamePadButton.X) bs = state.Buttons.X;
        else if (btn.Button == GamePadButton.Y) bs = state.Buttons.Y;
        else if (btn.Button == GamePadButton.BigButton) bs = state.Buttons.BigButton;
        else if (btn.Button == GamePadButton.LeftShoulder) bs = state.Buttons.LeftShoulder;
        else if (btn.Button == GamePadButton.RightShoulder) bs = state.Buttons.RightShoulder;
        else if (btn.Button == GamePadButton.LeftStick) bs = state.Buttons.LeftStick;
        else if (btn.Button == GamePadButton.RightStick) bs = state.Buttons.RightStick;                        
        else bs = GetVectorState(btn.Button, state);
        
        bool pressed = (bs == ButtonState.Pressed);
        if (pressed)
        {
          double ms = gameTime.ElapsedGameTime.TotalMilliseconds;          
          if (pressed) btn.Countdown -= ms;
        }

        if ((pressed) && (!btn.Pressed))
        {
          btn.Pressed = true;
          BuildGamePadEvent(state, btn.Button, ref e);

          if (GamePadDown != null) GamePadDown.Invoke(this, e);
          if (GamePadPress != null) GamePadPress.Invoke(this, e);
        }
        else if ((!pressed) && (btn.Pressed))
        {
          btn.Pressed = false;
          btn.Countdown = RepeatDelay;
          BuildGamePadEvent(state, btn.Button, ref e);

          if (GamePadUp != null) GamePadUp.Invoke(this, e);
        }
        else if (btn.Pressed && btn.Countdown < 0)
        {
          e.Button = btn.Button;
          btn.Countdown = RepeatRate;          
          BuildGamePadEvent(state, btn.Button, ref e);

          if (GamePadPress != null) GamePadPress.Invoke(this, e);          
        }
      }    
      gamePadState = state;
    }
Example #23
0
		private void GamePadPressProcess(GamePadEventArgs e) {
			Invalidate();
			if (!Suspended)
				OnGamePadPress(e);
		}
Example #24
0
		////////////////////////////////////////////////////////////////////////////

		////////////////////////////////////////////////////////////////////////////
		protected override void OnGamePadPress(GamePadEventArgs e)
		{
			if (e.Button == GamePadActions.Up)
			{
				e.Handled = true;
				ShiftIndex(true);
			}
			else if (e.Button == GamePadActions.Down)
			{
				e.Handled = true;
				ShiftIndex(false);
			}

			base.OnGamePadPress(e);
		}
Example #25
0
		private void GamePadUpProcess(GamePadEventArgs e) {
			Invalidate();

			if (e.Button == GamePadActions.Press && pressed[(int)e.Button]) {
				pressed[(int)e.Button] = false;
			}

			if (!Suspended)
				OnGamePadUp(e);

			if (e.Button == GamePadActions.ContextMenu && !e.Handled) {
				if (contextMenu != null) {
					contextMenu.Show(this, AbsoluteLeft + 8, AbsoluteTop + 8);
				}
			}
		}
Example #26
0
        /// <summary>
        /// Handles button press events for the context menu.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGamePadPress(GamePadEventArgs e)
        {
            timer = 0;

            if (e.Button == GamePadButton.None) return;

            // Move to the next menu entry on Down or Right Shoulder button presses.
            if (e.Button == GamePadActions.Down || e.Button == GamePadActions.NextControl)
            {
                e.Handled = true;
                ItemIndex += 1;
            }

            // Move to the previous menu entry on Up or Left Shoulder button presses.
            else if (e.Button == GamePadActions.Up || e.Button == GamePadActions.PrevControl)
            {
                e.Handled = true;
                ItemIndex -= 1;
            }

            // Wrap selected index in range.
            if (ItemIndex > Items.Count - 1) ItemIndex = 0;
            if (ItemIndex < 0) ItemIndex = Items.Count - 1;

            // Open child menu, if there is one, when the Right button is pressed.
            if (e.Button == GamePadActions.Right && Items[ItemIndex].Items.Count > 0)
            {
                e.Handled = true;
                OnClick(new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
            }

            // Close child menu, if there is one, when the Left button is pressed.
            if (e.Button == GamePadActions.Left)
            {
                e.Handled = true;
                if (ParentMenu != null && ParentMenu is ContextMenu)
                {
                    (ParentMenu as ContextMenu).Focused = true;
                    (ParentMenu as ContextMenu).HideMenu(false);
                }
            }

            base.OnGamePadPress(e);
        }
Example #27
0
		private void GamePadDownProcess(GamePadEventArgs e) {
			Invalidate();

			ToolTipOut();

			if (e.Button == GamePadActions.Press && !IsPressed) {
				pressed[(int)e.Button] = true;
			}

			if (!Suspended)
				OnGamePadDown(e);
		}
Example #28
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        void GamePadPressProcess(object sender, GamePadEventArgs e)
        {
            Control c = states.Buttons[(int)e.Button];
            if (c != null)
            {
                c.SendMessage(Message.GamePadPress, e);

                if ((e.Button == c.GamePadActions.Right ||
                     e.Button == c.GamePadActions.Left ||
                     e.Button == c.GamePadActions.Up ||
                     e.Button == c.GamePadActions.Down) && !e.Handled && CheckButtons((int)e.Button))
                {
                    ProcessArrows(c, new KeyEventArgs(), e);
                    GamePadDownProcess(sender, e);
                }
                else if (e.Button == c.GamePadActions.NextControl && !e.Handled && CheckButtons((int)e.Button))
                {
                    TabNextControl(c);
                    GamePadDownProcess(sender, e);
                }
                else if (e.Button == c.GamePadActions.PrevControl && !e.Handled && CheckButtons((int)e.Button))
                {
                    TabPrevControl(c);
                    GamePadDownProcess(sender, e);
                }
            }
        }
Example #29
0
		protected virtual void OnGamePadUp(GamePadEventArgs e) {
			if (GamePadUp != null)
				GamePadUp.Invoke(this, e);
		}
Example #30
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////    
        private void ProcessArrows(Control control, KeyEventArgs kbe, GamePadEventArgs gpe)
        {
            Control c = control;
            if (c.Parent != null && c.Parent.Controls != null)
            {
                int index = -1;

                if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Left && !kbe.Handled) ||
                    (gpe.Button == c.GamePadActions.Left && !gpe.Handled))
                {
                    int miny = int.MaxValue;
                    int minx = int.MinValue;
                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        int cay = (int)(c.Top + (c.Height / 2));
                        int cby = (int)(cx.Top + (cx.Height / 2));

                        if (Math.Abs(cay - cby) <= miny && (cx.Left + cx.Width) >= minx && (cx.Left + cx.Width) <= c.Left)
                        {
                            miny = Math.Abs(cay - cby);
                            minx = cx.Left + cx.Width;
                            index = i;
                        }
                    }
                }
                else if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Right && !kbe.Handled) ||
                         (gpe.Button == c.GamePadActions.Right && !gpe.Handled))
                {
                    int miny = int.MaxValue;
                    int minx = int.MaxValue;
                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        int cay = (int)(c.Top + (c.Height / 2));
                        int cby = (int)(cx.Top + (cx.Height / 2));

                        if (Math.Abs(cay - cby) <= miny && cx.Left <= minx && cx.Left >= (c.Left + c.Width))
                        {
                            miny = Math.Abs(cay - cby);
                            minx = cx.Left;
                            index = i;
                        }
                    }
                }
                else if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Up && !kbe.Handled) ||
                         (gpe.Button == c.GamePadActions.Up && !gpe.Handled))
                {
                    int miny = int.MinValue;
                    int minx = int.MaxValue;
                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        int cax = (int)(c.Left + (c.Width / 2));
                        int cbx = (int)(cx.Left + (cx.Width / 2));

                        if (Math.Abs(cax - cbx) <= minx && (cx.Top + cx.Height) >= miny && (cx.Top + cx.Height) <= c.Top)
                        {
                            minx = Math.Abs(cax - cbx);
                            miny = cx.Top + cx.Height;
                            index = i;
                        }
                    }
                }
                else if ((kbe.Key == Microsoft.Xna.Framework.Input.Keys.Down && !kbe.Handled) ||
                         (gpe.Button == c.GamePadActions.Down && !gpe.Handled))
                {
                    int miny = int.MaxValue;
                    int minx = int.MaxValue;
                    for (int i = 0; i < (c.Parent.Controls as ControlsList).Count; i++)
                    {
                        Control cx = (c.Parent.Controls as ControlsList)[i];
                        if (cx == c || !cx.Visible || !cx.Enabled || cx.Passive || !cx.CanFocus) continue;

                        int cax = (int)(c.Left + (c.Width / 2));
                        int cbx = (int)(cx.Left + (cx.Width / 2));

                        if (Math.Abs(cax - cbx) <= minx && cx.Top <= miny && cx.Top >= (c.Top + c.Height))
                        {
                            minx = Math.Abs(cax - cbx);
                            miny = cx.Top;
                            index = i;
                        }
                    }
                }

                if (index != -1)
                {
                    (c.Parent.Controls as ControlsList)[index].Focused = true;
                    kbe.Handled = true;
                    gpe.Handled = true;
                }
            }
        }
Example #31
0
		protected virtual void OnGamePadDown(GamePadEventArgs e) {
			if (GamePadDown != null)
				GamePadDown.Invoke(this, e);
		}
Example #32
0
		protected override void OnGamePadPress(GamePadEventArgs e) {
			timer = 0;

			if (e.Button == EGamePadButton.None)
				return;

			if (e.Button == GamePadActions.Down || e.Button == GamePadActions.NextControl) {
				e.Handled = true;
				ItemIndex += 1;
			} else if (e.Button == GamePadActions.Up || e.Button == GamePadActions.PrevControl) {
				e.Handled = true;
				ItemIndex -= 1;
			}

			if (ItemIndex > Items.Count - 1)
				ItemIndex = 0;
			if (ItemIndex < 0)
				ItemIndex = Items.Count - 1;

			if (e.Button == GamePadActions.Right && Items[ItemIndex].Items.Count > 0) {
				e.Handled = true;
				OnClick(new MouseEventArgs(new MouseState(), EMouseButton.None, Point.Zero));
			}
			if (e.Button == GamePadActions.Left) {
				e.Handled = true;
				if (ParentMenu != null && ParentMenu is ContextMenu) {
					(ParentMenu as ContextMenu).Focused = true;
					(ParentMenu as ContextMenu).HideMenu(false);
				}
			}

			base.OnGamePadPress(e);
		}
Example #33
0
 protected virtual void OnButtonUp(GamePadEventArgs e)
 {
 }