#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
{
///
/// Represents specific information about the state of a controller,
/// including the current state of buttons and sticks.
///
public struct GamePadState
{
#region Public Properties
///
/// Indicates whether the controller is connected.
///
public bool IsConnected
{
get;
internal set;
}
///
/// Gets the packet number associated with this state.
///
public int PacketNumber
{
get;
internal set;
}
///
/// Returns a structure that identifies which buttons on the controller
/// are pressed.
///
public GamePadButtons Buttons
{
get;
internal set;
}
///
/// Returns a structure that identifies which directions of the directional pad
/// on the controller are pressed.
///
public GamePadDPad DPad
{
get;
internal set;
}
///
/// Returns a structure that indicates the position of the controller thumbsticks.
///
public GamePadThumbSticks ThumbSticks
{
get;
internal set;
}
///
/// Returns a structure that identifies the position of triggers on the controller.
///
public GamePadTriggers Triggers
{
get;
internal set;
}
#endregion
#region Public Constructors
///
/// Initializes a new instance of the GamePadState class using the specified
/// GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
///
/// Initial thumbstick state.
/// Initial trigger state.
/// Initial button state.
/// Initial directional pad state.
public GamePadState(
GamePadThumbSticks thumbSticks,
GamePadTriggers triggers,
GamePadButtons buttons,
GamePadDPad dPad
) : this() {
ThumbSticks = thumbSticks;
Triggers = triggers;
Buttons = buttons;
DPad = dPad;
IsConnected = true;
PacketNumber = 0;
}
///
/// Initializes a new instance of the GamePadState class with the specified stick,
/// trigger, and button values.
///
///
/// Left stick value. Each axis is clamped between 1.0 and 1.0.
///
///
/// Right stick value. Each axis is clamped between 1.0 and 1.0.
///
///
/// Left trigger value. This value is clamped between 0.0 and 1.0.
///
///
/// Right trigger value. This value is clamped between 0.0 and 1.0.
///
///
/// Array or parameter list of Buttons to initialize as pressed.
///
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
///
/// Determines whether specified input device buttons are pressed in this GamePadState.
///
///
/// Buttons to query. Specify a single button, or combine multiple buttons using
/// a bitwise OR operation.
///
public bool IsButtonDown(Buttons button)
{
return (Buttons.buttons & button) == button;
}
///
/// Determines whether specified input device buttons are up (not pressed) in this
/// GamePadState.
///
///
/// Buttons to query. Specify a single button, or combine multiple buttons using
/// a bitwise OR operation.
///
public bool IsButtonUp(Buttons button)
{
return (Buttons.buttons & button) != button;
}
#endregion
#region Public Static Operators and Override Methods
///
/// Determines whether two GamePadState instances are not equal.
///
/// Object on the left of the equal sign.
/// Object on the right of the equal sign.
public static bool operator !=(GamePadState left, GamePadState right)
{
return !left.Equals(right);
}
///
/// Determines whether two GamePadState instances are equal.
///
/// Object on the left of the equal sign.
/// Object on the right of the equal sign.
public static bool operator ==(GamePadState left, GamePadState right)
{
return left.Equals(right);
}
///
/// Returns a value that indicates whether the current instance is equal to a
/// specified object.
///
/// Object with which to make the comparison.
public override bool Equals(object obj)
{
return base.Equals(obj);
}
///
/// Gets the hash code for this instance.
///
public override int GetHashCode()
{
return base.GetHashCode();
}
///
/// Retrieves a string representation of this object.
///
public override string ToString()
{
return base.ToString();
}
#endregion
}
}