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-cpp-utils.hpp"
8#include "./raylib.hpp"
9
10namespace raylib {
14class Gamepad {
15public:
16 Gamepad(int gamepadNumber = 0) : number(gamepadNumber) {};
17 int number;
18
19 GETTERSETTER(int, Number, number)
20
21 Gamepad& operator=(const Gamepad& gamepad) {
22 if (this != &gamepad) {
23 set(static_cast<int>(gamepad));
24 }
25 return *this;
26 }
27
28 Gamepad& operator=(int gamepadNumber) {
29 if (this->number != gamepadNumber) {
30 set(gamepadNumber);
31 }
32 return *this;
33 }
34
35 explicit operator int() const { return number; }
36
40 [[nodiscard]] bool IsAvailable() const { return ::IsGamepadAvailable(number); }
41
45 static bool IsAvailable(int number) { return ::IsGamepadAvailable(number); }
46
50 [[nodiscard]] std::string GetName() const { return ::GetGamepadName(number); }
51
55 explicit operator std::string() const { return GetName(); }
56
60 [[nodiscard]] bool IsButtonPressed(int button) const { return ::IsGamepadButtonPressed(number, button); }
61
65 [[nodiscard]] bool IsButtonDown(int button) const { return ::IsGamepadButtonDown(number, button); }
66
70 [[nodiscard]] bool IsButtonReleased(int button) const { return ::IsGamepadButtonReleased(number, button); }
71
75 [[nodiscard]] bool IsButtonUp(int button) const { return ::IsGamepadButtonUp(number, button); }
76
80 static int GetButtonPressed() { return ::GetGamepadButtonPressed(); }
81
85 [[nodiscard]] int GetAxisCount() const { return ::GetGamepadAxisCount(number); }
86
90 [[nodiscard]] float GetAxisMovement(int axis) const { return ::GetGamepadAxisMovement(number, axis); }
91
92 int SetMappings(const std::string_view mappings) {
93 return SetGamepadMappings(mappings.data());
94 }
95
99 void SetVibration(float leftMotor, float rightMotor, float duration) const {
100 ::SetGamepadVibration(number, leftMotor, rightMotor, duration);
101 }
102protected:
103 void set(int gamepadNumber) { number = gamepadNumber; }
104};
105} // namespace raylib
106
108
109#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:70
int GetAxisCount() const
Return gamepad axis count for a gamepad.
Definition: Gamepad.hpp:85
void SetVibration(float leftMotor, float rightMotor, float duration) const
Set gamepad vibration for both motors (duration in seconds)
Definition: Gamepad.hpp:99
static bool IsAvailable(int number)
Detect if a gamepad is available.
Definition: Gamepad.hpp:45
static int GetButtonPressed()
Get the last gamepad button pressed.
Definition: Gamepad.hpp:80
bool IsAvailable() const
Detect if a gamepad is available.
Definition: Gamepad.hpp:40
bool IsButtonDown(int button) const
Detect if a gamepad button is being pressed.
Definition: Gamepad.hpp:65
std::string GetName() const
Return gamepad internal name id.
Definition: Gamepad.hpp:50
bool IsButtonUp(int button) const
Detect if a gamepad button is NOT being pressed.
Definition: Gamepad.hpp:75
bool IsButtonPressed(int button) const
Detect if a gamepad button has been pressed once.
Definition: Gamepad.hpp:60
float GetAxisMovement(int axis) const
Return axis movement value for a gamepad axis.
Definition: Gamepad.hpp:90
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8