Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Gamepad.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 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 "GraphicsApi.h"
28
29namespace gf {
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31inline 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,
56 DPadUp,
57 DPadDown,
58 DPadLeft,
59 DPadRight,
60 };
61
71 enum class GamepadAxis {
72 Invalid,
73 LeftX,
74 LeftY,
75 RightX,
76 RightY,
79 };
80
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_GRAPHICS_API Gamepad {
145 public:
152 static const char *getAxisName(GamepadAxis axis);
153
160 static const char *getButtonName(GamepadButton button);
161
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_GRAPHICS_API GamepadTracker {
246 public:
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
Some gamepad related functions.
Definition: Gamepad.h:144
static bool isAttached(GamepadId id)
Check if a gamepad is attached.
static GamepadId open(GamepadHwId hwid)
Open a gamepad.
static const char * getButtonName(GamepadButton button)
Get the button name.
static void close(GamepadId id)
Close a gamepad.
static const char * getName(GamepadId id)
Get the name of the gamepad.
static const char * getAxisName(GamepadAxis axis)
Get the axis name.
static void initialize()
Initialize the already connected gamepads.
Gamepad()=delete
Deleted constructor.
A tracker for the connection/disconnection of gamepads.
Definition: Gamepad.h:245
std::size_t getConnectedGamepadCount() const
void processEvent(const Event &event)
Process an event.
GamepadTracker()
Constructor.
@ X
The x cell axis.
@ Y
The y cell axis.
GamepadId
A gamepad identifier.
Definition: Gamepad.h:123
GamepadAxis
The gamepad axis.
Definition: Gamepad.h:71
constexpr GamepadId AnyGamepad
A special identifier for all gamepads.
Definition: Gamepad.h:138
GamepadButton
The gamepad buttons.
Definition: Gamepad.h:43
GamepadHwId
A gamepad hardware identifier.
Definition: Gamepad.h:106
GamepadAxisDirection
A gamepad axis direction.
Definition: Gamepad.h:89
@ TriggerLeft
The left trigger axis.
@ TriggerRight
The right trigger axis.
@ LeftY
The left stick Y axis.
@ LeftX
The left stick X axis.
@ RightX
The right stick X axis.
@ RightY
The right stick Y axis.
@ Back
The Back button.
@ DPadLeft
The directional pad left button.
@ Invalid
Invalid button.
@ RightBumper
The right bumper button.
@ Guide
The Guide button.
@ DPadUp
The directional pad up button.
@ LeftStick
The left stick button.
@ A
The A button.
@ DPadDown
The directional pad down button.
@ RightStick
The right stick button.
@ LeftBumper
The left bumper button.
@ B
The B button.
@ Start
The Start button.
@ DPadRight
The directional pad right button.
@ Positive
Positive direction of the axis.
@ Negative
Negative direction of the axis.
The namespace for gf classes.
Defines a system event and its parameters.
Definition: Event.h:224