예제 #1
0
        private void ParseButtonStates(GamePadState currentState, GamePadState previousState)
        {
            if (currentState.Guide != previousState.Guide)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.Guide, currentState.Guide);
            }

            if (currentState.Start != previousState.Start)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.Start, currentState.Start);
            }

            if (currentState.Options != previousState.Options)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.Back, currentState.Options);
            }

            if (currentState.Left != previousState.Left)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.DpadLeft, currentState.Left);
            }

            if (currentState.Up != previousState.Up)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.DpadUp, currentState.Up);
            }

            if (currentState.Right != previousState.Right)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.DpadRight, currentState.Right);
            }

            if (currentState.Down != previousState.Down)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.DpadDown, currentState.Down);
            }

            if (currentState.A != previousState.A)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.A, currentState.A);
            }

            if (currentState.B != previousState.B)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.B, currentState.B);
            }

            if (currentState.X != previousState.X)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.X, currentState.X);
            }

            if (currentState.Y != previousState.Y)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.Y, currentState.Y);
            }

            if (currentState.LeftBumper != previousState.LeftBumper)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.LB, currentState.LeftBumper);
            }

            if (currentState.LeftStick != previousState.LeftStick)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.LS, currentState.LeftStick);
            }

            if (currentState.RightBumper != previousState.RightBumper)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.RB, currentState.RightBumper);
            }

            if (currentState.RightStick != previousState.RightStick)
            {
                OnDeviceButtonStateChanged(XInputControls.Button.RS, currentState.RightStick);
            }
        }
예제 #2
0
        private void ParseAnalogStates(GamePadState currentState)
        {
            int x;
            int y;

            // Parsing left thumbstick state
            x = (int)((float)currentState.LeftStickX / short.MaxValue * THUMBSTICK_AXIS_RANGE);
            y = (int)((float)currentState.LeftStickY / short.MaxValue * THUMBSTICK_AXIS_RANGE);

            if ((-THUMBSTICK_DEAD_ZONE_X <= x) && (x <= THUMBSTICK_DEAD_ZONE_X))
            {
                x = 0;
            }

            if ((-THUMBSTICK_DEAD_ZONE_Y <= y) && (y <= THUMBSTICK_DEAD_ZONE_Y))
            {
                y = 0;
            }

            if (x != 0 || y != 0)
            {
                OnDeviceAnalogStateChanged(XInputControls.Analog.LeftThumbStick, new int[] { x, -y });
            }

            // Parsing right thumbstick state
            x = (int)((float)currentState.RightStickX / short.MaxValue * THUMBSTICK_AXIS_RANGE);
            y = (int)((float)currentState.RightStickY / short.MaxValue * THUMBSTICK_AXIS_RANGE);

            if ((-THUMBSTICK_DEAD_ZONE_X <= x) && (x <= THUMBSTICK_DEAD_ZONE_X))
            {
                x = 0;
            }

            if ((-THUMBSTICK_DEAD_ZONE_Y <= y) && (y <= THUMBSTICK_DEAD_ZONE_Y))
            {
                y = 0;
            }

            if (x != 0 || y != 0)
            {
                OnDeviceAnalogStateChanged(XInputControls.Analog.RightThumbStick, new int[] { x, -y });
            }

            // Parsing left trigger state
            OnDeviceAnalogStateChanged(XInputControls.Analog.LeftTrigger, new int[] { currentState.LeftTrigger });

            if (currentState.LeftTrigger > TRIGGER_CLICK_THRESHOLD)
            {
                if (!isLeftTriggerClicked)
                {
                    isLeftTriggerClicked = true;
                    OnDeviceButtonStateChanged(XInputControls.Button.LT, true);
                }
            }
            else
            {
                if (isLeftTriggerClicked)
                {
                    isLeftTriggerClicked = false;
                    OnDeviceButtonStateChanged(XInputControls.Button.LT, false);
                }
            }

            // Parsing right trigger state
            OnDeviceAnalogStateChanged(XInputControls.Analog.RightTrigger, new int[] { currentState.RightTrigger });

            if (currentState.RightTrigger > TRIGGER_CLICK_THRESHOLD)
            {
                if (!isRightTriggerClicked)
                {
                    isRightTriggerClicked = true;
                    OnDeviceButtonStateChanged(XInputControls.Button.RT, true);
                }
            }
            else
            {
                if (isRightTriggerClicked)
                {
                    isRightTriggerClicked = false;
                    OnDeviceButtonStateChanged(XInputControls.Button.RT, false);
                }
            }
        }