Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
authorGabriel Jacobo <gabomdq@gmail.com>
Thu, 23 Jan 2014 08:44:25 -0300
changeset 81227e01e3908f41
parent 8121 1b62b081a83b
child 8123 d7b7ec662687
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
src/joystick/android/SDL_sysjoystick.c
     1.1 --- a/src/joystick/android/SDL_sysjoystick.c	Wed Jan 22 12:39:34 2014 -0500
     1.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Thu Jan 23 08:44:25 2014 -0300
     1.3 @@ -85,35 +85,70 @@
     1.4      int button = 0;
     1.5      switch(keycode) 
     1.6      {
     1.7 -        /* D-Pad key codes (API 1), these get mapped to 0...4 */
     1.8 +        /* Some gamepad buttons (API 9) */
     1.9 +        case AKEYCODE_BUTTON_A:
    1.10 +            button = SDL_CONTROLLER_BUTTON_A;
    1.11 +            break;
    1.12 +        case AKEYCODE_BUTTON_B:
    1.13 +            button = SDL_CONTROLLER_BUTTON_B;
    1.14 +            break;
    1.15 +        case AKEYCODE_BUTTON_X:
    1.16 +            button = SDL_CONTROLLER_BUTTON_X;
    1.17 +            break;
    1.18 +        case AKEYCODE_BUTTON_Y:
    1.19 +            button = SDL_CONTROLLER_BUTTON_Y;
    1.20 +            break;
    1.21 +        case AKEYCODE_BUTTON_L1:
    1.22 +            button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
    1.23 +            break;
    1.24 +        case AKEYCODE_BUTTON_R1:
    1.25 +            button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
    1.26 +            break;
    1.27 +        case AKEYCODE_BUTTON_THUMBL:
    1.28 +            button = SDL_CONTROLLER_BUTTON_LEFTSTICK;
    1.29 +            break;
    1.30 +        case AKEYCODE_BUTTON_THUMBR:
    1.31 +            button = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
    1.32 +            break;
    1.33 +        case AKEYCODE_BUTTON_START:
    1.34 +            button = SDL_CONTROLLER_BUTTON_START;
    1.35 +            break;
    1.36 +        case AKEYCODE_BUTTON_SELECT:
    1.37 +            button = SDL_CONTROLLER_BUTTON_BACK;
    1.38 +            break;
    1.39 +        case AKEYCODE_BUTTON_MODE:
    1.40 +            button = SDL_CONTROLLER_BUTTON_GUIDE;
    1.41 +            break;
    1.42 +        case AKEYCODE_BUTTON_L2:
    1.43 +            button = SDL_CONTROLLER_BUTTON_MAX; /* Not supported by GameController */
    1.44 +            break;
    1.45 +        case AKEYCODE_BUTTON_R2:
    1.46 +            button = SDL_CONTROLLER_BUTTON_MAX+1; /* Not supported by GameController */
    1.47 +            break;
    1.48 +        case AKEYCODE_BUTTON_C:
    1.49 +            button = SDL_CONTROLLER_BUTTON_MAX+2; /* Not supported by GameController */
    1.50 +            break;
    1.51 +        case AKEYCODE_BUTTON_Z:
    1.52 +            button = SDL_CONTROLLER_BUTTON_MAX+3; /* Not supported by GameController */
    1.53 +            break;
    1.54 +                        
    1.55 +        /* D-Pad key codes (API 1) */
    1.56          case AKEYCODE_DPAD_UP:
    1.57 +            button = SDL_CONTROLLER_BUTTON_DPAD_UP;
    1.58 +            break;
    1.59          case AKEYCODE_DPAD_DOWN:
    1.60 +            button = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
    1.61 +            break;
    1.62          case AKEYCODE_DPAD_LEFT:
    1.63 +            button = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
    1.64 +            break;
    1.65          case AKEYCODE_DPAD_RIGHT:
    1.66 +            button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
    1.67 +            break;
    1.68          case AKEYCODE_DPAD_CENTER:
    1.69 -            button = keycode - AKEYCODE_DPAD_UP;
    1.70 +            button = SDL_CONTROLLER_BUTTON_MAX+4; /* Not supported by GameController */
    1.71              break;
    1.72 -        
    1.73 -        /* Some gamepad buttons (API 9), these get mapped to 5...19*/
    1.74 -        case AKEYCODE_BUTTON_A:
    1.75 -        case AKEYCODE_BUTTON_B:
    1.76 -        case AKEYCODE_BUTTON_C:
    1.77 -        case AKEYCODE_BUTTON_X:
    1.78 -        case AKEYCODE_BUTTON_Y:
    1.79 -        case AKEYCODE_BUTTON_Z:
    1.80 -        case AKEYCODE_BUTTON_L1:
    1.81 -        case AKEYCODE_BUTTON_L2:
    1.82 -        case AKEYCODE_BUTTON_R1:
    1.83 -        case AKEYCODE_BUTTON_R2:
    1.84 -        case AKEYCODE_BUTTON_THUMBL:
    1.85 -        case AKEYCODE_BUTTON_THUMBR:
    1.86 -        case AKEYCODE_BUTTON_START:
    1.87 -        case AKEYCODE_BUTTON_SELECT:
    1.88 -        case AKEYCODE_BUTTON_MODE:
    1.89 -            button = keycode - AKEYCODE_BUTTON_A + 5;
    1.90 -            break;
    1.91 -            
    1.92 -        
    1.93 +
    1.94          /* More gamepad buttons (API 12), these get mapped to 20...35*/
    1.95          case AKEYCODE_BUTTON_1:
    1.96          case AKEYCODE_BUTTON_2:
    1.97 @@ -131,7 +166,7 @@
    1.98          case AKEYCODE_BUTTON_14:
    1.99          case AKEYCODE_BUTTON_15:
   1.100          case AKEYCODE_BUTTON_16:
   1.101 -            button = keycode - AKEYCODE_BUTTON_1 + 20;
   1.102 +            button = keycode - AKEYCODE_BUTTON_1 + SDL_CONTROLLER_BUTTON_MAX + 5;
   1.103              break;
   1.104              
   1.105          default: