From 9f88a78519be8c933107ba4d2e3feb14178cdc48 Mon Sep 17 00:00:00 2001 From: pelya Date: Wed, 8 Feb 2012 15:16:26 +0200 Subject: [PATCH] New multitouch API for SDL 1.2 --- project/jni/application/src | 2 +- .../testmultitouch/AndroidAppSettings.cfg | 2 +- .../application/testmultitouch/example.cpp | 52 ++-- .../jni/sdl-1.2/src/video/android/keymap.c | 1 + .../src/video/android/SDL_androidinput.c | 281 +++--------------- .../src/video/android/SDL_androidinput.h | 2 + .../jni/sdl-1.3/src/video/android/keymap.c | 242 +++++++++++++++ 7 files changed, 318 insertions(+), 264 deletions(-) create mode 120000 project/jni/sdl-1.2/src/video/android/keymap.c create mode 100644 project/jni/sdl-1.3/src/video/android/keymap.c diff --git a/project/jni/application/src b/project/jni/application/src index f80955918..be6e061ab 120000 --- a/project/jni/application/src +++ b/project/jni/application/src @@ -1 +1 @@ -test32bpp \ No newline at end of file +testmultitouch \ No newline at end of file diff --git a/project/jni/application/testmultitouch/AndroidAppSettings.cfg b/project/jni/application/testmultitouch/AndroidAppSettings.cfg index 17a2f7560..926a26ee8 100644 --- a/project/jni/application/testmultitouch/AndroidAppSettings.cfg +++ b/project/jni/application/testmultitouch/AndroidAppSettings.cfg @@ -28,7 +28,7 @@ RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE" AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 RedefinedKeysScreenKb="1 2 3 4 5 6 1 2 3 4" -StartupMenuButtonTimeout=3000 +StartupMenuButtonTimeout=0 HiddenMenuOptions='OptionalDownloadConfig' FirstStartMenuOptions='' MultiABI=n diff --git a/project/jni/application/testmultitouch/example.cpp b/project/jni/application/testmultitouch/example.cpp index 3e2c1495c..a172cf486 100644 --- a/project/jni/application/testmultitouch/example.cpp +++ b/project/jni/application/testmultitouch/example.cpp @@ -1,4 +1,3 @@ - #include #include "SDL.h" @@ -8,16 +7,16 @@ int main(int argc, char* argv[]) SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); SDL_Surface * screen = SDL_SetVideoMode(640, 480, 16, 0); - enum { MAX_POINTERS = 16, PTR_PRESSED = 4 }; - int touchPointers[MAX_POINTERS][5]; - int accel[5]; + enum { MAX_POINTERS = 16 }; + // some random colors + int colors[MAX_POINTERS] = { 0xaaaaaa, 0xffffff, 0x888888, 0xcccccc, 0x666666, 0x999999, 0xdddddd, 0xeeeeee, 0xaaaaaa, 0xffffff, 0x888888, 0xcccccc, 0x666666, 0x999999, 0xdddddd, 0xeeeeee }; + struct TouchPointer_t { int x; int y; int pressure; int pressed; } touchPointers[MAX_POINTERS]; + int accel[3]; // Only first 2 coords are used int i; memset(touchPointers, 0, sizeof(touchPointers)); memset(accel, 0, sizeof(accel)); - SDL_Joystick * joysticks[MAX_POINTERS+1]; - for(i=0; inbuttons = 0; // Ignored + joystick->nbuttons = 0; joystick->nhats = 0; joystick->nballs = 0; if( joystick->index == 0 ) + { joystick->naxes = 3; + if(isMultitouchUsed) + { + joystick->naxes = 3 + MAX_MULTITOUCH_POINTERS; // Accelerometer/orientation, plus touch pressure/size + joystick->nbuttons = MAX_MULTITOUCH_POINTERS; + joystick->nballs = MAX_MULTITOUCH_POINTERS; + } + } else { joystick->naxes = 4; @@ -1348,6 +1363,10 @@ extern void SDL_ANDROID_PumpEvents() if( ev.jbutton.which < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[ev.jbutton.which] ) SDL_PrivateJoystickButton( SDL_ANDROID_CurrentJoysticks[ev.jbutton.which], ev.jbutton.button, ev.jbutton.state ); break; + case SDL_JOYBALLMOTION: + if( ev.jball.which < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[ev.jbutton.which] ) + SDL_PrivateJoystickBall( SDL_ANDROID_CurrentJoysticks[ev.jball.which], ev.jball.ball, ev.jball.xrel, ev.jball.yrel ); + break; #if SDL_VERSION_ATLEAST(1,3,0) case SDL_FINGERMOTION: SDL_SendTouchMotion(0, ev.tfinger.fingerId, 0, (float)ev.tfinger.x / (float)window->w, (float)ev.tfinger.y / (float)window->h, ev.tfinger.pressure); @@ -1579,6 +1598,26 @@ extern void SDL_ANDROID_MainThreadPushJoystickButton(int joy, int button, int pr BufferedEventsEnd = nextEvent; SDL_mutexV(BufferedEventsMutex); }; +extern void SDL_ANDROID_MainThreadPushJoystickBall(int joy, int ball, int x, int y) +{ + if( ! ( joy < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[joy] ) ) + return; + + int nextEvent = getNextEventAndLock(); + if( nextEvent == -1 ) + return; + + SDL_Event * ev = &BufferedEvents[BufferedEventsEnd]; + + ev->type = SDL_JOYBALLMOTION; + ev->jball.which = joy; + ev->jball.ball = ball; + ev->jball.xrel = x; + ev->jball.yrel = y; + + BufferedEventsEnd = nextEvent; + SDL_mutexV(BufferedEventsMutex); +} extern void SDL_ANDROID_MainThreadPushMultitouchButton(int id, int pressed, int x, int y, int force) { #if SDL_VERSION_ATLEAST(1,3,0) @@ -1938,237 +1977,5 @@ int SDL_ANDROID_GetScreenKeyboardRedefinedByUser() JNIEXPORT void JNICALL JAVA_EXPORT_NAME(Settings_nativeInitKeymap) ( JNIEnv* env, jobject thiz ) { - int i; - SDLKey * keymap = SDL_android_keymap; - - for (i=0; i