From 2bfd9d5c593e9e64076280bd4c6e7f692ac6c122 Mon Sep 17 00:00:00 2001 From: pelya Date: Mon, 18 Jun 2012 16:49:38 +0300 Subject: [PATCH] Bigger touch area for joystick so the finger won't slip away from it --- .../src/video/android/SDL_androidinput.c | 4 ++- .../video/android/SDL_touchscreenkeyboard.c | 29 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c index 5137edab9..748c3421a 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c @@ -44,6 +44,8 @@ #include "jniwrapperstuff.h" #include "atan2i.h" +#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) +#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) static SDLKey SDL_android_keymap[KEYCODE_LAST+1]; @@ -1678,7 +1680,7 @@ extern void SDL_ANDROID_MainThreadPushJoystickAxis(int joy, int axis, int value) ev->type = SDL_JOYAXISMOTION; ev->jaxis.which = joy; ev->jaxis.axis = axis; - ev->jaxis.value = value; + ev->jaxis.value = MAX( -32768, MIN( 32767, value ) ); BufferedEventsEnd = nextEvent; SDL_mutexV(BufferedEventsMutex); diff --git a/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c index 38142750a..5f862bca8 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c @@ -48,7 +48,7 @@ #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) -enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT-1 } ; // Max amount of custom buttons +enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT-1, BUTTON_ARROWS = MAX_BUTTONS } ; // Max amount of custom buttons int SDL_ANDROID_isTouchscreenKeyboardUsed = 0; static int touchscreenKeyboardTheme = 0; @@ -58,7 +58,7 @@ static int buttonsize = 1; static int buttonDrawSize = 1; static int transparency = 128; -static SDL_Rect arrows, buttons[MAX_BUTTONS], buttonsAutoFireRect[MAX_BUTTONS_AUTOFIRE]; +static SDL_Rect arrows, arrowsExtended, buttons[MAX_BUTTONS], buttonsAutoFireRect[MAX_BUTTONS_AUTOFIRE]; static SDL_Rect arrowsDraw, buttonsDraw[MAX_BUTTONS]; static SDLKey buttonKeysyms[MAX_BUTTONS] = { SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_0)), @@ -298,7 +298,7 @@ static void drawTouchscreenKeyboardSun() int i; drawCharTex( &arrowImages[0], NULL, &arrowsDraw, 255, 255, 255, transparency ); - if(pointerInButtonRect[MAX_BUTTONS] != -1) + if(pointerInButtonRect[BUTTON_ARROWS] != -1) { SDL_Rect touch = arrowsDraw; touch.w /= 2; @@ -425,9 +425,9 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer if( InsideRect( &arrows, x, y ) ) { processed = 1; - if( pointerInButtonRect[MAX_BUTTONS] == -1 ) + if( pointerInButtonRect[BUTTON_ARROWS] == -1 ) { - pointerInButtonRect[MAX_BUTTONS] = pointerId; + pointerInButtonRect[BUTTON_ARROWS] = pointerId; joystickTouchPoints[0] = x; joystickTouchPoints[1] = y; if( SDL_ANDROID_isJoystickUsed ) @@ -481,10 +481,10 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer if( action == MOUSE_UP ) { //__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action); - if( pointerInButtonRect[MAX_BUTTONS] == pointerId ) + if( pointerInButtonRect[BUTTON_ARROWS] == pointerId ) { processed = 1; - pointerInButtonRect[MAX_BUTTONS] = -1; + pointerInButtonRect[BUTTON_ARROWS] = -1; if( SDL_ANDROID_isJoystickUsed ) { SDL_ANDROID_MainThreadPushJoystickAxis(0, 0, 0 ); @@ -532,12 +532,12 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer // Process cases when pointer leaves button area // TODO: huge code size, split it or somehow make it more readable - if( pointerInButtonRect[MAX_BUTTONS] == pointerId ) + if( pointerInButtonRect[BUTTON_ARROWS] == pointerId ) { processed = 1; - if( ! InsideRect( &arrows, x, y ) ) + if( ! InsideRect( &arrowsExtended, x, y ) ) { - pointerInButtonRect[MAX_BUTTONS] = -1; + pointerInButtonRect[BUTTON_ARROWS] = -1; if( SDL_ANDROID_isJoystickUsed ) { SDL_ANDROID_MainThreadPushJoystickAxis(0, 0, 0 ); @@ -702,6 +702,11 @@ JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thi // Move to the screen edge arrows.x = 0; arrows.y = SDL_ANDROID_sWindowHeight - arrows.h; + + arrowsExtended.w = arrows.w * 2; + arrowsExtended.h = arrows.h * 2; + arrowsExtended.x = arrows.x + arrows.w / 2 - arrowsExtended.w / 2; + arrowsExtended.y = arrows.y + arrows.h / 2 - arrowsExtended.h / 2; /* // This will leave some unused space near the edge arrows.x = SDL_ANDROID_sWindowWidth / 4; @@ -925,6 +930,10 @@ int SDL_ANDROID_SetScreenKeyboardButtonPos(int buttonId, SDL_Rect * pos) if( buttonId == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD ) { arrows = *pos; + arrowsExtended.w = arrows.w * 2; + arrowsExtended.h = arrows.h * 2; + arrowsExtended.x = arrows.x + arrows.w / 2 - arrowsExtended.w / 2; + arrowsExtended.y = arrows.y + arrows.h / 2 - arrowsExtended.h / 2; shrinkButtonRect(arrows, &arrowsDraw); } else