Ejemplo n.º 1
0
        private static int ButtonToTicks(GamePadButton padDirection)
        {
            switch (padDirection)
            {
            case GamePadButton.PadUp:
                return(0);

            case GamePadButton.PadUp | GamePadButton.PadRight:
                return(1);

            case GamePadButton.PadRight:
                return(2);

            case GamePadButton.PadRight | GamePadButton.PadDown:
                return(3);

            case GamePadButton.PadDown:
                return(4);

            case GamePadButton.PadDown | GamePadButton.PadLeft:
                return(5);

            case GamePadButton.PadLeft:
                return(6);

            case GamePadButton.PadLeft | GamePadButton.PadUp:
                return(7);

            default:
                return(-1);
            }
        }
Ejemplo n.º 2
0
 private bool IsDpadButton(GamePadButton button)
 {
     return(button == GamePadButton.DPadUp ||
            button == GamePadButton.DPadDown ||
            button == GamePadButton.DPadLeft ||
            button == GamePadButton.DPadRight);
 }
Ejemplo n.º 3
0
        private void UpdateButton(XnaInput.ButtonState newState, GamePadButton button)
        {
            var buttonIndex = (int)button;

            states[buttonIndex] =
                states[buttonIndex].UpdateOnNativePressing(newState == XnaInput.ButtonState.Pressed);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadButtonDown_DropDownClosed(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                IsDropDownOpen = true;
                data.Handled   = true;
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                    case GamePadButton.DPadUp:
                    case GamePadButton.DPadLeft:
                        MoveItemSelection(-1);
                        break;

                    case GamePadButton.DPadDown:
                    case GamePadButton.DPadRight:
                        MoveItemSelection(1);
                        break;
                    }
                    data.Handled = true;
                }
            }
        }
Ejemplo n.º 5
0
 public GamePadButtonInfo(GamePadController controller, GamePadButton button, bool pressed, bool prevPressed)
 {
     this.controller  = controller;
     this.button      = button;
     this.pressed     = pressed;
     this.prevPressed = prevPressed;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Activates the "pressed" or released script for a specific button.
 /// </summary>
 /// <param name="btn">The button.</param>
 /// <param name="pressed">Whether the button is pressed.</param>
 public void Activate(GamePadButton btn, bool pressed)
 {
     if (pressed)
     {
         if (!WasDown[(int)btn] || TheClient.GlobalTickTimeLocal - StartedTime[(int)btn] > PressRepTime)
         {
             if (ButtonBinds[(int)btn] != null)
             {
                 CommandQueue queue = ButtonBinds[(int)btn].ToQueue(TheClient.Commands.CommandSystem);
                 queue.CommandStack.Peek().Debug = DebugMode.MINIMAL;
                 queue.Execute();
             }
         }
         if (StartedTime[(int)btn] == 0)
         {
             StartedTime[(int)btn] = TheClient.GlobalTickTimeLocal;
         }
     }
     else if (!pressed && WasDown[(int)btn])
     {
         if (ButtonInverseBinds[(int)btn] != null)
         {
             CommandQueue queue = ButtonInverseBinds[(int)btn].ToQueue(TheClient.Commands.CommandSystem);
             queue.CommandStack.Peek().Debug = DebugMode.MINIMAL;
             queue.Execute();
         }
         StartedTime[(int)btn] = 0;
     }
     WasDown[(int)btn] = pressed;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadButtonDown_DropDownClosed(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                IsDropDownOpen = true;
                data.Handled   = true;
            }
            else
            {
                switch (button)
                {
                case GamePadButton.LeftStickUp:
                case GamePadButton.LeftStickLeft:
                    MoveItemSelection(-1);
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickDown:
                case GamePadButton.LeftStickRight:
                    MoveItemSelection(1);
                    data.Handled = true;
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Attempts to perform navigation as a result of the specified game pad button press.
        /// </summary>
        /// <param name="view">The view for which to perform navigation.</param>
        /// <param name="device">The game pad device that raised the button press event.</param>
        /// <param name="button">The button that was pressed.</param>
        /// <returns><c>true</c> if navigation was performed; otherwise, <c>false</c>.</returns>
        public static Boolean PerformNavigation(PresentationFoundationView view, GamePadDevice device, GamePadButton button)
        {
            Contract.Require(view, "view");

            var element = (view.ElementWithFocus ?? view.LayoutRoot) as UIElement;
            if (element == null)
                return false;

            if (GamePad.TabButton == button)
                return PerformNavigation(view, element, FocusNavigationDirection.Next, false);

            if (GamePad.ShiftTabButton == button)
                return PerformNavigation(view, element, FocusNavigationDirection.Previous, false);

            if (!GamePad.UseAxisForDirectionalNavigation)
            {
                switch (button)
                {
                    case GamePadButton.DPadUp:
                        return PerformNavigation(view, element, FocusNavigationDirection.Up, false);

                    case GamePadButton.DPadDown:
                        return PerformNavigation(view, element, FocusNavigationDirection.Down, false);

                    case GamePadButton.DPadLeft:
                        return PerformNavigation(view, element, FocusNavigationDirection.Left, false);

                    case GamePadButton.DPadRight:
                        return PerformNavigation(view, element, FocusNavigationDirection.Right, false);
                }
            }

            return false;
        }
Ejemplo n.º 9
0
 public InputAction(GamePadButton myButton, bool myNewPressOnly,int myPlayer)
 {
     gamePadButton = myButton;
     newPressOnly = myNewPressOnly;
     inputType = InputType.gamepad;
     playerIndex = myPlayer;
 }
Ejemplo n.º 10
0
        internal static void HandleKeyUp(int deviceId, Keycode keyCode)
        {
            int num = TranslateDeviceId(deviceId);

            if (num < 0)
            {
                return;
            }
            GamePadButton gamePadButton = TranslateKey(keyCode);

            if (gamePadButton >= GamePadButton.A)
            {
                m_states[num].Buttons[(int)gamePadButton] = false;
                return;
            }
            switch (keyCode)
            {
            case Keycode.ButtonL2:
                m_states[num].Triggers[0] = 0f;
                break;

            case Keycode.ButtonR2:
                m_states[num].Triggers[1] = 0f;
                break;
            }
        }
Ejemplo n.º 11
0
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        private ButtonState GetVectorState(GamePadButton button, GamePadState state)
        {
            ButtonState ret  = ButtonState.Released;
            bool        down = false;
            float       t    = ClickThreshold;

            switch (button)
            {
            case GamePadButton.LeftStickLeft: down = state.ThumbSticks.Left.X < -t; break;

            case GamePadButton.LeftStickRight: down = state.ThumbSticks.Left.X > t; break;

            case GamePadButton.LeftStickUp: down = state.ThumbSticks.Left.Y > t; break;

            case GamePadButton.LeftStickDown: down = state.ThumbSticks.Left.Y < -t; break;

            case GamePadButton.RightStickLeft: down = state.ThumbSticks.Right.X < -t; break;

            case GamePadButton.RightStickRight: down = state.ThumbSticks.Right.X > t; break;

            case GamePadButton.RightStickUp: down = state.ThumbSticks.Right.Y > t; break;

            case GamePadButton.RightStickDown: down = state.ThumbSticks.Right.Y < -t; break;

            case GamePadButton.LeftTrigger: down = state.Triggers.Left > t; break;

            case GamePadButton.RightTrigger: down = state.Triggers.Right > t; break;
            }

            ret = down ? ButtonState.Pressed : ButtonState.Released;

            return(ret);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Make a new game button from the player index, key, and game pad button.
 /// </summary>
 /// <param name="playerIndex">Player index.</param>
 /// <param name="key">Key to define.</param>
 /// <param name="gamePadButtons">Game pad button.</param>
 /// <param name="fireDelay">How long to wait before raising the fired event.</param>
 public GameButton(PlayerIndex playerIndex, Keys key, GamePadButton gamePadButtons, long fireDelay = 1000)
 {
     PlayerIndex    = playerIndex;
     Key            = key;
     GamePadButtons = gamePadButtons;
     FireDelay      = fireDelay;
 }
        public static bool IsGamePadButtonDown(this InputManager input, GamePadButton button, int index)
        {
            if (input.GamePadCount < index)
                return false;

            return (input.GetGamePad(index).Buttons & button) == button;
        }
Ejemplo n.º 14
0
 public static bool Upward(GamePadButton button, int padIndex)
 {
     if (padIndex < 0)
     {
         throw new System.Exception("padIndex must be non-negative, but is '" + padIndex + "'");
     }
     return(Upward(button, (uint)padIndex));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Adds a mapping from a button index to <see cref="GamePadButton"/>
 /// </summary>
 /// <param name="index">The button index of the button on this device</param>
 /// <param name="button">The button(s) to map to</param>
 protected void AddButtonToButton(int index, GamePadButton button)
 {
     while (buttonMap.Count <= index)
     {
         buttonMap.Add(GamePadButton.None);
     }
     buttonMap[index] = button;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Adds a mapping from an axis index to <see cref="GamePadButton"/>
 /// </summary>
 /// <param name="index">The axis index of the axis on this device</param>
 /// <param name="button">The button(s) to map to</param>
 protected void AddAxisToButton(int index, GamePadButton button)
 {
     while (axisToButtonMap.Count <= index)
     {
         axisToButtonMap.Add(GamePadButton.None);
     }
     axisToButtonMap[index] = button;
 }
 /// <inheritdoc/>
 public override Boolean MatchesGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     if (PlayerIndex == AnyPlayerIndex || PlayerIndex == device.PlayerIndex)
     {
         return(Button == button);
     }
     return(base.MatchesGamePadButtonDown(device, button, repeat, data));
 }
Ejemplo n.º 18
0
        /// <inheritdoc/>
        public override bool IsButtonPressed(GamePadButton button, bool ignoreRepeats = true)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var btnval = (Int32)button;

            return(states[btnval].Pressed || (!ignoreRepeats && states[btnval].Repeated));
        }
Ejemplo n.º 19
0
        private void UpdateButton(GamepadButtonFlags buttons, GamepadButtonFlags nativeButton,
                                  GamePadButton button)
        {
            var buttonIndex = (int)button;

            states[buttonIndex] =
                states[buttonIndex].UpdateOnNativePressing((buttons & nativeButton) != 0);
        }
Ejemplo n.º 20
0
 public static bool IsButtonDown(int gamePadIndex, GamePadButton button)
 {
     if (IsConnected(gamePadIndex))
     {
         return(m_states[gamePadIndex].Buttons[(int)button]);
     }
     return(false);
 }
Ejemplo n.º 21
0
        /// <inheritdoc/>
        public override bool IsButtonReleased(GamePadButton button)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var btnval = (Int32)button;

            return(states[btnval].Released);
        }
        internal bool IsButtonBinded(GamePadButton button)
        {
            if (GamepadInputs == null || GamepadInputs?.Count == 0)
            {
                return(false);
            }

            return(GamepadInputs.Values.Any(c => c != null && c.GamepadInput.HasValue && c.GamepadInput.Value == button));
        }
        /// <summary>
        /// Looks for the game control that <paramref name="button"/> is binded to and removes it by setting it to null;
        /// </summary>
        private void RemoveExistingGamepadBinding(GamePadButton button)
        {
            var existingBinding = GamepadInputs.Where(kv => kv.Value != null && kv.Value.GamepadInput.HasValue && kv.Value.GamepadInput.Value == button).FirstOrDefault();

            if (existingBinding.Value != null)
            {
                GamepadInputs[existingBinding.Key] = null;
            }
        }
 public ControlInputSetting(string displayText, int val, GamePadButton padInput, StringKey?translationKey = null)
 {
     DisplayText    = displayText;
     ConfigValue    = val;
     KeyboardKey    = null;
     KeyIsExtended  = false;
     TranslationKey = translationKey;
     GamepadInput   = padInput;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GamePadGesture"/> class.
        /// </summary>
        /// <param name="button">The button associated with this game pad gesture.</param>
        /// <param name="playerIndex">The player index of the game pad for this gesture.</param>
        /// <param name="displayString">The display string for this keyboard gesture.</param>
        public GamePadGesture(GamePadButton button, Int32 playerIndex, String displayString)
        {
            Contract.EnsureRange(playerIndex >= AnyPlayerIndex, nameof(playerIndex));
            Contract.Require(displayString, nameof(displayString));

            this.Button        = button;
            this.PlayerIndex   = playerIndex;
            this.DisplayString = displayString;
        }
Ejemplo n.º 26
0
        public static bool Upward(GamePadButton button, uint padIndex)
        {
            if (!isInitialized)
            {
                Initialize();
            }

            return(!padInputs[padIndex].currentButton[(int)button] && padInputs[padIndex].oldButton[(int)button]);
        }
Ejemplo n.º 27
0
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        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;
        }
Ejemplo n.º 28
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button && !repeat)
     {
         HandlePressed();
         data.Handled = true;
     }
     base.OnGamePadButtonDown(device, button, repeat, data);
 }
Ejemplo n.º 29
0
        public override int GetHashCode()
        {
            // Was auto generated by VS, please do not kill me
            int hashCode = 1488379021 + GamePadButton.GetHashCode();

            hashCode = hashCode * -1521134295 + Key.GetHashCode();
            hashCode = hashCode * -1521134295 + Modifiers.GetHashCode();
            return(hashCode);
        }
Ejemplo n.º 30
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonUp(GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button)
     {
         HandleReleased(false);
         data.Handled = true;
     }
     base.OnGamePadButtonUp(device, button, data);
 }
Ejemplo n.º 31
0
        public static bool IsGamePadButtonDown(this InputManager input, GamePadButton button, int index)
        {
            if (input.GamePadCount < index)
            {
                return(false);
            }

            return((input.GetGamePadByIndex(index).State.Buttons & button) == button);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Gets the gamepad button up state (true if was released during the current frame).
        /// </summary>
        /// <param name="button">Gamepad button to check</param>
        /// <returns>True if user releases the button, otherwise false.</returns>
        public bool GetButtonUp(GamePadButton button)
        {
            if (_version != Input.gamepadsVersion)
            {
                throw new AccessViolationException();
            }
            int state = Internal_GetButton(_index, button);

            return((state & 1) == 0 && (state & 2) != 0);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GamePadInputBinding"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="playerIndex">The index of the player for which to create the binding.</param>
        /// <param name="button">A <see cref="GamePadButton"/> value representing the binding's primary button.</param>
        public GamePadInputBinding(UltravioletContext uv, Int32 playerIndex, GamePadButton button)
            : base()
        {
            Contract.Require(uv, "uv");
            Contract.EnsureRange(playerIndex >= 0, "playerIndex");

            this.uv = uv;
            this.playerIndex = playerIndex;
            this.button  = button;
        }
        public static bool IsGamePadButtonDownAny(this InputManager input, GamePadButton button)
        {
            for (int i = 0; i < input.GamePadCount; i++)
            {
                if ((input.GetGamePad(i).Buttons & button) == button)
                    return true;
            }

            return false;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is open.
        /// </summary>
        private void OnGamePadButtonDown_DropDownOpen(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                SelectFocusedItem();
                IsDropDownOpen = false;
                data.Handled   = true;
            }
            else if (GamePad.CancelButton == button)
            {
                IsDropDownOpen = false;
                data.Handled   = true;
            }
            else if (GamePad.TabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.None);
                data.Handled = true;
            }
            else if (GamePad.ShiftTabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.Shift);
                data.Handled = true;
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                    case GamePadButton.DPadUp:
                        MoveItemSelection(-1);
                        break;

                    case GamePadButton.DPadDown:
                        MoveItemSelection(1);
                        break;

                    case GamePadButton.DPadLeft:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, ref data);
                        }
                        break;

                    case GamePadButton.DPadRight:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                        }
                        break;
                    }
                    data.Handled = true;
                }
            }
        }
Ejemplo n.º 36
0
        public static bool isPressed(GamePadButton button, uint padIndex)
        {
            if (!isInitialized) { initialize(); }

            if (button == GamePadButton.LT)
                return padInputs[padIndex].LTRT > 50;
            if (button == GamePadButton.RT)
                return padInputs[padIndex].LTRT < -50;

            return padInputs[padIndex].currentButton[(int)button];
        }
Ejemplo n.º 37
0
        internal GamePadInputBinding(UltravioletContext uv, XElement element)
        {
            Contract.Require(uv, nameof(uv));
            Contract.Require(element, nameof(element));

            this.uv = uv;
            this.playerIndex = element.ElementValueInt32("Player") ?? 0;
            this.button = element.ElementValueEnum<GamePadButton>("Button") ?? GamePadButton.None;

            this.stringRepresentation = BuildStringRepresentation();
        }
Ejemplo n.º 38
0
        public GamePadInputBinding(UltravioletContext uv, Int32 playerIndex, GamePadButton button)
            : base()
        {
            Contract.Require(uv, nameof(uv));
            Contract.EnsureRange(playerIndex >= 0, nameof(playerIndex));

            this.uv = uv;
            this.playerIndex = playerIndex;
            this.button = button;

            this.stringRepresentation = BuildStringRepresentation();
        }
Ejemplo n.º 39
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (!GamePad.UseAxisForDirectionalNavigation)
            {
                switch (button)
                {
                    case GamePadButton.DPadUp:
                        DecreaseSmall();
                        data.Handled = true;
                        break;

                    case GamePadButton.DPadDown:
                        IncreaseSmall();
                        data.Handled = true;
                        break;
                }
            }
            base.OnGamePadButtonDown(device, button, repeat, data);
        }
Ejemplo n.º 40
0
 public static Buttons MonoGameToXnaButton(GamePadButton button)
 {
     switch (button)
     {
         case GamePadButton.Up: return Buttons.DPadUp;
         case GamePadButton.Down: return Buttons.DPadDown;
         case GamePadButton.Left: return Buttons.DPadLeft;
         case GamePadButton.Right: return Buttons.DPadRight;
         case GamePadButton.A: return Buttons.A;
         case GamePadButton.B: return Buttons.B;
         case GamePadButton.X: return Buttons.X;
         case GamePadButton.Y: return Buttons.Y;
         case GamePadButton.Back: return Buttons.Back;
         case GamePadButton.Start: return Buttons.Start;
         case GamePadButton.BigButton: return Buttons.BigButton;
         case GamePadButton.LB: return Buttons.LeftShoulder;
         case GamePadButton.RB: return Buttons.RightShoulder;
         case GamePadButton.LS: return Buttons.LeftStick;
         case GamePadButton.RS: return Buttons.RightStick;
         default: throw new NotSupportedException();
     }
 }
Ejemplo n.º 41
0
 public bool CheckButtonPress(GamePadButton Button, PlayerIndex Index)
 {
     switch (Button)
     {
         case GamePadButton.A:
             if (m_CurrentState[Index].Buttons.A == ButtonState.Pressed && m_PreviousState[Index].Buttons.A == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.B:
             if (m_CurrentState[Index].Buttons.B == ButtonState.Pressed && m_PreviousState[Index].Buttons.B == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.X:
             if (m_CurrentState[Index].Buttons.X == ButtonState.Pressed && m_PreviousState[Index].Buttons.X == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.Y:
             if (m_CurrentState[Index].Buttons.Y == ButtonState.Pressed && m_PreviousState[Index].Buttons.Y == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.BigButton:
             if (m_CurrentState[Index].Buttons.BigButton == ButtonState.Pressed && m_PreviousState[Index].Buttons.BigButton == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.LeftShoulder:
             if (m_CurrentState[Index].Buttons.LeftShoulder == ButtonState.Pressed && m_PreviousState[Index].Buttons.LeftShoulder == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.RightShoulder:
             if (m_CurrentState[Index].Buttons.RightShoulder == ButtonState.Pressed && m_PreviousState[Index].Buttons.RightShoulder == ButtonState.Released)
                 return true;
             else return false;
         case GamePadButton.Start:
             if (m_CurrentState[Index].Buttons.Start == ButtonState.Pressed && m_PreviousState[Index].Buttons.Start == ButtonState.Released)
                 return true;
             else return false;
     }
     return false;
 }
 // Get button down event
 public bool GetButtonDown(PlayerIndex player, GamePadButton button)
 {
     switch (player)
     {
         case PlayerIndex.One:
             switch (button)
             {
                 case GamePadButton.Guide: return p1PrevState.Buttons.Guide == ButtonState.Released && p1State.Buttons.Guide == ButtonState.Pressed;
                 case GamePadButton.A: return p1PrevState.Buttons.A == ButtonState.Released && p1State.Buttons.A == ButtonState.Pressed;
                 case GamePadButton.B: return p1PrevState.Buttons.B == ButtonState.Released && p1State.Buttons.B == ButtonState.Pressed;
                 case GamePadButton.X: return p1PrevState.Buttons.X == ButtonState.Released && p1State.Buttons.X == ButtonState.Pressed;
                 case GamePadButton.Y: return p1PrevState.Buttons.Y == ButtonState.Released && p1State.Buttons.Y == ButtonState.Pressed;
                 case GamePadButton.L_Stick: return p1PrevState.Buttons.LeftStick == ButtonState.Released && p1State.Buttons.LeftStick == ButtonState.Pressed;
                 case GamePadButton.R_Stick: return p1PrevState.Buttons.RightStick == ButtonState.Released && p1State.Buttons.RightStick == ButtonState.Pressed;
                 case GamePadButton.L_Trigger: return p1PrevState.Triggers.Left == 0.0f && p1State.Triggers.Left >= 0.1f;
                 case GamePadButton.R_Trigger: return p1PrevState.Triggers.Right == 0.0f && p1State.Triggers.Right >= 0.1f;
                 case GamePadButton.L_Bumper: return p1PrevState.Buttons.LeftShoulder == ButtonState.Released && p1State.Buttons.LeftShoulder == ButtonState.Pressed;
                 case GamePadButton.R_Bumper: return p1PrevState.Buttons.RightShoulder == ButtonState.Released && p1State.Buttons.RightShoulder == ButtonState.Pressed;
                 default: return false;
             }
         case PlayerIndex.Two:
             switch (button)
             {
                 case GamePadButton.Guide: return p2PrevState.Buttons.Guide == ButtonState.Released && p2State.Buttons.Guide == ButtonState.Pressed;
                 case GamePadButton.A: return p2PrevState.Buttons.A == ButtonState.Released && p2State.Buttons.A == ButtonState.Pressed;
                 case GamePadButton.B: return p2PrevState.Buttons.B == ButtonState.Released && p2State.Buttons.B == ButtonState.Pressed;
                 case GamePadButton.X: return p2PrevState.Buttons.X == ButtonState.Released && p2State.Buttons.X == ButtonState.Pressed;
                 case GamePadButton.Y: return p2PrevState.Buttons.Y == ButtonState.Released && p2State.Buttons.Y == ButtonState.Pressed;
                 case GamePadButton.L_Stick: return p2PrevState.Buttons.LeftStick == ButtonState.Released && p2State.Buttons.LeftStick == ButtonState.Pressed;
                 case GamePadButton.R_Stick: return p2PrevState.Buttons.RightStick == ButtonState.Released && p2State.Buttons.RightStick == ButtonState.Pressed;
                 case GamePadButton.L_Trigger: return p2PrevState.Triggers.Left == 0.0f && p2State.Triggers.Left >= 0.1f;
                 case GamePadButton.R_Trigger: return p2PrevState.Triggers.Right == 0.0f && p2State.Triggers.Right >= 0.1f;
                 case GamePadButton.L_Bumper: return p2PrevState.Buttons.LeftShoulder == ButtonState.Released && p2State.Buttons.LeftShoulder == ButtonState.Pressed;
                 case GamePadButton.R_Bumper: return p2PrevState.Buttons.RightShoulder == ButtonState.Released && p2State.Buttons.RightShoulder == ButtonState.Pressed;
                 default: return false;
             }
         default: return false;
     }
 }
Ejemplo n.º 43
0
 ////////////////////////////////////////////////////////////////////////////
 
 ////////////////////////////////////////////////////////////////////////////
 public GamePadEventArgs(PlayerIndex playerIndex, GamePadButton button)
 {
   PlayerIndex = playerIndex;
   Button = button;
 }
Ejemplo n.º 44
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonUp(GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button)
     {
         HandleReleased(false);
         data.Handled = true;
     }
     base.OnGamePadButtonUp(device, button, data);
 }
Ejemplo n.º 45
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button && !repeat)
     {
         HandlePressed();
         data.Handled = true;
     }
     base.OnGamePadButtonDown(device, button, repeat, data);
 }
Ejemplo n.º 46
0
        public static bool isReleased(GamePadButton button, uint padIndex)
        {
            if (!isInitialized) { initialize(); }

            return !padInputs[padIndex].currentButton[(int)button] && padInputs[padIndex].oldButton[(int)button];
        }
Ejemplo n.º 47
0
 public bool OnButtonUp(GamePadButton button)
 {
     if (!_buttonBindingTable.ContainsKey(button))
     {
         return false;
     }
     InputBinding binding = _buttonBindingTable[button];
     binding.OnRelease();
     return true;
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Invokes the <see cref="OnGamePadButtonDown"/> method.
 /// </summary>
 private static void OnGamePadButtonDownProxy(DependencyObject element, GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadButtonDown(device, button, repeat, data);
 }
Ejemplo n.º 49
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            var templatedParent = TemplatedParent as Control;
            if (templatedParent == null || !templatedParent.HandlesScrolling)
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                        case GamePadButton.DPadUp:
                            HandleKeyScrolling(Key.Up, ModifierKeys.None, ref data);
                            break;

                        case GamePadButton.DPadDown:
                            HandleKeyScrolling(Key.Down, ModifierKeys.None, ref data);
                            break;

                        case GamePadButton.DPadLeft:
                            HandleKeyScrolling(Key.Left, ModifierKeys.None, ref data);
                            break;

                        case GamePadButton.DPadRight:
                            HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                            break;
                    }
                    data.Handled = true;
                }
            }

            base.OnGamePadButtonDown(device, button, repeat, ref data);
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Invokes by the <see cref="GamePad.ButtonDownEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="button">The button that was pressed.</param>
        /// <param name="repeat">A value indicating whether this is a repeated button press.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {

        }
Ejemplo n.º 51
0
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    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;
    }
Ejemplo n.º 52
0
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    private ButtonState GetVectorState(GamePadButton button, GamePadState state)
    {
      ButtonState ret = ButtonState.Released;
      bool down = false;
      float t = ClickThreshold;
      
      switch (button)
      {
        case GamePadButton.LeftStickLeft: down = state.ThumbSticks.Left.X < -t; break;
        case GamePadButton.LeftStickRight: down = state.ThumbSticks.Left.X > t; break;
        case GamePadButton.LeftStickUp: down = state.ThumbSticks.Left.Y > t; break;
        case GamePadButton.LeftStickDown: down = state.ThumbSticks.Left.Y < -t; break;

        case GamePadButton.RightStickLeft: down = state.ThumbSticks.Right.X < -t; break;
        case GamePadButton.RightStickRight: down = state.ThumbSticks.Right.X > t; break;
        case GamePadButton.RightStickUp: down = state.ThumbSticks.Right.Y > t; break;
        case GamePadButton.RightStickDown: down = state.ThumbSticks.Right.Y < -t; break;      
        
        case GamePadButton.LeftTrigger: down = state.Triggers.Left > t; break;
        case GamePadButton.RightTrigger: down = state.Triggers.Right > t; break;
      }
      
      ret = down ? ButtonState.Pressed : ButtonState.Released;
            
      return ret;
    }
Ejemplo n.º 53
0
 public InputGamePadButton(GamePadButton button)
 {
   Button = button;
 }
Ejemplo n.º 54
0
        public void BindButton(GamePadButton button, string command)
        {
            // TODO: Allow input bindings to be either a message send
            // or a console command.
            if (command.Length == 0)
                return;

            InputBinding binding;
            if (!_buttonBindingTable.ContainsKey(button))
            {
                binding = new InputBinding();
                _buttonBindingTable.Add(button, binding);
            }
            else
            {
                binding = _buttonBindingTable[button];
            }

            if (command.StartsWith("-"))
            {
                command = command.Remove(0, 1);
                binding.ReleaseMessage = command;
            }
            else
            {
                if (command.StartsWith("+"))
                    command = command.Remove(0, 1);

                binding.PressMessage = command;
            }
        }
Ejemplo n.º 55
0
 /// <summary>
 /// Raises the ButtonUp attached event for the specified element.
 /// </summary>
 internal static void RaiseButtonUp(DependencyObject element, GamePadDevice device, GamePadButton button, ref RoutedEventData data)
 {
     var temp = EventManager.GetInvocationDelegate<UpfGamePadButtonUpEventHandler>(ButtonUpEvent);
     if (temp != null)
     {
         temp(element, device, button, ref data);
     }
 }
Ejemplo n.º 56
0
 public abstract State GetButtonState(GamePadButton button);
Ejemplo n.º 57
0
 /// <summary>
 /// Invokes the <see cref="OnGamePadButtonUp"/> method.
 /// </summary>
 private static void OnGamePadButtonUpProxy(DependencyObject element, GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadButtonUp(device, button, data);
 }
Ejemplo n.º 58
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                var listBoxItem = ItemsControlUtil.FindContainer<ListBoxItem>(this, data.OriginalSource);
                if (listBoxItem != null)
                {
                    HandleItemClicked(listBoxItem);
                    data.Handled = true;
                }
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                        case GamePadButton.DPadLeft:
                            if (PART_ScrollViewer != null)
                            {
                                PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, data);
                            }
                            data.Handled = true;
                            break;

                        case GamePadButton.DPadRight:
                            if (PART_ScrollViewer != null)
                            {
                                PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, data);
                            }
                            data.Handled = true;
                            break;

                        case GamePadButton.DPadUp:
                            if (SelectionMode == SelectionMode.Single)
                            {
                                MoveSelectedItem(FocusNavigationDirection.Up);
                            }
                            data.Handled = true;
                            break;

                        case GamePadButton.DPadDown:
                            if (SelectionMode == SelectionMode.Single)
                            {
                                MoveSelectedItem(FocusNavigationDirection.Down);
                            }
                            data.Handled = true;
                            break;
                    }
                }
            }

            base.OnGamePadButtonDown(device, button, repeat, data);
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Invokes by the <see cref="GamePad.ButtonUpEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="button">The button that was released.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadButtonUp(GamePadDevice device, GamePadButton button, RoutedEventData data)
        {

        }
Ejemplo n.º 60
0
        public static bool IsGamePadButtonPressed(GamePadButton myButton, int myPlayer)
        {
            if (newGamePads[myPlayer].IsConnected)
            {

                if (myButton == GamePadButton.A)
                {
                    if (newGamePads[myPlayer].Buttons.A == ButtonState.Pressed)
                    {
                        return true;
                    }

                }

                if (myButton == GamePadButton.X)
                {
                    if (newGamePads[myPlayer].Buttons.X == ButtonState.Pressed)
                    {
                        return true;
                    }

                }
            }
            return false;
        }