raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Gamepad.hpp
1#ifndef RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
2#define RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
3
4#include <string>
5#include <string_view>
6
7#include "./raylib.hpp"
8#include "./raylib-cpp-utils.hpp"
9
10namespace raylib {
14class Gamepad {
15 public:
16 Gamepad(int gamepadNumber = 0) {
17 set(gamepadNumber);
18 }
19 int number;
20
21 GETTERSETTER(int, Number, number)
22
23 Gamepad& operator=(const Gamepad& gamepad) {
24 set(gamepad);
25 return *this;
26 }
27
28 Gamepad& operator=(int gamepadNumber) {
29 set(gamepadNumber);
30 return *this;
31 }
32
33 operator int() const { return number; }
34
38 bool IsAvailable() const {
39 return ::IsGamepadAvailable(number);
40 }
41
45 static bool IsAvailable(int number) {
46 return ::IsGamepadAvailable(number);
47 }
48
52 std::string GetName() const {
53 return ::GetGamepadName(number);
54 }
55
59 operator std::string() const {
60 return GetName();
61 }
62
66 bool IsButtonPressed(int button) const {
67 return ::IsGamepadButtonPressed(number, button);
68 }
69
73 bool IsButtonDown(int button) const {
74 return ::IsGamepadButtonDown(number, button);
75 }
76
80 bool IsButtonReleased(int button) const {
81 return ::IsGamepadButtonReleased(number, button);
82 }
83
87 bool IsButtonUp(int button) const {
88 return ::IsGamepadButtonUp(number, button);
89 }
90
94 int GetButtonPressed() const {
95 return ::GetGamepadButtonPressed();
96 }
97
101 int GetAxisCount() const {
102 return ::GetGamepadAxisCount(number);
103 }
104
108 float GetAxisMovement(int axis) const {
109 return ::GetGamepadAxisMovement(number, axis);
110 }
111
112 int SetMappings(const std::string_view mappings) {
113 return SetGamepadMappings(mappings.data());
114 }
115
116 protected:
117 void set(int gamepadNumber) {
118 number = gamepadNumber;
119 }
120};
121} // namespace raylib
122
124
125#endif // RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
Input-related functions: gamepads.
Definition: Gamepad.hpp:14
bool IsButtonReleased(int button) const
Detect if a gamepad button has been released once.
Definition: Gamepad.hpp:80
int GetAxisCount() const
Return gamepad axis count for a gamepad.
Definition: Gamepad.hpp:101
static bool IsAvailable(int number)
Detect if a gamepad is available.
Definition: Gamepad.hpp:45
bool IsAvailable() const
Detect if a gamepad is available.
Definition: Gamepad.hpp:38
int GetButtonPressed() const
Get the last gamepad button pressed.
Definition: Gamepad.hpp:94
bool IsButtonDown(int button) const
Detect if a gamepad button is being pressed.
Definition: Gamepad.hpp:73
std::string GetName() const
Return gamepad internal name id.
Definition: Gamepad.hpp:52
bool IsButtonUp(int button) const
Detect if a gamepad button is NOT being pressed.
Definition: Gamepad.hpp:87
bool IsButtonPressed(int button) const
Detect if a gamepad button has been pressed once.
Definition: Gamepad.hpp:66
float GetAxisMovement(int axis) const
Return axis movement value for a gamepad axis.
Definition: Gamepad.hpp:108