Fixed invalid axes in third on-screen joystick

This commit is contained in:
pelya
2014-03-02 22:20:52 +02:00
parent a7cc994ae0
commit 80e290a9d6
3 changed files with 16 additions and 10 deletions

View File

@@ -1398,6 +1398,7 @@ const char *SDL_SYS_JoystickName(int index)
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
{
joystick->naxes = 0;
joystick->nbuttons = 0;
joystick->nhats = 0;
joystick->nballs = 0;
@@ -1412,11 +1413,12 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
joystick->naxes = 8; // Normalized accelerometer = axes 0-1, gyroscope = axes 2-4, raw accelerometer = axes 5-7
SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1);
}
if( joystick->index >= JOY_GAMEPAD1 || joystick->index <= JOY_GAMEPAD4 )
if( joystick->index >= JOY_GAMEPAD1 && joystick->index <= JOY_GAMEPAD4 )
{
joystick->naxes = 8; // Two analog stick + two trigger buttons + Ouya touchpad
}
SDL_ANDROID_CurrentJoysticks[joystick->index] = joystick;
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Opened joystick %d axes %d buttons %d balls %d", joystick->index, joystick->naxes, joystick->nbuttons, joystick->nballs);
return(0);
}

View File

@@ -384,8 +384,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
int xx = (x - arrows[j].x - arrows[j].w / 2) * 65534 / arrows[j].w;
if( xx == 0 ) // Do not allow (0,0) coordinate, when the user touches the joystick
xx = 1;
SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, xx );
SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h );
int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4;
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, xx );
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h );
}
else
{
@@ -436,8 +437,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
pointerInButtonRect[BUTTON_ARROWS+j] = -1;
if( SDL_ANDROID_joysticksAmount > 0 )
{
SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, 0 );
SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, 0 );
int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4;
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, 0 );
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, 0 );
}
else
{
@@ -492,8 +494,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
pointerInButtonRect[BUTTON_ARROWS+j] = -1;
if( SDL_ANDROID_joysticksAmount > 0 )
{
SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, 0 );
SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, 0 );
int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4;
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, 0 );
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, 0 );
}
else
{
@@ -510,8 +513,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po
joystickTouchPoints[1+j*2] = y;
if( SDL_ANDROID_joysticksAmount > 0 )
{
SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, (x - arrows[j].x - arrows[j].w / 2) * 65534 / arrows[j].w );
SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h );
int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4;
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, (x - arrows[j].x - arrows[j].w / 2) * 65534 / arrows[j].w );
SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h );
}
else
{