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 
62  static inline bool IsAvailable(int number) {
63  return ::IsGamepadAvailable(number);
64  }
65 
69  inline bool IsName(const std::string& name) const {
70  return ::IsGamepadName(number, name.c_str());
71  }
72 
76  std::string GetName() const {
77  return ::GetGamepadName(number);
78  }
79 
83  operator std::string() const {
84  return GetName();
85  }
86 
90  inline bool IsButtonPressed(int button) const {
91  return ::IsGamepadButtonPressed(number, button);
92  }
93 
97  inline bool IsButtonDown(int button) const {
98  return ::IsGamepadButtonDown(number, button);
99  }
100 
104  inline bool IsButtonReleased(int button) const {
105  return ::IsGamepadButtonReleased(number, button);
106  }
107 
111  inline bool IsButtonUp(int button) const {
112  return ::IsGamepadButtonUp(number, button);
113  }
114 
118  inline int GetButtonPressed() const {
119  return ::GetGamepadButtonPressed();
120  }
121 
125  inline int GetAxisCount() const {
126  return ::GetGamepadAxisCount(number);
127  }
128 
132  inline float GetAxisMovement(int axis) const {
133  return ::GetGamepadAxisMovement(number, axis);
134  }
135 
136  protected:
137  inline void set(int gamepadNumber) {
138  number = gamepadNumber;
139  }
140 };
141 } // namespace raylib
142 
143 #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:132
raylib::Gamepad::IsButtonReleased
bool IsButtonReleased(int button) const
Detect if a gamepad button has been released once.
Definition: Gamepad.hpp:104
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:111
raylib::Gamepad::set
void set(int gamepadNumber)
Definition: Gamepad.hpp:137
raylib::Gamepad::GetName
std::string GetName() const
Return gamepad internal name id.
Definition: Gamepad.hpp:76
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:90
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:97
raylib::Gamepad::GetButtonPressed
int GetButtonPressed() const
Get the last gamepad button pressed.
Definition: Gamepad.hpp:118
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:69
raylib::Gamepad::GetAxisCount
int GetAxisCount() const
Return gamepad axis count for a gamepad.
Definition: Gamepad.hpp:125
raylib::Gamepad::IsAvailable
static bool IsAvailable(int number)
Definition: Gamepad.hpp:62
raylib::Gamepad::number
int number
Definition: Gamepad.hpp:39