QTfrontend/util/SDLInteraction.cpp
changeset 13514 31d0b0911cba
parent 11362 ed5a6478e710
child 13515 c5365f05d4de
equal deleted inserted replaced
13513:d8462cc9d42d 13514:31d0b0911cba
   103 void SDLInteraction::addGameControllerKeys() const
   103 void SDLInteraction::addGameControllerKeys() const
   104 {
   104 {
   105     QStringList result;
   105     QStringList result;
   106 
   106 
   107 #if SDL_VERSION_ATLEAST(2, 0, 0)
   107 #if SDL_VERSION_ATLEAST(2, 0, 0)
   108 // TODO or not TODO?
       
   109 #else
       
   110     int i = 0;
   108     int i = 0;
   111     while(i < 1024 && sdlkeys[i][1][0] != '\0')
   109     while(i < 1024 && sdlkeys[i][1][0] != '\0')
   112         i++;
   110         i++;
   113 
   111 
   114     // Iterate through all game controllers
   112     // Iterate through all game controllers
       
   113     qDebug("Detecting controllers ...");
   115     for(int jid = 0; jid < SDL_NumJoysticks(); jid++)
   114     for(int jid = 0; jid < SDL_NumJoysticks(); jid++)
   116     {
   115     {
   117         SDL_Joystick* joy = SDL_JoystickOpen(jid);
   116         SDL_Joystick* joy = SDL_JoystickOpen(jid);
   118 
   117 
   119         // Retrieve the game controller's name and strip "Controller (...)" that's added by some drivers (English only)
   118         // Retrieve the game controller's name
   120         QString joyname = QString(SDL_JoystickName(jid)).replace(QRegExp("^Controller \\((.*)\\)$"), "\\1");
   119         QString joyname = QString(SDL_JoystickNameForIndex(jid));
       
   120 
       
   121         // Strip "Controller (...)" that's added by some drivers (English only)
       
   122         joyname.replace(QRegExp("^Controller \\((.*)\\)$"), "\\1");
       
   123 
       
   124         qDebug("- Controller no. %d: %s", jid, qPrintable(joyname));
   121 
   125 
   122         // Connected Xbox 360 controller? Use specific button names then
   126         // Connected Xbox 360 controller? Use specific button names then
   123         // Might be interesting to add 'named' buttons for the most often used gamepads
   127         // Might be interesting to add 'named' buttons for the most often used gamepads
   124         bool isxb = joyname.contains("Xbox 360");
   128         bool isxb = joyname.contains("Xbox 360");
   125 
   129