fna-workbench

fna-workbench Git Source Tree


Root/src/Input/GamePad.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
 * Copyright 2009-2016 Ethan Lee and the MonoGame Team
 *
 * Released under the Microsoft Public License.
 * See LICENSE for details.
 */
#endregion
 
#region Using Statements
using System;
#endregion
 
namespace Microsoft.Xna.Framework.Input
{
    public static class GamePad
    {
        #region Internal Static Variables
 
        /* Determines how many controllers we should be tracking.
         * Per XNA4 we track 4 by default, but if you want to track more you can
         * do this by changing PlayerIndex.cs to include more index names.
         * -flibit
         */
        internal static readonly int GAMEPAD_COUNT = DetermineNumGamepads();
 
        private static int DetermineNumGamepads()
        {
            string numGamepadString = Environment.GetEnvironmentVariable(
                "FNA_GAMEPAD_NUM_GAMEPADS"
            );
            if (!String.IsNullOrEmpty(numGamepadString))
            {
                int numGamepads;
                if (int.TryParse(numGamepadString, out numGamepads))
                {
                    if (numGamepads >= 0)
                    {
                        return numGamepads;
                    }
                }
            }
            return Enum.GetNames(typeof(PlayerIndex)).Length;
        }
 
        #endregion
 
        #region Public GamePad API
 
        public static GamePadCapabilities GetCapabilities(PlayerIndex playerIndex)
        {
            return FNAPlatform.GetGamePadCapabilities((int) playerIndex);
        }
 
        public static GamePadState GetState(PlayerIndex playerIndex)
        {
            return FNAPlatform.GetGamePadState(
                (int) playerIndex,
                GamePadDeadZone.IndependentAxes
            );
        }
 
        public static GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
        {
            return FNAPlatform.GetGamePadState(
                (int) playerIndex,
                deadZoneMode
            );
        }
 
        public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)
        {
            return FNAPlatform.SetGamePadVibration(
                (int) playerIndex,
                leftMotor,
                rightMotor
            );
        }
 
        #endregion
 
        #region Public GamePad API, FNA Extensions
 
        public static string GetGUIDEXT(PlayerIndex playerIndex)
        {
            return FNAPlatform.GetGamePadGUID((int) playerIndex);
        }
 
        public static void SetLightBarEXT(PlayerIndex playerIndex, Color color)
        {
            FNAPlatform.SetGamePadLightBar((int) playerIndex, color);
        }
 
        #endregion
    }
}

Archive Download this file

Branches

Number of commits:
Page rendered in 0.22263s using 11 queries.