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
|
using Microsoft.Xna.Framework;
using System;
namespace Microsoft.Xna.Framework.Input
{
//
// Summary:
// Represents specific information about the state of an Xbox 360 Controller,
// including the current state of buttons and sticks. Reference page contains
// links to related code samples.
public struct GamePadState
{
//
// Summary:
// Indicates whether the Xbox 360 Controller is connected. Reference page contains
// links to related code samples.
public bool IsConnected
{
get;
internal set;
}
//
// Summary:
// Gets the packet number associated with this state. Reference page contains
// links to related code samples.
public int PacketNumber
{
get;
internal set;
}
//
// Summary:
// Returns a structure that identifies what buttons on the Xbox 360 controller
// are pressed. Reference page contains links to related code samples.
public GamePadButtons Buttons
{
get;
internal set;
}
//
// Summary:
// Returns a structure that identifies what directions of the directional pad
// on the Xbox 360 Controller are pressed.
public GamePadDPad DPad
{
get;
internal set;
}
//
// Summary:
// Returns a structure that indicates the position of the Xbox 360 Controller
// sticks (thumbsticks).
public GamePadThumbSticks ThumbSticks
{
get;
internal set;
}
//
// Summary:
// Returns a structure that identifies the position of triggers on the Xbox
// 360 controller.
public GamePadTriggers Triggers
{
get;
internal set;
}
private static GamePadState initializedGamePadState = new GamePadState();
internal static GamePadState InitializedState
{
get {
return initializedGamePadState;
}
}
//
// Summary:
// Initializes a new instance of the GamePadState class using the specified
// GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.
//
// Parameters:
// thumbSticks:
// Initial thumbstick state.
//
// triggers:
// Initial trigger state.
//
// buttons:
// Initial button state.
//
// dPad:
// 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;
}
//
// Summary:
// Initializes a new instance of the GamePadState class with the specified stick,
// trigger, and button values.
//
// Parameters:
// leftThumbStick:
// Left stick value. Each axis is clamped between −1.0 and 1.0.
//
// rightThumbStick:
// Right stick value. Each axis is clamped between −1.0 and 1.0.
//
// leftTrigger:
// Left trigger value. This value is clamped between 0.0 and 1.0.
//
// rightTrigger:
// Right trigger value. This value is clamped between 0.0 and 1.0.
//
// buttons:
// 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())
{
}
//
// Summary:
// Determines whether specified input device buttons are pressed in this GamePadState.
//
// Parameters:
// button:
// 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;
}
//
// Summary:
// Determines whether specified input device buttons are up (not pressed) in
// this GamePadState.
//
// Parameters:
// button:
// 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;
}
//
// Summary:
// Determines whether two GamePadState instances are not equal.
//
// Parameters:
// left:
// Object on the left of the equal sign.
//
// right:
// Object on the right of the equal sign.
public static bool operator !=(GamePadState left, GamePadState right)
{
return !left.Equals(right);
}
//
// Summary:
// Determines whether two GamePadState instances are equal.
//
// Parameters:
// left:
// Object on the left of the equal sign.
//
// right:
// Object on the right of the equal sign.
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.
//
// Parameters:
// obj:
// Object with which to make the comparison.
public override bool Equals(object obj)
{
return base.Equals(obj);
}
//
// Summary:
// Gets the hash code for this instance.
public override int GetHashCode()
{
return base.GetHashCode();
}
//
// Summary:
// Retrieves a string representation of this object.
public override string ToString()
{
return base.ToString();
}
}
}
|