Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GamePadState.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Runtime.InteropServices;
5 
6 using SiliconStudio.Core.Mathematics;
7 
8 namespace SiliconStudio.Paradox.Input
9 {
10  /// <summary>
11  /// Describes the state of a gamepad.
12  /// </summary>
13  /// <seealso cref="InputManager.GetGamePad"/>
14  [StructLayout(LayoutKind.Sequential)]
15  public struct GamePadState : IEquatable<GamePadState>
16  {
17  /// <summary>
18  /// A boolean indicating the connect status of this gamepad. <c>true</c> if connected, otherwise <c>false</c>.
19  /// </summary>
20  public bool IsConnected;
21 
22  /// <summary>
23  /// Bitmask of the gamepad buttons.
24  /// </summary>
26 
27  /// <summary>
28  /// Left thumbstick x-axis/y-axis value. The value is in the range [-1.0f, 1.0f] for both axis.
29  /// </summary>
31 
32  /// <summary>
33  /// Right thumbstick x-axis/y-axis value. The value is in the range [-1.0f, 1.0f] for both axis.
34  /// </summary>
36 
37  /// <summary>
38  /// The left trigger analog control in the range [0, 1.0f]. See remarks.
39  /// </summary>
40  /// <remarks>
41  /// Some controllers are not supporting the range of value and may act as a simple button returning only 0 or 1.
42  /// </remarks>
43  public float LeftTrigger;
44 
45  /// <summary>
46  /// The right trigger analog control in the range [0, 1.0f]. See remarks.
47  /// </summary>
48  /// <remarks>
49  /// Some controllers are not supporting the range of value and may act as a simple button returning only 0 or 1.
50  /// </remarks>
51  public float RightTrigger;
52 
53  /// <summary>
54  /// Indicates whether the current object is equal to another object of the same type.
55  /// </summary>
56  /// <param name="other">An object to compare with this object.</param>
57  /// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
58  public bool Equals(GamePadState other)
59  {
60  return IsConnected.Equals(other.IsConnected) && Buttons.Equals(other.Buttons) && LeftThumb.Equals(other.LeftThumb) && RightThumb.Equals(other.RightThumb) && LeftTrigger.Equals(other.LeftTrigger) && RightTrigger.Equals(other.RightTrigger);
61  }
62 
63  public override bool Equals(object obj)
64  {
65  if (ReferenceEquals(null, obj)) return false;
66  return obj is GamePadState && Equals((GamePadState)obj);
67  }
68 
69  public override int GetHashCode()
70  {
71  unchecked
72  {
73  int hashCode = IsConnected.GetHashCode();
74  hashCode = (hashCode * 397) ^ Buttons.GetHashCode();
75  hashCode = (hashCode * 397) ^ LeftThumb.GetHashCode();
76  hashCode = (hashCode * 397) ^ RightThumb.GetHashCode();
77  hashCode = (hashCode * 397) ^ LeftTrigger.GetHashCode();
78  hashCode = (hashCode * 397) ^ RightTrigger.GetHashCode();
79  return hashCode;
80  }
81  }
82 
83  /// <summary>
84  /// Implements the == operator.
85  /// </summary>
86  /// <param name="left">The left gamepad value.</param>
87  /// <param name="right">The right gamepad value.</param>
88  /// <returns>The result of the operator.</returns>
89  public static bool operator ==(GamePadState left, GamePadState right)
90  {
91  return left.Equals(right);
92  }
93 
94  /// <summary>
95  /// Implements the != operator.
96  /// </summary>
97  /// <param name="left">The left gamepad value.</param>
98  /// <param name="right">The right gamepad value.</param>
99  /// <returns>The result of the operator.</returns>
100  public static bool operator !=(GamePadState left, GamePadState right)
101  {
102  return !left.Equals(right);
103  }
104 
105  public override string ToString()
106  {
107  return string.Format("IsConnected: {0}, Buttons: {1}, LeftThumb: {2}, RightThumb: {3}, LeftTrigger: {4}, RightTrigger: {5}", IsConnected, Buttons, LeftThumb, RightThumb, LeftTrigger, RightTrigger);
108  }
109  }
110 }
override bool Equals(object obj)
Definition: GamePadState.cs:63
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
bool Equals(GamePadState other)
Indicates whether the current object is equal to another object of the same type. ...
Definition: GamePadState.cs:58
Vector2 RightThumb
Right thumbstick x-axis/y-axis value. The value is in the range [-1.0f, 1.0f] for both axis...
Definition: GamePadState.cs:35
float RightTrigger
The right trigger analog control in the range [0, 1.0f]. See remarks.
Definition: GamePadState.cs:51
GamePadButton Buttons
Bitmask of the gamepad buttons.
Definition: GamePadState.cs:25
Describes the state of a gamepad.
Definition: GamePadState.cs:15
float LeftTrigger
The left trigger analog control in the range [0, 1.0f]. See remarks.
Definition: GamePadState.cs:43
bool IsConnected
A boolean indicating the connect status of this gamepad. true if connected, otherwise false...
Definition: GamePadState.cs:20
GamePadButton
Buttons for gamepad returned by GamePadState.
Vector2 LeftThumb
Left thumbstick x-axis/y-axis value. The value is in the range [-1.0f, 1.0f] for both axis...
Definition: GamePadState.cs:30