fna-workbench

fna-workbench Git Source Tree


Root/src/Input/GamePadState.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#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
 
namespace Microsoft.Xna.Framework.Input
{
    /// <summary>
    /// Represents specific information about the state of a controller,
    /// including the current state of buttons and sticks.
    /// </summary>
    public struct GamePadState
    {
        #region Public Properties
 
        /// <summary>
        /// Indicates whether the controller is connected.
        /// </summary>
        public bool IsConnected
        {
            get;
            internal set;
        }
 
        /// <summary>
        /// Gets the packet number associated with this state.
        /// </summary>
        public int PacketNumber
        {
            get;
            internal set;
        }
 
        /// <summary>
        /// Returns a structure that identifies which buttons on the controller
        /// are pressed.
        /// </summary>
        public GamePadButtons Buttons
        {
            get;
            internal set;
        }
 
        /// <summary>
        /// Returns a structure that identifies which directions of the directional pad
        /// on the controller are pressed.
        /// </summary>
        public GamePadDPad DPad
        {
            get;
            internal set;
        }
 
        /// <summary>
        /// Returns a structure that indicates the position of the controller thumbsticks.
        /// </summary>
        public GamePadThumbSticks ThumbSticks
        {
            get;
            internal set;
        }
 
        /// <summary>
        /// Returns a structure that identifies the position of triggers on the controller.
        /// </summary>
        public GamePadTriggers Triggers
        {
            get;
            internal set;
        }
 
        #endregion
 
        #region Public Constructors
 
        /// <summary>
        /// Initializes a new instance of the GamePadState class using the specified
        /// GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
        /// </summary>
        /// <param name="thumbSticks">Initial thumbstick state.</param>
        /// <param name="triggers">Initial trigger state.</param>
        /// <param name="buttons">Initial button state.</param>
        /// <param name="dPad">Initial directional pad state.</param>
        public GamePadState(
            GamePadThumbSticks thumbSticks,
            GamePadTriggers triggers,
            GamePadButtons buttons,
            GamePadDPad dPad
        ) : this() {
            ThumbSticks = thumbSticks;
            Triggers = triggers;
            Buttons = buttons;
            DPad = dPad;
            IsConnected = true;
            PacketNumber = 0;
        }
 
        /// <summary>
        /// Initializes a new instance of the GamePadState class with the specified stick,
        /// trigger, and button values.
        /// </summary>
        /// <param name="leftThumbStick">
        /// Left stick value. Each axis is clamped between 1.0 and 1.0.
        /// </param>
        /// <param name="rightThumbStick">
        /// Right stick value. Each axis is clamped between 1.0 and 1.0.
        /// </param>
        /// <param name="leftTrigger">
        /// Left trigger value. This value is clamped between 0.0 and 1.0.
        /// </param>
        /// <param name="rightTrigger">
        /// Right trigger value. This value is clamped between 0.0 and 1.0.
        /// </param>
        /// <param name="buttons">
        /// Array or parameter list of Buttons to initialize as pressed.
        /// </param>
        public GamePadState(
            Vector2 leftThumbStick,
            Vector2 rightThumbStick,
            float leftTrigger,
            float rightTrigger,
            params Buttons[] buttons
        ) : this(
            new GamePadThumbSticks(leftThumbStick, rightThumbStick),
            new GamePadTriggers(leftTrigger, rightTrigger),
            new GamePadButtons(buttons),
            new GamePadDPad(buttons)
        ) {
        }
 
        #endregion
 
        #region Public Methods
 
        /// <summary>
        /// Determines whether specified input device buttons are pressed in this GamePadState.
        /// </summary>
        /// <param name="button">
        /// Buttons to query. Specify a single button, or combine multiple buttons using
        /// a bitwise OR operation.
        /// </param>
        public bool IsButtonDown(Buttons button)
        {
            return (Buttons.buttons & button) == button;
        }
 
        /// <summary>
        /// Determines whether specified input device buttons are up (not pressed) in this
        /// GamePadState.
        /// </summary>
        /// <param name="button">
        /// Buttons to query. Specify a single button, or combine multiple buttons using
        /// a bitwise OR operation.
        /// </param>
        public bool IsButtonUp(Buttons button)
        {
            return (Buttons.buttons & button) != button;
        }
 
        #endregion
 
        #region Public Static Operators and Override Methods
 
        /// <summary>
        /// Determines whether two GamePadState instances are not equal.
        /// </summary>
        /// <param name="left">Object on the left of the equal sign.</param>
        /// <param name="right">Object on the right of the equal sign.</param>
        public static bool operator !=(GamePadState left, GamePadState right)
        {
            return !left.Equals(right);
        }
 
        /// <summary>
        /// Determines whether two GamePadState instances are equal.
        /// </summary>
        /// <param name="left">Object on the left of the equal sign.</param>
        /// <param name="right">Object on the right of the equal sign.</param>
        public static bool operator ==(GamePadState left, GamePadState right)
        {
            return left.Equals(right);
        }
 
        /// <summary>
        /// Returns a value that indicates whether the current instance is equal to a
        /// specified object.
        /// </summary>
        /// <param name="obj">Object with which to make the comparison.</param>
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
 
        /// <summary>
        /// Gets the hash code for this instance.
        /// </summary>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
 
        /// <summary>
        /// Retrieves a string representation of this object.
        /// </summary>
        public override string ToString()
        {
            return base.ToString();
        }
 
        #endregion
    }
}

Archive Download this file

Branches

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