Exemple #1
0
        private void HandleMouseButtons(InputMapping mapping)
        {
            if (mapping.PositiveMouseButton == null && mapping.NegativeMouseButton == null)
            {
                return;
            }

            if (mapping.PressType == PressType.Down)
            {
                if (mapping.PositiveMouseButton != null && InputService.IsDown(mapping.PositiveMouseButton.Value))
                {
                    Value++;
                }
                if (mapping.NegativeMouseButton != null && InputService.IsDown(mapping.NegativeMouseButton.Value))
                {
                    Value--;
                }
            }
            else if (mapping.PressType == PressType.Press)
            {
                if (mapping.PositiveMouseButton != null && InputService.IsPressed(mapping.PositiveMouseButton.Value, false))
                {
                    Value++;
                }
                if (mapping.NegativeMouseButton != null && InputService.IsPressed(mapping.NegativeMouseButton.Value, false))
                {
                    Value--;
                }
            }
            else
            {
                Debug.Assert(mapping.PressType == PressType.DoubleClick, "Unhandled press type.");

                if (mapping.PositiveMouseButton != null && InputService.IsDoubleClick(mapping.PositiveMouseButton.Value))
                {
                    Value++;
                }
                if (mapping.NegativeMouseButton != null && InputService.IsDoubleClick(mapping.NegativeMouseButton.Value))
                {
                    Value--;
                }
            }
        }
Exemple #2
0
        private void HandleMapping(InputMapping mapping)
        {
            if (mapping == null)
            {
                return;
            }

            if (mapping.ModifierKeys == ModifierKeys.None ||
                (InputService.ModifierKeys & mapping.ModifierKeys) == mapping.ModifierKeys)
            {
                // No modifiers necessary, or all modifiers are down.
                HandleKeys(mapping);
                HandleMouseButtons(mapping);
            }


            if (mapping.ModifierButtons == null ||
                InputService.IsDown(mapping.ModifierButtons.Value, LogicalPlayerIndex))
            {
                // No modifiers necessary, or all modifiers are down.
                HandleButtons(mapping);
            }


            Value = MathHelper.Clamp(Value, -1, 1);

            float axisValue = HandleAxis(mapping);

            // Combine Value and axisValue.
            // The normal value limit is 1, but mouse axis can give a value beyond 1. We take the
            // max of these values as the limit. The Value must not increase above the limit when
            // the user uses axis + keys/buttons. (For instance, concurrent presses should not
            // make a player faster.)
            float limit = Math.Max(1, Math.Abs(axisValue));

            Value = MathHelper.Clamp(Value + axisValue, -limit, limit);

            if (mapping.Invert)
            {
                Value = -Value;
            }
        }
Exemple #3
0
        private float HandleAxis(InputMapping mapping)
        {
            if (mapping.Axis == null)
            {
                return(0);
            }

            float axisValue = 0;

            switch (mapping.Axis.Value)
            {
            case DeviceAxis.MouseXAbsolute:
                axisValue = InputService.MousePosition.X;
                break;

            case DeviceAxis.MouseYAbsolute:
                axisValue = InputService.MousePosition.Y;
                break;

            case DeviceAxis.MouseXRelative:
                axisValue = InputService.MousePositionDelta.X;
                break;

            case DeviceAxis.MouseYRelative:
                axisValue = InputService.MousePositionDelta.Y;
                break;

            case DeviceAxis.MouseWheel:
                axisValue = InputService.MouseWheelDelta;
                break;

            case DeviceAxis.GamePadStickLeftX:
                axisValue = InputService.GetGamePadState(LogicalPlayerIndex).ThumbSticks.Left.X;
                break;

            case DeviceAxis.GamePadStickLeftY:
                axisValue = InputService.GetGamePadState(LogicalPlayerIndex).ThumbSticks.Left.Y;
                break;

            case DeviceAxis.GamePadStickRightX:
                axisValue = InputService.GetGamePadState(LogicalPlayerIndex).ThumbSticks.Right.X;
                break;

            case DeviceAxis.GamePadStickRightY:
                axisValue = InputService.GetGamePadState(LogicalPlayerIndex).ThumbSticks.Right.Y;
                break;

            case DeviceAxis.GamePadTriggerLeft:
                axisValue = InputService.GetGamePadState(LogicalPlayerIndex).Triggers.Left;
                break;

            case DeviceAxis.GamePadTriggerRight:
                axisValue = InputService.GetGamePadState(LogicalPlayerIndex).Triggers.Right;
                break;

            default:
                Debug.Assert(false, "Unhandled device axis.");
                break;
            }

            if (Sensitivity != 1.0f)
            {
                axisValue = Math.Sign(axisValue) * (float)Math.Pow(Math.Abs(axisValue), 1.0f / Sensitivity);
            }

            return(axisValue);
        }