Пример #1
0
        public short GetAnalog(uint port, RETRO_DEVICE_INDEX_ANALOG index, RETRO_DEVICE_ID_ANALOG direction)
        {
            RetroAnalogDevice positive;
            RetroAnalogDevice negative;

            RetroPadMapping.GetAnalogEnums(index, direction, out positive, out negative);

            short positivePosition = 0;
            short negativePosition = 0;

            Keys key;

            if (_analogMappings.TryGetValue(positive, out key) && Keyboard.IsKeyDown(key))
            {
                positivePosition = short.MaxValue;
            }
            if (_analogMappings.TryGetValue(negative, out key) && Keyboard.IsKeyDown(key))
            {
                negativePosition = short.MinValue;
            }

            if (positivePosition != 0 && negativePosition == 0)
            {
                return(positivePosition);
            }
            if (positivePosition == 0 && negativePosition != 0)
            {
                return(negativePosition);
            }
            return(0);
        }
Пример #2
0
        public short GetAnalog(uint port, RETRO_DEVICE_INDEX_ANALOG index, RETRO_DEVICE_ID_ANALOG direction)
        {
            HidState state = _currentState;

            if (state == null)
            {
                return(0);
            }

            RetroAnalogDevice positive;
            RetroAnalogDevice negative;

            RetroPadMapping.GetAnalogEnums(index, direction, out positive, out negative);
            short positivePosition = 0;
            short negativePosition = 0;

            HidAxis           axis;
            ushort            button;
            DirectionPadState directionPadState;

            if (_analogToAnalogMappings.TryGetValue(positive, out axis))
            {
                positivePosition = GetAxisPositionMapped(axis, state, true);
            }
            else if (_directionPadToAnalogMappings.TryGetValue(positive, out directionPadState) && IsDirectionPadPressed(directionPadState, state))
            {
                positivePosition = short.MaxValue;
            }
            else if (_buttonToAnalogMappings.TryGetValue(positive, out button) && IsButtonPressed(button, state))
            {
                positivePosition = short.MaxValue;
            }

            if (_analogToAnalogMappings.TryGetValue(negative, out axis))
            {
                negativePosition = GetAxisPositionMapped(axis, state, false);
            }
            else if (_directionPadToAnalogMappings.TryGetValue(negative, out directionPadState) && IsDirectionPadPressed(directionPadState, state))
            {
                positivePosition = short.MinValue;
            }
            else if (_buttonToAnalogMappings.TryGetValue(negative, out button) && IsButtonPressed(button, state))
            {
                negativePosition = short.MinValue;
            }

            if (positivePosition != 0 && negativePosition == 0)
            {
                return(positivePosition);
            }
            if (positivePosition == 0 && negativePosition != 0)
            {
                return(negativePosition);
            }
            return(0);
        }
Пример #3
0
        public short GetAnalog(uint port, RETRO_DEVICE_INDEX_ANALOG index, RETRO_DEVICE_ID_ANALOG direction)
        {
            if (port != _controllerIndex)
            {
                return(0);
            }
            Gamepad gamepad;

            if (!TryGetGamepad(out gamepad))
            {
                return(0);
            }

            RetroAnalogDevice positive;
            RetroAnalogDevice negative;

            RetroPadMapping.GetAnalogEnums(index, direction, out positive, out negative);
            short positivePosition = 0;
            short negativePosition = 0;

            XInputAxis         axis;
            GamepadButtonFlags buttonFlag;

            if (_analogToAnalogMappings.TryGetValue(positive, out axis))
            {
                positivePosition = GetAxisPositionMapped(axis, gamepad, true);
            }
            else if (_buttonToAnalogMappings.TryGetValue(positive, out buttonFlag) && IsButtonPressed(buttonFlag, gamepad))
            {
                positivePosition = short.MaxValue;
            }

            if (_analogToAnalogMappings.TryGetValue(negative, out axis))
            {
                negativePosition = GetAxisPositionMapped(axis, gamepad, false);
            }
            else if (_buttonToAnalogMappings.TryGetValue(negative, out buttonFlag) && IsButtonPressed(buttonFlag, gamepad))
            {
                negativePosition = short.MinValue;
            }

            if (positivePosition != 0 && negativePosition == 0)
            {
                return(positivePosition);
            }
            if (positivePosition == 0 && negativePosition != 0)
            {
                return(negativePosition);
            }
            return(0);
        }