raylib_impl 0.1.0
Vendor raylib 5.5 : IGraphic2Module / IGraphic3Module / IAudioModule
Loading...
Searching...
No Matches
RayGamepad.hpp
Go to the documentation of this file.
1
11#ifndef RAYGAMEPAD_HPP_
12#define RAYGAMEPAD_HPP_
13
14//Raylib (without conflict)
15#include "RaylibAliases.hpp"
16
17//Interface
18#include "IGamepad.hpp"
19
20#include <unordered_map>
21
22class RayGamepad : public graphic::IGamepad {
23
24 public:
25 RayGamepad(int index = 0) : _index(index) {}
26
27 ~RayGamepad() override = default;
28
29 bool isAvailable() const override {
30 return raylib::IsGamepadAvailable(_index);
31 }
32
33 bool isButtonPressed(Button button) const override {
34 return raylib::IsGamepadButtonPressed(_index, _buttons.at(button));
35 }
36 bool isButtonDown(Button button) const override {
37 return raylib::IsGamepadButtonDown(_index, _buttons.at(button));
38 }
39 bool isButtonReleased(Button button) const override {
40 return raylib::IsGamepadButtonReleased(_index, _buttons.at(button));
41 }
42 bool isButtonUp(Button button) const override {
43 return raylib::IsGamepadButtonUp(_index, _buttons.at(button));
44 }
45
46 float getAxisMovement(Axis axis) const override {
47 return raylib::GetGamepadAxisMovement(_index, _axes.at(axis));
48 }
49
50 private:
51 int _index;
52
53 const std::unordered_map<IGamepad::Button, int> _buttons = {
54 {IGamepad::BUTTON_A, raylib::GAMEPAD_BUTTON_RIGHT_FACE_DOWN},
55 {IGamepad::BUTTON_B, raylib::GAMEPAD_BUTTON_RIGHT_FACE_RIGHT},
56 {IGamepad::BUTTON_X, raylib::GAMEPAD_BUTTON_RIGHT_FACE_LEFT},
57 {IGamepad::BUTTON_Y, raylib::GAMEPAD_BUTTON_RIGHT_FACE_UP},
58 {IGamepad::BUTTON_LEFT_BUMPER, raylib::GAMEPAD_BUTTON_LEFT_TRIGGER_1},
59 {IGamepad::BUTTON_RIGHT_BUMPER, raylib::GAMEPAD_BUTTON_RIGHT_TRIGGER_1},
60 {IGamepad::BUTTON_BACK, raylib::GAMEPAD_BUTTON_MIDDLE_LEFT},
61 {IGamepad::BUTTON_START, raylib::GAMEPAD_BUTTON_MIDDLE_RIGHT},
62 {IGamepad::BUTTON_LEFT_THUMB, raylib::GAMEPAD_BUTTON_LEFT_THUMB},
63 {IGamepad::BUTTON_RIGHT_THUMB, raylib::GAMEPAD_BUTTON_RIGHT_THUMB},
64 {IGamepad::BUTTON_DPAD_UP, raylib::GAMEPAD_BUTTON_LEFT_FACE_UP},
65 {IGamepad::BUTTON_DPAD_RIGHT, raylib::GAMEPAD_BUTTON_LEFT_FACE_RIGHT},
66 {IGamepad::BUTTON_DPAD_DOWN, raylib::GAMEPAD_BUTTON_LEFT_FACE_DOWN},
67 {IGamepad::BUTTON_DPAD_LEFT, raylib::GAMEPAD_BUTTON_LEFT_FACE_LEFT},
68 };
69
70 const std::unordered_map<IGamepad::Axis, int> _axes = {
71 {IGamepad::AXIS_LEFT_X, raylib::GAMEPAD_AXIS_LEFT_X},
72 {IGamepad::AXIS_LEFT_Y, raylib::GAMEPAD_AXIS_LEFT_Y},
73 {IGamepad::AXIS_RIGHT_X, raylib::GAMEPAD_AXIS_RIGHT_X},
74 {IGamepad::AXIS_RIGHT_Y, raylib::GAMEPAD_AXIS_RIGHT_Y},
75 {IGamepad::AXIS_LEFT_TRIGGER, raylib::GAMEPAD_AXIS_LEFT_TRIGGER},
76 {IGamepad::AXIS_RIGHT_TRIGGER, raylib::GAMEPAD_AXIS_RIGHT_TRIGGER},
77 };
78};
79
82#endif /* !RAYGAMEPAD_HPP_ */
Definition RayGamepad.hpp:22
~RayGamepad() override=default
bool isButtonReleased(Button button) const override
Definition RayGamepad.hpp:39
RayGamepad(int index=0)
Definition RayGamepad.hpp:25
bool isButtonPressed(Button button) const override
Definition RayGamepad.hpp:33
bool isButtonUp(Button button) const override
Definition RayGamepad.hpp:42
float getAxisMovement(Axis axis) const override
Definition RayGamepad.hpp:46
bool isButtonDown(Button button) const override
Definition RayGamepad.hpp:36
bool isAvailable() const override
Definition RayGamepad.hpp:29