gKit2 light
gamepads.h
1 
2 #ifndef _GAMEPAD_H
3 #define _GAMEPAD_H
4 
5 #include <SDL2/SDL.h>
6 
7 
8 struct Gamepad
9 {
10  Gamepad( ) : m_pad(NULL) {}
11  Gamepad( SDL_GameController *pad ) : m_pad(pad) {}
12 
13  ~Gamepad( ) {}
14 
16  bool connected( );
17 
19  int button( const SDL_GameControllerButton b );
21  void clear_button( const SDL_GameControllerButton b );
22 
24  float axis( const SDL_GameControllerAxis a );
26  void clear_axis( const SDL_GameControllerAxis a );
27 
28  int m_buttons[SDL_CONTROLLER_BUTTON_MAX];
29  float m_axis[SDL_CONTROLLER_AXIS_MAX];
30 
31  SDL_GameController *m_pad;
32 };
33 
34 struct Gamepads
35 {
37  Gamepads( );
38  ~Gamepads( );
39 
41  bool create( );
43  void release( );
44 
46  void update( );
47 
49  int pads( );
51  Gamepad& pad( const unsigned int index );
52 
54  int button( const unsigned int index, const SDL_GameControllerButton b );
56  void clear_button( const unsigned int index, const SDL_GameControllerButton b );
57 
59  float axis( const unsigned int index, const SDL_GameControllerAxis a );
61  void clear_axis( const unsigned int index, const SDL_GameControllerAxis a );
62 
63 protected:
64  std::vector<Gamepad> m_pads;
65 };
66 
67 #endif
float axis(const SDL_GameControllerAxis a)
renvoie la position d'un axe.
Definition: gamepads.cpp:145
int button(const SDL_GameControllerButton b)
renvoie l'etat d'un bouton.
Definition: gamepads.cpp:133
void clear_axis(const SDL_GameControllerAxis a)
re-initialise la position d'un axe.
Definition: gamepads.cpp:151
void clear_button(const SDL_GameControllerButton b)
desactive un button.
Definition: gamepads.cpp:139
bool connected()
renvoie l'etat d'un gamepad. debranche ou pas.
Definition: gamepads.cpp:128
bool create()
detection des pads connectes.
Definition: gamepads.cpp:10
void update()
lecture des infos des pads connectes.
Definition: gamepads.cpp:56
Gamepads()
constructeur par defaut.
Definition: gamepads.cpp:8
void clear_button(const unsigned int index, const SDL_GameControllerButton b)
desactive un button d'un controlleur.
Definition: gamepads.cpp:113
float axis(const unsigned int index, const SDL_GameControllerAxis a)
renvoie la position d'un axe d'un controlleur.
Definition: gamepads.cpp:118
int button(const unsigned int index, const SDL_GameControllerButton b)
renvoie l'etat d'un button d'un controlleur. cf la doc SDL2 pour les codes.
Definition: gamepads.cpp:108
void clear_axis(const unsigned int index, const SDL_GameControllerAxis a)
re-initialise la position d'un axe d'un controlleur.
Definition: gamepads.cpp:123
int pads()
renvoie le nombre de game controllers.
Definition: gamepads.cpp:97
Gamepad & pad(const unsigned int index)
renvoie un game controller.
Definition: gamepads.cpp:102