sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
joystick.h
1#ifndef __JOYSTICK_H__
2#define __JOYSTICK_H__
3
4#include "app.h"
5
6namespace sgltk {
7
14class Joystick {
15 SDL_Joystick *joystick;
16 std::vector<int> switches;
17
18 static unsigned int id_max;
19 EXPORT static std::list<unsigned int> ids;
20
21 public:
26 unsigned int id;
31 unsigned int instance_id;
35 std::string name;
39 unsigned int num_axes;
43 unsigned int num_buttons;
47 unsigned int num_hats;
51 unsigned int deadzone;
55 std::vector<int> buttons_pressed;
56
60 Joystick(unsigned int device_id);
61 ~Joystick();
62
68 EXPORT void set_button_state(int button, bool state);
75 EXPORT void mark_switch(int button, bool mark = true);
80 EXPORT void set_deadzone(unsigned int deadzone);
86 EXPORT int get_axis_value(unsigned int axis);
92 EXPORT unsigned int get_hat_value(unsigned int hat);
93};
94
95}
96
97#endif //__JOYSTICK_H__
std::vector< int > buttons_pressed
A list of all buttons currently pressed.
Definition joystick.h:55
unsigned int instance_id
The instance ID of the gamepad as provided by an SDL2 event.
Definition joystick.h:31
int get_axis_value(unsigned int axis)
Call this function to get the current value of an axis.
Definition joystick.cpp:79
unsigned int num_axes
The number of axes the joystick has.
Definition joystick.h:39
unsigned int get_hat_value(unsigned int hat)
Call this function to get the current value of a hat.
Definition joystick.cpp:86
std::string name
The name of the joystick.
Definition joystick.h:35
void set_button_state(int button, bool state)
Sets the state of a button.
Definition joystick.cpp:46
unsigned int deadzone
The axis deadzone.
Definition joystick.h:51
unsigned int num_hats
The number of hats the joystick has.
Definition joystick.h:47
unsigned int id
The joystick id. When a new joystick is attached it is assigned the first free ID starting at 0.
Definition joystick.h:26
void set_deadzone(unsigned int deadzone)
Sets a dedzone for all axes.
Definition joystick.cpp:75
void mark_switch(int button, bool mark=true)
Marks or unmarks a button as a switch. Switches will not be added to the buttons_pressed list.
Definition joystick.cpp:61
Joystick(unsigned int device_id)
Definition joystick.cpp:8
unsigned int num_buttons
The number of buttons the joystick has.
Definition joystick.h:43