Ejemplo n.º 1
0
        private static GamePadState ReadState(PlayerIndex index, GamePadDeadZone deadZone)
        {
            IntPtr    device = SdlGamePad.GetDevice(index);
            PadConfig config = SdlGamePad.GetConfig(index);

            if (device == IntPtr.Zero || config == null)
            {
                return(GamePadState.InitializedState);
            }
            Vector2            vector2_1   = config.LeftStick.ReadAxisPair(device);
            Vector2            vector2_2   = config.RightStick.ReadAxisPair(device);
            GamePadThumbSticks thumbSticks = new GamePadThumbSticks(new Vector2(vector2_1.X, vector2_1.Y), new Vector2(vector2_2.X, vector2_2.Y));

            thumbSticks.ApplyDeadZone(deadZone, 0.27f);
            GamePadTriggers triggers = new GamePadTriggers(config.LeftTrigger.ReadFloat(device), config.RightTrigger.ReadFloat(device));
            GamePadButtons  buttons  = new GamePadButtons(SdlGamePad.ReadButtons(device, config, 0.27f) | SdlGamePad.StickToButtons(thumbSticks.Left, Buttons.LeftThumbstickLeft, Buttons.LeftThumbstickRight, Buttons.LeftThumbstickUp, Buttons.LeftThumbstickDown, 0.27f) | SdlGamePad.StickToButtons(thumbSticks.Right, Buttons.RightThumbstickLeft, Buttons.RightThumbstickRight, Buttons.RightThumbstickUp, Buttons.RightThumbstickDown, 0.27f) | SdlGamePad.TriggerToButton(triggers.Left, Buttons.LeftTrigger, 0.27f) | SdlGamePad.TriggerToButton(triggers.Right, Buttons.RightTrigger, 0.27f));
            GamePadDPad     dPad     = new GamePadDPad(buttons.buttons);

            return(new GamePadState(thumbSticks, triggers, buttons, dPad));
        }
Ejemplo n.º 2
0
        public static GamePadCapabilities GetCapabilities(PlayerIndex playerIndex)
        {
            IntPtr    device = SdlGamePad.GetDevice(playerIndex);
            PadConfig config = SdlGamePad.GetConfig(playerIndex);

            if (config == null || (config.JoystickName == null || config.JoystickName == string.Empty) && device == IntPtr.Zero)
            {
                return(new GamePadCapabilities());
            }
            return(new GamePadCapabilities()
            {
                IsConnected = device != IntPtr.Zero,
                HasAButton = config.Button_A.Type != InputType.None,
                HasBButton = config.Button_B.Type != InputType.None,
                HasXButton = config.Button_X.Type != InputType.None,
                HasYButton = config.Button_Y.Type != InputType.None,
                HasBackButton = config.Button_Back.Type != InputType.None,
                HasStartButton = config.Button_Start.Type != InputType.None,
                HasDPadDownButton = config.Dpad.Down.Type != InputType.None,
                HasDPadLeftButton = config.Dpad.Left.Type != InputType.None,
                HasDPadRightButton = config.Dpad.Right.Type != InputType.None,
                HasDPadUpButton = config.Dpad.Up.Type != InputType.None,
                HasLeftShoulderButton = config.Button_LB.Type != InputType.None,
                HasRightShoulderButton = config.Button_RB.Type != InputType.None,
                HasLeftStickButton = config.LeftStick.Press.Type != InputType.None,
                HasRightStickButton = config.RightStick.Press.Type != InputType.None,
                HasLeftTrigger = config.LeftTrigger.Type != InputType.None,
                HasRightTrigger = config.RightTrigger.Type != InputType.None,
                HasLeftXThumbStick = config.LeftStick.X.Type != InputType.None,
                HasLeftYThumbStick = config.LeftStick.Y.Type != InputType.None,
                HasRightXThumbStick = config.RightStick.X.Type != InputType.None,
                HasRightYThumbStick = config.RightStick.Y.Type != InputType.None,
                HasLeftVibrationMotor = false,
                HasRightVibrationMotor = false,
                HasVoiceSupport = false,
                HasBigButton = false
            });
        }