sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
gamepad.h
1#ifndef __GAMEPAD_H__
2#define __GAMEPAD_H__
3
4#include "app.h"
5
6namespace sgltk {
7
14class Gamepad {
15 SDL_GameController *gamepad;
16 SDL_Joystick *joystick;
17 SDL_Haptic *haptic;
18
19 static unsigned int id_max;
20 EXPORT static std::list<unsigned int> ids;
21
22 public:
27 unsigned int id;
32 unsigned int instance_id;
36 unsigned int num_axes;
40 unsigned int num_buttons;
44 unsigned int deadzone;
48 std::vector<int> buttons_pressed;
49
53 EXPORT Gamepad(unsigned int device_id);
54 EXPORT ~Gamepad();
55
61 EXPORT void set_button_state(int button, bool state);
66 EXPORT void set_deadzone(unsigned int deadzone);
73 EXPORT int get_axis_value(unsigned int axis);
79 EXPORT void play_rumble(float magnitude, unsigned int duration);
83 EXPORT void stop_rumble();
84};
85
86}
87
88#endif //__GAMEPAD_H__
unsigned int num_axes
The number of axes the gamepad has.
Definition gamepad.h:36
std::vector< int > buttons_pressed
A list of all buttons currently pressed.
Definition gamepad.h:48
void set_button_state(int button, bool state)
Sets the state of a button.
Definition gamepad.cpp:60
void set_deadzone(unsigned int deadzone)
Sets a dedzone for all axes.
Definition gamepad.cpp:72
int get_axis_value(unsigned int axis)
Call this function to get the current value of an axis.
Definition gamepad.cpp:76
unsigned int deadzone
The axis deadzone.
Definition gamepad.h:44
unsigned int num_buttons
The number of buttons the gamepad has.
Definition gamepad.h:40
Gamepad(unsigned int device_id)
Definition gamepad.cpp:8
unsigned int id
The gamepad id. When a new gamepad is attached it is assigned the first free ID starting at 0.
Definition gamepad.h:27
unsigned int instance_id
The instance ID of the gamepad as provided by an SDL2 event.
Definition gamepad.h:32
void stop_rumble()
Stops the rumble effect.
Definition gamepad.cpp:89
void play_rumble(float magnitude, unsigned int duration)
Plays a rumble effect.
Definition gamepad.cpp:83