Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VirtualButton.GamePad.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 namespace SiliconStudio.Paradox.Input
4 {
5  /// <summary>
6  /// Describes a virtual button (a key from a keyboard, a mouse button, an axis of a joystick...etc.).
7  /// </summary>
8  public partial class VirtualButton
9  {
10  /// <summary>
11  /// GamePad virtual button.
12  /// </summary>
13  public class GamePad : VirtualButton
14  {
15  private GamePad(string name, VirtualButtonType type, int id, bool isPositiveAndNegative = false) : base(name, type, id, isPositiveAndNegative)
16  {
17  PadIndex = -1;
18  }
19 
20  private GamePad(GamePad parentPad, int index) : base(parentPad.Name, parentPad.Type, parentPad.Id, parentPad.IsPositiveAndNegative)
21  {
22  PadIndex = index;
23  }
24 
25  /// <summary>
26  /// The pad index.
27  /// </summary>
28  public readonly int PadIndex;
29 
30  /// <summary>
31  /// Return an instance of a particular GamePad.
32  /// </summary>
33  /// <param name="index">The gamepad index.</param>
34  /// <returns>A new GamePad button linked to the gamepad index.</returns>
35  public GamePad Index(int index)
36  {
37  return new GamePad(this, index);
38  }
39 
40  /// <summary>
41  /// Equivalent to <see cref="GamePadButton.PadUp"/>.
42  /// </summary>
43  public static readonly GamePad PadUp = new GamePad("GamePad.PadUp", VirtualButtonType.GamePad, 0);
44 
45  /// <summary>
46  /// Equivalent to <see cref="GamePadButton.PadDown"/>.
47  /// </summary>
48  public static readonly GamePad PadDown = new GamePad("GamePad.PadDown", VirtualButtonType.GamePad, 1);
49 
50  /// <summary>
51  /// Equivalent to <see cref="GamePadButton.PadLeft"/>.
52  /// </summary>
53  public static readonly GamePad PadLeft = new GamePad("GamePad.PadLeft", VirtualButtonType.GamePad, 2);
54 
55  /// <summary>
56  /// Equivalent to <see cref="GamePadButton.PadRight"/>.
57  /// </summary>
58  public static readonly GamePad PadRight = new GamePad("GamePad.PadRight", VirtualButtonType.GamePad, 3);
59 
60  /// <summary>
61  /// Equivalent to <see cref="GamePadButton.Start"/>.
62  /// </summary>
63  public static readonly GamePad Start = new GamePad("GamePad.Start", VirtualButtonType.GamePad, 4);
64 
65  /// <summary>
66  /// Equivalent to <see cref="GamePadButton.Back"/>.
67  /// </summary>
68  public static readonly GamePad Back = new GamePad("GamePad.Back", VirtualButtonType.GamePad, 5);
69 
70  /// <summary>
71  /// Equivalent to <see cref="GamePadButton.LeftThumb"/>.
72  /// </summary>
73  public static readonly GamePad LeftThumb = new GamePad("GamePad.LeftThumb", VirtualButtonType.GamePad, 6);
74 
75  /// <summary>
76  /// Equivalent to <see cref="GamePadButton.RightThumb"/>.
77  /// </summary>
78  public static readonly GamePad RightThumb = new GamePad("GamePad.RightThumb", VirtualButtonType.GamePad, 7);
79 
80  /// <summary>
81  /// Equivalent to <see cref="GamePadButton.LeftShoulder"/>.
82  /// </summary>
83  public static readonly GamePad LeftShoulder = new GamePad("GamePad.LeftShoulder", VirtualButtonType.GamePad, 8);
84 
85  /// <summary>
86  /// Equivalent to <see cref="GamePadButton.RightShoulder"/>.
87  /// </summary>
88  public static readonly GamePad RightShoulder = new GamePad("GamePad.RightShoulder", VirtualButtonType.GamePad, 9);
89 
90  /// <summary>
91  /// Equivalent to <see cref="GamePadButton.A"/>.
92  /// </summary>
93  public static readonly GamePad A = new GamePad("GamePad.A", VirtualButtonType.GamePad, 12);
94 
95  /// <summary>
96  /// Equivalent to <see cref="GamePadButton.B"/>.
97  /// </summary>
98  public static readonly GamePad B = new GamePad("GamePad.B", VirtualButtonType.GamePad, 13);
99 
100  /// <summary>
101  /// Equivalent to <see cref="GamePadButton.X"/>.
102  /// </summary>
103  public static readonly GamePad X = new GamePad("GamePad.X", VirtualButtonType.GamePad, 14);
104 
105  /// <summary>
106  /// Equivalent to <see cref="GamePadButton.Y"/>.
107  /// </summary>
108  public static readonly GamePad Y = new GamePad("GamePad.Y", VirtualButtonType.GamePad, 15);
109 
110  /// <summary>
111  /// Equivalent to the X Axis of <see cref="GamePadState.LeftThumb"/>.
112  /// </summary>
113  public readonly static GamePad LeftThumbAxisX = new GamePad("GamePad.LeftThumbAxisX", VirtualButtonType.GamePad, 16, true);
114 
115  /// <summary>
116  /// Equivalent to the Y Axis of <see cref="GamePadState.LeftThumb"/>.
117  /// </summary>
118  public readonly static GamePad LeftThumbAxisY = new GamePad("GamePad.LeftThumbAxisY", VirtualButtonType.GamePad, 17, true);
119 
120  /// <summary>
121  /// Equivalent to the X Axis of <see cref="GamePadState.RightThumb"/>.
122  /// </summary>
123  public readonly static GamePad RightThumbAxisX = new GamePad("GamePad.RightThumbAxisX", VirtualButtonType.GamePad, 18, true);
124 
125  /// <summary>
126  /// Equivalent to the Y Axis of <see cref="GamePadState.RightThumb"/>.
127  /// </summary>
128  public readonly static GamePad RightThumbAxisY = new GamePad("GamePad.RightThumbAxisY", VirtualButtonType.GamePad, 19, true);
129 
130  /// <summary>
131  /// Equivalent to <see cref="GamePadState.LeftTrigger"/>.
132  /// </summary>
133  public readonly static GamePad LeftTrigger = new GamePad("GamePad.LeftTrigger", VirtualButtonType.GamePad, 20);
134 
135  /// <summary>
136  /// Equivalent to <see cref="GamePadState.RightTrigger"/>.
137  /// </summary>
138  public readonly static GamePad RightTrigger = new GamePad("GamePad.RightTrigger", VirtualButtonType.GamePad, 21);
139 
140 
141  public override float GetValue(InputManagerBase manager)
142  {
143  var state = manager.GetGamePad(PadIndex);
144 
145  var index = (int)(Id & TypeIdMask);
146 
147  if (index <= 15)
148  {
149  if ((state.Buttons & (GamePadButton)(1 << index)) != 0)
150  {
151  return 1.0f;
152  }
153  }
154  else
155  {
156  switch (index)
157  {
158  case 16:
159  return state.LeftThumb.X;
160  case 17:
161  return state.LeftThumb.Y;
162  case 18:
163  return state.RightThumb.X;
164  case 19:
165  return state.RightThumb.Y;
166  case 20:
167  return state.LeftTrigger;
168  case 21:
169  return state.RightTrigger;
170  }
171  }
172 
173  return 0.0f;
174  }
175  }
176  }
177 }
readonly bool IsPositiveAndNegative
A boolean indicating whether this button supports positive and negative value.
GamePad Index(int index)
Return an instance of a particular GamePad.
readonly int Id
Unique Id for a particular button Type.
Describes a virtual button (a key from a keyboard, a mouse button, an axis of a joystick...etc.).
readonly VirtualButtonType Type
Type of this button.
Interface for input management system, including keyboard, mouse, gamepads and touch.
readonly string Name
Name of this button.
override float GetValue(InputManagerBase manager)
Gets the value associated with this virtual button from an input manager.
VirtualButtonType
Type of a VirtualButton.
GamePadButton
Buttons for gamepad returned by GamePadState.