Esempio n. 1
0
        /// <summary>
        /// Gets the internal state of the given <see cref="GamePadState"/>
        /// </summary>
        /// <param name="self">The <see cref="GamePadState"/> to get the internal state of</param>
        /// <returns>An analogous object to the inaccessible internal state</returns>
        public static XINPUT_GAMEPAD GetInternalState(this GamePadState self)
        {
            object state = StatePadField.GetValue(StateField.GetValue(self));

            XINPUT_GAMEPAD result = default;

            result.Connected    = self.IsConnected;
            result.Buttons      = (ushort)GamePadButtons.GetValue(state);
            result.LeftTrigger  = (byte)GamePadLeftTrigger.GetValue(state);
            result.RightTrigger = (byte)GamePadRightTrigger.GetValue(state);
            result.ThumbLX      = (short)GamePadThumbLX.GetValue(state);
            result.ThumbLY      = (short)GamePadThumbLY.GetValue(state);
            result.ThumbRX      = (short)GamePadThumbRX.GetValue(state);
            result.ThumbRY      = (short)GamePadThumbRY.GetValue(state);

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="GamePadState"/> from the given <see cref="XINPUT_GAMEPAD"/>
        /// </summary>
        /// <param name="orig">The desired internal state of the returned <see cref="GamePadState"/></param>
        /// <param name="deadZone">The <see cref="GamePadDeadZone"/> to be used for the returnd <see cref="GamePadState"/></param>
        /// <returns>A new <see cref="GamePadState"/> with the given internal state</returns>
        public static GamePadState FromInternalState(XINPUT_GAMEPAD orig, GamePadDeadZone deadZone)
        {
            GamePadState result = default;
            object       state  = StateField.GetValue(result);
            object       pad    = StatePadField.GetValue(state);

            GamePadButtons.SetValue(pad, Enum.ToObject(GamePadButtons.FieldType, orig.Buttons));
            GamePadLeftTrigger.SetValue(pad, orig.LeftTrigger);
            GamePadRightTrigger.SetValue(pad, orig.RightTrigger);
            GamePadThumbLX.SetValue(pad, orig.ThumbLX);
            GamePadThumbLY.SetValue(pad, orig.ThumbLY);
            GamePadThumbRX.SetValue(pad, orig.ThumbRX);
            GamePadThumbRY.SetValue(pad, orig.ThumbRY);

            StatePadField.SetValue(state, pad);
            object errorCode = Enum.ToObject(ErrorCodeType, orig.Connected ? 0u : 997u);

            return((GamePadState)Ctor.Invoke(new object[] { state, errorCode, deadZone }));
        }