Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Gamepad.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_GAMEPAD_H
22 #define GF_GAMEPAD_H
23 
24 #include <cstdint>
25 #include <vector>
26 
27 #include "Portability.h"
28 
29 namespace gf {
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 inline namespace v1 {
32 #endif
33 
43  enum class GamepadButton {
44  Invalid,
45  A,
46  B,
47  X,
48  Y,
49  Back,
50  Guide,
51  Start,
52  LeftStick,
53  RightStick,
54  LeftBumper,
55  RightBumper,
56  DPadUp,
57  DPadDown,
58  DPadLeft,
59  DPadRight,
60  };
61 
71  enum class GamepadAxis {
72  Invalid,
73  LeftX,
74  LeftY,
75  RightX,
76  RightY,
77  TriggerLeft,
78  TriggerRight,
79  };
80 
89  enum class GamepadAxisDirection {
90  Positive,
91  Negative,
92  };
93 
94 
104  enum class GamepadHwId : int
105  #ifdef DOXYGEN_SHOULD_SKIP_THIS
106  {
107  }
108  #endif
109  ;
110 
121  enum class GamepadId : int32_t
122  #ifdef DOXYGEN_SHOULD_SKIP_THIS
123  {
124  }
125  #endif
126  ;
127 
138  constexpr GamepadId AnyGamepad = static_cast<GamepadId>(INT32_C(-1));
139 
144  class GF_API Gamepad {
145  public:
152  static const char *getAxisName(GamepadAxis axis);
153 
160  static const char *getButtonName(GamepadButton button);
161 
185  static GamepadId open(GamepadHwId hwid);
186 
193  static bool isAttached(GamepadId id);
194 
211  static void close(GamepadId id);
212 
219  static const char *getName(GamepadId id);
220 
226  static void initialize();
227 
231  Gamepad() = delete;
232  };
233 
234 
235  struct Event;
236 
245  class GF_API GamepadTracker {
246  public:
250  GamepadTracker();
251 
252  std::size_t getConnectedGamepadCount() const;
253 
257  void processEvent(const Event& event);
258 
259  private:
260  std::vector<GamepadId> m_ids;
261  };
262 
263 #ifndef DOXYGEN_SHOULD_SKIP_THIS
264 }
265 #endif
266 }
267 
268 #endif // GF_GAMEPAD_H
GamepadAxisDirection
A gamepad axis direction.
Definition: Gamepad.h:89
GamepadButton
The gamepad buttons.
Definition: Gamepad.h:43
The Guide button.
The right bumper button.
The left stick Y axis.
Some gamepad related functions.
Definition: Gamepad.h:144
The left trigger axis.
The right trigger axis.
A tracker for the connection/disconnection of gamepads.
Definition: Gamepad.h:245
The B button.
The left stick button.
The left bumper button.
GamepadHwId
A gamepad hardware identifier.
Definition: Gamepad.h:104
The Start button.
The right stick button.
GamepadAxis
The gamepad axis.
Definition: Gamepad.h:71
constexpr GamepadId AnyGamepad
A special identifier for all gamepads.
Definition: Gamepad.h:138
The Y button.
Negative direction of the axis.
The namespace for gf classes.
Definition: Action.h:35
The left stick X axis.
GamepadId
A gamepad identifier.
Definition: Gamepad.h:121
The directional pad right button.
The X button.
The directional pad up button.
The right stick X axis.
Positive direction of the axis.
The directional pad left button.
The Back button.
Defines a system event and its parameters.
Definition: Event.h:118
The A button.
The directional pad down button.
The right stick Y axis.