raylib-cpp
C++ object-oriented wrapper library for raylib.
Gamepad.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
26 #define RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 #include "./raylib-cpp-utils.hpp"
32 
33 namespace raylib {
34 class Gamepad {
35  public:
36  Gamepad(int gamepadNumber = 0) {
37  set(gamepadNumber);
38  }
39  int number;
40 
41  GETTERSETTER(int, Number, number)
42 
43  Gamepad& operator=(const Gamepad& gamepad) {
44  set(gamepad);
45  return *this;
46  }
47 
48  Gamepad& operator=(int gamepadNumber) {
49  set(gamepadNumber);
50  return *this;
51  }
52 
53  operator int() const { return number; }
54 
58  inline bool IsAvailable() const {
59  return ::IsGamepadAvailable(number);
60  }
61 
65  static inline bool IsAvailable(int number) {
66  return ::IsGamepadAvailable(number);
67  }
68 
72  inline bool IsName(const std::string& name) const {
73  return ::IsGamepadName(number, name.c_str());
74  }
75 
79  std::string GetName() const {
80  return ::GetGamepadName(number);
81  }
82 
86  operator std::string() const {
87  return GetName();
88  }
89 
93  inline bool IsButtonPressed(int button) const {
94  return ::IsGamepadButtonPressed(number, button);
95  }
96 
100  inline bool IsButtonDown(int button) const {
101  return ::IsGamepadButtonDown(number, button);
102  }
103 
107  inline bool IsButtonReleased(int button) const {
108  return ::IsGamepadButtonReleased(number, button);
109  }
110 
114  inline bool IsButtonUp(int button) const {
115  return ::IsGamepadButtonUp(number, button);
116  }
117 
121  inline int GetButtonPressed() const {
122  return ::GetGamepadButtonPressed();
123  }
124 
128  inline int GetAxisCount() const {
129  return ::GetGamepadAxisCount(number);
130  }
131 
135  inline float GetAxisMovement(int axis) const {
136  return ::GetGamepadAxisMovement(number, axis);
137  }
138 
139  protected:
140  inline void set(int gamepadNumber) {
141  number = gamepadNumber;
142  }
143 };
144 } // namespace raylib
145 
146 #endif // RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Gamepad::GetAxisMovement
float GetAxisMovement(int axis) const
Return axis movement value for a gamepad axis.
Definition: Gamepad.hpp:135
raylib::Gamepad::IsButtonReleased
bool IsButtonReleased(int button) const
Detect if a gamepad button has been released once.
Definition: Gamepad.hpp:107
raylib::Gamepad::Gamepad
Gamepad(int gamepadNumber=0)
Definition: Gamepad.hpp:36
raylib::Gamepad::IsButtonUp
bool IsButtonUp(int button) const
Detect if a gamepad button is NOT being pressed.
Definition: Gamepad.hpp:114
raylib::Gamepad::set
void set(int gamepadNumber)
Definition: Gamepad.hpp:140
raylib::Gamepad::GetName
std::string GetName() const
Return gamepad internal name id.
Definition: Gamepad.hpp:79
raylib::Gamepad
Definition: Gamepad.hpp:34
raylib::Gamepad::IsButtonPressed
bool IsButtonPressed(int button) const
Detect if a gamepad button has been pressed once.
Definition: Gamepad.hpp:93
raylib::Gamepad::operator=
Gamepad & operator=(int gamepadNumber)
Definition: Gamepad.hpp:48
raylib::Gamepad::IsButtonDown
bool IsButtonDown(int button) const
Detect if a gamepad button is being pressed.
Definition: Gamepad.hpp:100
raylib::Gamepad::GetButtonPressed
int GetButtonPressed() const
Get the last gamepad button pressed.
Definition: Gamepad.hpp:121
raylib::Gamepad::IsAvailable
bool IsAvailable() const
Detect if a gamepad is available.
Definition: Gamepad.hpp:58
raylib::Gamepad::IsName
bool IsName(const std::string &name) const
Check gamepad name (if available)
Definition: Gamepad.hpp:72
raylib::Gamepad::GetAxisCount
int GetAxisCount() const
Return gamepad axis count for a gamepad.
Definition: Gamepad.hpp:128
raylib::Gamepad::IsAvailable
static bool IsAvailable(int number)
Detect if a gamepad is available.
Definition: Gamepad.hpp:65
raylib::Gamepad::number
int number
Definition: Gamepad.hpp:39