Source/ThirdParty/SDL/src/joystick/SDL_gamecontroller.c
/*
 * given a controller button name and a joystick name update our mapping structure with it
 */
given a controller button name and a joystick name update our mapping structure with it
given a controller button name and a joystick name update our mapping structure with it
void SDL_PrivateGameControllerParseButton(const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping)
{
    int iSDLButton = 0;
    SDL_GameControllerButton button;
    SDL_GameControllerAxis axis;
    button = SDL_GameControllerGetButtonFromString(szGameButton);
    axis = SDL_GameControllerGetAxisFromString(szGameButton);
    iSDLButton = SDL_atoi(&szJoystickButton[1]);
    if (szJoystickButton[0] == 'a') {
        if (iSDLButton >= k_nMaxReverseEntries) {
            SDL_SetError("Axis index too large: %d", iSDLButton);
            return;
        }
        if (axis != SDL_CONTROLLER_AXIS_INVALID) {
            pMapping->axes[ axis ] = iSDLButton;
            pMapping->raxes[ iSDLButton ] = axis;
        } else if (button != SDL_CONTROLLER_BUTTON_INVALID) {
            pMapping->axesasbutton[ button ] = iSDLButton;
            pMapping->raxesasbutton[ iSDLButton ] = button;
        } else {
            SDL_assert(!"How did we get here?");
        }
    } else if (szJoystickButton[0] == 'b') {
        if (iSDLButton >= k_nMaxReverseEntries) {
            SDL_SetError("Button index too large: %d", iSDLButton);
            return;
        }
        if (button != SDL_CONTROLLER_BUTTON_INVALID) {
            pMapping->buttons[ button ] = iSDLButton;
            pMapping->rbuttons[ iSDLButton ] = button;
        } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
            pMapping->buttonasaxis[ axis ] = iSDLButton;
            pMapping->rbuttonasaxis[ iSDLButton ] = axis;
        } else {
            SDL_assert(!"How did we get here?");
        }
    } else if (szJoystickButton[0] == 'h') {
        int hat = SDL_atoi(&szJoystickButton[1]);
        int mask = SDL_atoi(&szJoystickButton[3]);
        if (hat >= 4) {
            SDL_SetError("Hat index too large: %d", iSDLButton);
        }
        if (button != SDL_CONTROLLER_BUTTON_INVALID) {
            int ridx;
            pMapping->hatasbutton[ button ].hat = hat;
            pMapping->hatasbutton[ button ].mask = mask;
            ridx = (hat << 4) | mask;
            pMapping->rhatasbutton[ ridx ] = button;
        } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
            SDL_assert(!"Support hat as axis");
        } else {
            SDL_assert(!"How did we get here?");
        }
    }
}
void SDL_PrivateGameControllerParseButton ( const char * szGameButton , const char * szJoystickButton , struct _SDL_ControllerMapping * pMapping ) { int iSDLButton = 0 ; SDL_GameControllerButton button ; SDL_GameControllerAxis axis ; button = SDL_GameControllerGetButtonFromString ( szGameButton ) ; axis = SDL_GameControllerGetAxisFromString ( szGameButton ) ; iSDLButton = SDL_atoi ( & szJoystickButton [ 1 ] ) ; if ( szJoystickButton [ 0 ] == ' ' ) { if ( iSDLButton >= k_nMaxReverseEntries ) { SDL_SetError ( " " , iSDLButton ) ; return ; } if ( axis != SDL_CONTROLLER_AXIS_INVALID ) { pMapping -> axes [ axis ] = iSDLButton ; pMapping -> raxes [ iSDLButton ] = axis ; } else if ( button != SDL_CONTROLLER_BUTTON_INVALID ) { pMapping -> axesasbutton [ button ] = iSDLButton ; pMapping -> raxesasbutton [ iSDLButton ] = button ; } else { SDL_assert ( ! " " ) ; } } else if ( szJoystickButton [ 0 ] == ' ' ) { if ( iSDLButton >= k_nMaxReverseEntries ) { SDL_SetError ( " " , iSDLButton ) ; return ; } if ( button != SDL_CONTROLLER_BUTTON_INVALID ) { pMapping -> buttons [ button ] = iSDLButton ; pMapping -> rbuttons [ iSDLButton ] = button ; } else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) { pMapping -> buttonasaxis [ axis ] = iSDLButton ; pMapping -> rbuttonasaxis [ iSDLButton ] = axis ; } else { SDL_assert ( ! " " ) ; } } else if ( szJoystickButton [ 0 ] == ' ' ) { int hat = SDL_atoi ( & szJoystickButton [ 1 ] ) ; int mask = SDL_atoi ( & szJoystickButton [ 3 ] ) ; if ( hat >= 4 ) { SDL_SetError ( " " , iSDLButton ) ; } if ( button != SDL_CONTROLLER_BUTTON_INVALID ) { int ridx ; pMapping -> hatasbutton [ button ] . hat = hat ; pMapping -> hatasbutton [ button ] . mask = mask ; ridx = ( hat << 4 ) | mask ; pMapping -> rhatasbutton [ ridx ] = button ; } else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) { SDL_assert ( ! " " ) ; } else { SDL_assert ( ! " " ) ; } } }
given a controller button name and a joystick name update our mapping structure with it
given a controller button name and a joystick name update our mapping structure with it