From 5e2ad1da63efc3610119197f2033f50c637dd3ac Mon Sep 17 00:00:00 2001 From: pelya Date: Tue, 17 Aug 2010 18:47:32 +0300 Subject: [PATCH] Some processing for touchscreen keyboard --- ChangeAppSettings.sh | 10 +- .../src/video/android/SDL_androidinput.c | 53 ++---- .../src/video/android/SDL_androidinput.h | 20 ++- .../src/video/android/SDL_androidvideo.c | 10 +- .../video/android/SDL_touchscreenkeyboard.c | 154 +++++++++++++++--- .../src/video/android/jniwrapperstuff.h | 13 ++ 6 files changed, 186 insertions(+), 74 deletions(-) create mode 100644 project/sdl/sdl-1.3/src/video/android/jniwrapperstuff.h diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index 571be19fa..4a6405c92 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -48,13 +48,13 @@ if [ -n "$var" ] ; then NeedDepthBuffer="$var" fi -echo -n "\nApplication uses mouse (y) or (n) or (KEYCODE), if (KEYCODE) the screen touch will be mapped to KEYCODE ($AppUsesMouse): " +echo -n "\nApplication uses mouse, disables touchscreen keyboard currently (y) or (n) ($AppUsesMouse): " read var if [ -n "$var" ] ; then AppUsesMouse="$var" fi -echo -n "\nApplication needs arrow keys (y) or (n), if (y) the accelerometer will be used\nas arrow keys if phone does not have dpad/trackball ($AppNeedsArrowKeys): " +echo -n "\nApplication needs arrow keys (y) or (n), if (y) the accelerometer or touchscreen keyboard will be used\nas arrow keys if phone does not have dpad/trackball ($AppNeedsArrowKeys): " read var if [ -n "$var" ] ; then AppNeedsArrowKeys="$var" @@ -66,13 +66,15 @@ if [ -n "$var" ] ; then AppUsesJoystick="$var" fi -echo -n "\nApplication uses multitouch (y) or (n), multitouch events are passed as 4-axis joysticks 1-3, including pressure and size ($AppUsesMultitouch): " +echo -n "\nApplication uses multitouch (y) or (n), multitouch events are passed as 4-axis joysticks 1-5, including pressure and size ($AppUsesMultitouch): " read var if [ -n "$var" ] ; then AppUsesMultitouch="$var" fi -echo -n "\nRedefine common keys - MENU SEARCH VOLUMEUP VOLUMEDOWN ($RedefinedKeys): " +echo -n "\nRedefine common keys to SDL keysyms: TOUCHSCREEN SEARCH/CALL/DPAD_CENTER VOLUMEUP VOLUMEDOWN MENU" +echo -n "\nMENU hardware key and TOUCHSCREEN virtual 'key' are available on all devices, other keys may be absent" +echo -n "\nThe same key values are used if touchscreen keyboard is enabled ($RedefinedKeys): " read var if [ -n "$var" ] ; then RedefinedKeys="$var" diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c index 0521524ce..450bdfe0f 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c @@ -53,33 +53,30 @@ #include "SDL_androidvideo.h" #include "SDL_androidinput.h" - +#include "jniwrapperstuff.h" SDLKey SDL_android_keymap[KEYCODE_LAST+1]; -/* JNI-C++ wrapper stuff */ - -#ifndef SDL_JAVA_PACKAGE_PATH -#error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles" -#endif -#define JAVA_EXPORT_NAME2(name,package) Java_##package##_##name -#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package) -#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH) - static int isTrackballUsed = 0; static int isMouseUsed = 0; static int isJoystickUsed = 0; static int isMultitouchUsed = 0; static int isTouchscreenKeyboardUsed = 0; -static SDL_Joystick *CurrentJoysticks[4] = {NULL, NULL, NULL, NULL}; +static SDL_Joystick *CurrentJoysticks[MAX_MULTITOUCH_POINTERS+1] = {NULL,}; JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius ) { + if(pointerId < 0) + pointerId = 0; + if(pointerId > MAX_MULTITOUCH_POINTERS) + pointerId = MAX_MULTITOUCH_POINTERS; + if( isTouchscreenKeyboardUsed ) - if( SDL_android_processTouchscreenKeyboard(x, y, action) ) + if( SDL_android_processTouchscreenKeyboard(x, y, action, pointerId) ) return; + #if SDL_VIDEO_RENDER_RESIZE // Translate mouse coordinates @@ -98,27 +95,20 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j if( isMultitouchUsed ) { - if(pointerId < 0) - pointerId = 0; - if(pointerId > 2) - pointerId = 2; pointerId++; if( CurrentJoysticks[pointerId] ) { - SDL_PrivateJoystickAxis(CurrentJoysticks[0], 0, x); - SDL_PrivateJoystickAxis(CurrentJoysticks[0], 1, y); - SDL_PrivateJoystickAxis(CurrentJoysticks[0], 2, force); - SDL_PrivateJoystickAxis(CurrentJoysticks[0], 3, radius); + SDL_PrivateJoystickAxis(CurrentJoysticks[pointerId+1], 0, x); + SDL_PrivateJoystickAxis(CurrentJoysticks[pointerId+1], 1, y); + SDL_PrivateJoystickAxis(CurrentJoysticks[pointerId+1], 2, force); + SDL_PrivateJoystickAxis(CurrentJoysticks[pointerId+1], 3, radius); } } if( !isMouseUsed ) { - #ifndef SDL_ANDROID_KEYCODE_MOUSE - #define SDL_ANDROID_KEYCODE_MOUSE RETURN - #endif SDL_keysym keysym; - if( action != MOUSE_MOVE && SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_MOUSE)) != SDL_KEY(UNKNOWN) ) - SDL_SendKeyboardKey( action == MOUSE_DOWN ? SDL_PRESSED : SDL_RELEASED, GetKeysym(SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_MOUSE)) ,&keysym) ); + if( action != MOUSE_MOVE ) + SDL_SendKeyboardKey( action == MOUSE_DOWN ? SDL_PRESSED : SDL_RELEASED, GetKeysym(SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_0)) ,&keysym) ); return; } @@ -219,15 +209,8 @@ void ANDROID_InitOSKeymap() keymap[KEYCODE_BACK] = SDL_KEY(ESCAPE); -#ifndef SDL_ANDROID_KEYCODE_0 -#define SDL_ANDROID_KEYCODE_0 LCTRL -#define SDL_ANDROID_KEYCODE_1 END -#define SDL_ANDROID_KEYCODE_2 PAGEUP -#define SDL_ANDROID_KEYCODE_3 PAGEDOWN -#endif - // TODO: make this configurable - keymap[KEYCODE_MENU] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_0)); + keymap[KEYCODE_MENU] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_4)); keymap[KEYCODE_SEARCH] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_1)); keymap[KEYCODE_CALL] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_1)); @@ -594,7 +577,7 @@ int processAndroidTrackball(int key, int action) int SDL_SYS_JoystickInit(void) { - SDL_numjoysticks = 4; + SDL_numjoysticks = MAX_MULTITOUCH_POINTERS+1; return(0); } @@ -645,7 +628,7 @@ void SDL_SYS_JoystickClose(SDL_Joystick *joystick) void SDL_SYS_JoystickQuit(void) { int i; - for(i=0; i<4; i++) + for(i=0; i= r->x && x <= r->x + r->w ) && ( y >= r->y && y <= r->y + r->h ); +} + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz, jint size, jint _nbuttons ) +{ + int i; + nbuttons = _nbuttons; + // TODO: works for horizontal screen orientation only! + // TODO: configurable keyboard size + + // Arrows to the lower-left part of screen + arrows.x = 0; + arrows.w = SDL_ANDROID_sWindowWidth / 2; + arrows.h = arrows.w; + arrows.y = SDL_ANDROID_sWindowHeight - arrows.h; + + // Main button to the lower-right + buttons[0].x = SDL_ANDROID_sWindowWidth / 2; + buttons[0].w = SDL_ANDROID_sWindowWidth / 2; + buttons[0].y = SDL_ANDROID_sWindowHeight / 2; + buttons[0].h = SDL_ANDROID_sWindowHeight / 2; + + // Row of secondary buttons to the upper-right + for( i = 1; i < nbuttons; i++ ) + { + buttons[i].y = 0; + buttons[i].h = SDL_ANDROID_sWindowHeight / 2; + buttons[i].w = (SDL_ANDROID_sWindowWidth / 2) / (nbuttons - 1); + buttons[i].x = SDL_ANDROID_sWindowWidth / 2 + buttons[i].w * (i - 1); + } +}; + int SDL_android_drawTouchscreenKeyboard() { + // TODO: draw something here +}; + +static SDL_Rect * OldCoords[MAX_MULTITOUCH_POINTERS] = { NULL }; + +int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointerId) +{ + int i; + if( action == MOUSE_DOWN ) + { + if( InsideRect( &arrows, x, y ) ) + { + OldCoords[pointerId] = &arrows; + // TODO: processing + return 1; + } + + for( int i = 0; i < nbuttons; i++ ) + { + if( InsideRect( &buttons[i], x, y) ) + { + OldCoords[pointerId] = &buttons[i]; + SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym(buttonKeysyms[i]) ,&keysym) ); + return 1; + } + } + } + if( action == MOUSE_UP ) + { + if( OldCoords[pointerId] == &arrows ) + { + OldCoords[pointerId] = NULL; + // TODO: processing + return 1; + } + for( int i = 0; i < nbuttons; i++ ) + { + if( OldCoords[pointerId] == &buttons[i] ) + { + SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i]) ,&keysym) ); + OldCoords[pointerId] = NULL; + return 1; + } + } + } + if( action == MOUSE_MOVE ) + { + if( OldCoords[pointerId] && !InsideRect(OldCoords[pointerId], x, y) ) + { + SDL_android_processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId); + return SDL_android_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId); + } + } + return 0; }; diff --git a/project/sdl/sdl-1.3/src/video/android/jniwrapperstuff.h b/project/sdl/sdl-1.3/src/video/android/jniwrapperstuff.h new file mode 100644 index 000000000..6a37980aa --- /dev/null +++ b/project/sdl/sdl-1.3/src/video/android/jniwrapperstuff.h @@ -0,0 +1,13 @@ + +/* JNI-C++ wrapper stuff */ +#ifndef _JNI_WRAPPER_STUFF_H_ +#define _JNI_WRAPPER_STUFF_H_ + +#ifndef SDL_JAVA_PACKAGE_PATH +#error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles" +#endif +#define JAVA_EXPORT_NAME2(name,package) Java_##package##_##name +#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package) +#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH) + +#endif