1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-04 21:28:54 +03:00

Open all available joysticks

This commit is contained in:
Paul Cercueil 2013-07-29 01:28:52 -04:00
parent 50b3bb2b7f
commit fcb2618286
2 changed files with 12 additions and 12 deletions

View File

@ -41,19 +41,18 @@ void InputManager::init(const string &conffile, Menu *menu) {
InputManager::InputManager()
{
#ifndef SDL_JOYSTICK_DISABLED
if (SDL_NumJoysticks() > 0) {
joystick = SDL_JoystickOpen(0);
} else {
joystick = NULL;
}
int i;
for (i = 0; i < SDL_NumJoysticks(); i++)
joysticks.push_back(SDL_JoystickOpen(i));
#endif
}
InputManager::~InputManager() {
InputManager::~InputManager()
{
#ifndef SDL_JOYSTICK_DISABLED
if (joystick) {
SDL_JoystickClose(joystick);
}
for (std::vector<SDL_Joystick *>::iterator it = joysticks.begin();
it < joysticks.end(); it++)
SDL_JoystickClose(*it);
#endif
}
@ -139,10 +138,10 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
int i;
#ifndef SDL_JOYSTICK_DISABLED
if (joystick) {
if (joysticks.size() > 0)
SDL_JoystickUpdate();
}
#endif
SDL_Event event;
if (wait) {
SDL_WaitEvent(&event);

View File

@ -23,6 +23,7 @@
#include <SDL.h>
#include <string>
#include <vector>
class Menu;
@ -74,7 +75,7 @@ private:
ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
#ifndef SDL_JOYSTICK_DISABLED
SDL_Joystick *joystick;
std::vector<SDL_Joystick *> joysticks;
#endif
};