Engine/lib/sdl/src/joystick/android/SDL_sysjoystick.c
/* Function to convert Android keyCodes into SDL ones.
 * This code manipulation is done to get a sequential list of codes.
 * FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
 */
Function to convert Android keyCodes into SDL ones.
This code manipulation is done to get a sequential list of codes.
FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
Function to convert Android keyCodes into SDL ones . This code manipulation is done to get a sequential list of codes . FIXME : This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
static int
keycode_to_SDL(int keycode)
{
    int button = 0;
    switch(keycode) 
    {
        case AKEYCODE_BUTTON_A:
            button = SDL_CONTROLLER_BUTTON_A;
            break;
        case AKEYCODE_BUTTON_B:
            button = SDL_CONTROLLER_BUTTON_B;
            break;
        case AKEYCODE_BUTTON_X:
            button = SDL_CONTROLLER_BUTTON_X;
            break;
        case AKEYCODE_BUTTON_Y:
            button = SDL_CONTROLLER_BUTTON_Y;
            break;
        case AKEYCODE_BUTTON_L1:
            button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
            break;
        case AKEYCODE_BUTTON_R1:
            button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
            break;
        case AKEYCODE_BUTTON_THUMBL:
            button = SDL_CONTROLLER_BUTTON_LEFTSTICK;
            break;
        case AKEYCODE_BUTTON_THUMBR:
            button = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
            break;
        case AKEYCODE_BUTTON_START:
            button = SDL_CONTROLLER_BUTTON_START;
            break;
        case AKEYCODE_BUTTON_SELECT:
            button = SDL_CONTROLLER_BUTTON_BACK;
            break;
        case AKEYCODE_BUTTON_MODE:
            button = SDL_CONTROLLER_BUTTON_GUIDE;
            break;
        case AKEYCODE_BUTTON_L2:
            button = SDL_CONTROLLER_BUTTON_MAX; 
            break;
        case AKEYCODE_BUTTON_R2:
            button = SDL_CONTROLLER_BUTTON_MAX+1; 
            break;
        case AKEYCODE_BUTTON_C:
            button = SDL_CONTROLLER_BUTTON_MAX+2; 
            break;
        case AKEYCODE_BUTTON_Z:
            button = SDL_CONTROLLER_BUTTON_MAX+3; 
            break;
        case AKEYCODE_DPAD_UP:
            button = SDL_CONTROLLER_BUTTON_DPAD_UP;
            break;
        case AKEYCODE_DPAD_DOWN:
            button = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
            break;
        case AKEYCODE_DPAD_LEFT:
            button = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
            break;
        case AKEYCODE_DPAD_RIGHT:
            button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
            break;
        case AKEYCODE_DPAD_CENTER:
            button = SDL_CONTROLLER_BUTTON_MAX+4; 
            break;
        case AKEYCODE_BUTTON_1:
        case AKEYCODE_BUTTON_2:
        case AKEYCODE_BUTTON_3:
        case AKEYCODE_BUTTON_4:
        case AKEYCODE_BUTTON_5:
        case AKEYCODE_BUTTON_6:
        case AKEYCODE_BUTTON_7:
        case AKEYCODE_BUTTON_8:
        case AKEYCODE_BUTTON_9:
        case AKEYCODE_BUTTON_10:
        case AKEYCODE_BUTTON_11:
        case AKEYCODE_BUTTON_12:
        case AKEYCODE_BUTTON_13:
        case AKEYCODE_BUTTON_14:
        case AKEYCODE_BUTTON_15:
        case AKEYCODE_BUTTON_16:
            button = keycode - AKEYCODE_BUTTON_1 + SDL_CONTROLLER_BUTTON_MAX + 5;
            break;
        default:
            return -1;
            break;
    }
    SDL_assert(button < ANDROID_MAX_NBUTTONS);
    return button;
}
static int keycode_to_SDL ( int keycode ) { int button = 0 ; switch ( keycode ) { case AKEYCODE_BUTTON_A : button = SDL_CONTROLLER_BUTTON_A ; break ; case AKEYCODE_BUTTON_B : button = SDL_CONTROLLER_BUTTON_B ; break ; case AKEYCODE_BUTTON_X : button = SDL_CONTROLLER_BUTTON_X ; break ; case AKEYCODE_BUTTON_Y : button = SDL_CONTROLLER_BUTTON_Y ; break ; case AKEYCODE_BUTTON_L1 : button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER ; break ; case AKEYCODE_BUTTON_R1 : button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ; break ; case AKEYCODE_BUTTON_THUMBL : button = SDL_CONTROLLER_BUTTON_LEFTSTICK ; break ; case AKEYCODE_BUTTON_THUMBR : button = SDL_CONTROLLER_BUTTON_RIGHTSTICK ; break ; case AKEYCODE_BUTTON_START : button = SDL_CONTROLLER_BUTTON_START ; break ; case AKEYCODE_BUTTON_SELECT : button = SDL_CONTROLLER_BUTTON_BACK ; break ; case AKEYCODE_BUTTON_MODE : button = SDL_CONTROLLER_BUTTON_GUIDE ; break ; case AKEYCODE_BUTTON_L2 : button = SDL_CONTROLLER_BUTTON_MAX ; break ; case AKEYCODE_BUTTON_R2 : button = SDL_CONTROLLER_BUTTON_MAX + 1 ; break ; case AKEYCODE_BUTTON_C : button = SDL_CONTROLLER_BUTTON_MAX + 2 ; break ; case AKEYCODE_BUTTON_Z : button = SDL_CONTROLLER_BUTTON_MAX + 3 ; break ; case AKEYCODE_DPAD_UP : button = SDL_CONTROLLER_BUTTON_DPAD_UP ; break ; case AKEYCODE_DPAD_DOWN : button = SDL_CONTROLLER_BUTTON_DPAD_DOWN ; break ; case AKEYCODE_DPAD_LEFT : button = SDL_CONTROLLER_BUTTON_DPAD_LEFT ; break ; case AKEYCODE_DPAD_RIGHT : button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT ; break ; case AKEYCODE_DPAD_CENTER : button = SDL_CONTROLLER_BUTTON_MAX + 4 ; break ; case AKEYCODE_BUTTON_1 : case AKEYCODE_BUTTON_2 : case AKEYCODE_BUTTON_3 : case AKEYCODE_BUTTON_4 : case AKEYCODE_BUTTON_5 : case AKEYCODE_BUTTON_6 : case AKEYCODE_BUTTON_7 : case AKEYCODE_BUTTON_8 : case AKEYCODE_BUTTON_9 : case AKEYCODE_BUTTON_10 : case AKEYCODE_BUTTON_11 : case AKEYCODE_BUTTON_12 : case AKEYCODE_BUTTON_13 : case AKEYCODE_BUTTON_14 : case AKEYCODE_BUTTON_15 : case AKEYCODE_BUTTON_16 : button = keycode - AKEYCODE_BUTTON_1 + SDL_CONTROLLER_BUTTON_MAX + 5 ; break ; default : return -1 ; break ; } SDL_assert ( button < ANDROID_MAX_NBUTTONS ) ; return button ; }
Function to convert Android keyCodes into SDL ones.
Function to convert Android keyCodes into SDL ones .
/* FIXME: If this function gets too unwiedly in the future, replace with a lookup table */ /* Some gamepad buttons (API 9) */ /* Not supported by GameController */ /* Not supported by GameController */ /* Not supported by GameController */ /* Not supported by GameController */ /* D-Pad key codes (API 1) */ /* Not supported by GameController */ /* More gamepad buttons (API 12), these get mapped to 20...35*/ /* This is here in case future generations, probably with six fingers per hand, 
     * happily add new cases up above and forget to update the max number of buttons. 
     */