raylib-cpp
C++ object-oriented wrapper library for raylib.
Gamepad.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
2 #define RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 
9 namespace raylib {
13 class Gamepad {
14  public:
15  Gamepad(int gamepadNumber = 0) {
16  set(gamepadNumber);
17  }
18  int number;
19 
20  GETTERSETTER(int, Number, number)
21 
22  Gamepad& operator=(const Gamepad& gamepad) {
23  set(gamepad);
24  return *this;
25  }
26 
27  Gamepad& operator=(int gamepadNumber) {
28  set(gamepadNumber);
29  return *this;
30  }
31 
32  operator int() const { return number; }
33 
37  inline bool IsAvailable() const {
38  return ::IsGamepadAvailable(number);
39  }
40 
44  static inline bool IsAvailable(int number) {
45  return ::IsGamepadAvailable(number);
46  }
47 
51  std::string GetName() const {
52  return ::GetGamepadName(number);
53  }
54 
58  operator std::string() const {
59  return GetName();
60  }
61 
65  inline bool IsButtonPressed(int button) const {
66  return ::IsGamepadButtonPressed(number, button);
67  }
68 
72  inline bool IsButtonDown(int button) const {
73  return ::IsGamepadButtonDown(number, button);
74  }
75 
79  inline bool IsButtonReleased(int button) const {
80  return ::IsGamepadButtonReleased(number, button);
81  }
82 
86  inline bool IsButtonUp(int button) const {
87  return ::IsGamepadButtonUp(number, button);
88  }
89 
93  inline int GetButtonPressed() const {
94  return ::GetGamepadButtonPressed();
95  }
96 
100  inline int GetAxisCount() const {
101  return ::GetGamepadAxisCount(number);
102  }
103 
107  inline float GetAxisMovement(int axis) const {
108  return ::GetGamepadAxisMovement(number, axis);
109  }
110 
111  private:
112  inline void set(int gamepadNumber) {
113  number = gamepadNumber;
114  }
115 };
116 } // namespace raylib
117 
118 #endif // RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
raylib::Gamepad::GetAxisMovement
float GetAxisMovement(int axis) const
Return axis movement value for a gamepad axis.
Definition: Gamepad.hpp:107
raylib::Gamepad::IsButtonReleased
bool IsButtonReleased(int button) const
Detect if a gamepad button has been released once.
Definition: Gamepad.hpp:79
raylib::Gamepad::IsButtonUp
bool IsButtonUp(int button) const
Detect if a gamepad button is NOT being pressed.
Definition: Gamepad.hpp:86
raylib::Gamepad::GetName
std::string GetName() const
Return gamepad internal name id.
Definition: Gamepad.hpp:51
raylib::Gamepad
Input-related functions: gamepads.
Definition: Gamepad.hpp:13
raylib::Gamepad::IsButtonPressed
bool IsButtonPressed(int button) const
Detect if a gamepad button has been pressed once.
Definition: Gamepad.hpp:65
raylib::Gamepad::IsButtonDown
bool IsButtonDown(int button) const
Detect if a gamepad button is being pressed.
Definition: Gamepad.hpp:72
raylib::Gamepad::GetButtonPressed
int GetButtonPressed() const
Get the last gamepad button pressed.
Definition: Gamepad.hpp:93
raylib::Gamepad::IsAvailable
bool IsAvailable() const
Detect if a gamepad is available.
Definition: Gamepad.hpp:37
raylib::Gamepad::GetAxisCount
int GetAxisCount() const
Return gamepad axis count for a gamepad.
Definition: Gamepad.hpp:100
raylib::Gamepad::IsAvailable
static bool IsAvailable(int number)
Detect if a gamepad is available.
Definition: Gamepad.hpp:44