Multiple finger events now translate correctly into an SDL_MULTIGESTURE. I still haven't mapped this into anything meaningful, but all least the wiring is now present.

This commit is contained in:
wrenczes@gmail.com
2011-06-11 09:03:21 +00:00
parent 56a8bed0e3
commit b2eaa3cb8d
6 changed files with 69 additions and 46 deletions
@@ -123,9 +123,9 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
// Touch
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
JNIEnv* env, jclass jcls,
jint action, jfloat x, jfloat y, jfloat p)
jint index, jint action, jfloat x, jfloat y, jfloat p)
{
Android_OnTouch(action, x, y, p);
Android_OnTouch(index, action, x, y, p);
}
// Accelerometer
@@ -20,7 +20,10 @@
*/
#include "SDL_config.h"
#if defined(ANDROID)
#include <android/log.h>
#endif
/* General touch handling code for SDL */
@@ -35,6 +35,8 @@
#define ACTION_MOVE 2
#define ACTION_CANCEL 3
#define ACTION_OUTSIDE 4
#define ACTION_POINTER_DOWN 5
#define ACTION_POINTER_UP 6
static SDL_TouchID gTouchID = 0;
@@ -64,7 +66,7 @@ SDL_Touch* CreateTouchInstance()
return SDL_GetTouch(touch.id);
}
void Android_OnTouch(int action, float x, float y, float p)
void Android_OnTouch(int index, int action, float x, float y, float p)
{
if (!Android_Window)
{
@@ -81,23 +83,32 @@ void Android_OnTouch(int action, float x, float y, float p)
touch = CreateTouchInstance();
}
char buffer[64];
sprintf(buffer, "Touch action: %d x: %f y: %f", action, x, y);
__android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer);
//char buffer[64];
//sprintf(buffer, "Touch action: %d x: %f y: %f, index: %d", action, x, y, index);
//__android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer);
switch(action)
{
case ACTION_DOWN:
SDL_SendFingerDown(touch->id, 1, SDL_TRUE, x, y, p);
case ACTION_POINTER_DOWN:
SDL_SendFingerDown(touch->id, index, SDL_TRUE, x, y, p);
//SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
break;
case ACTION_MOVE:
SDL_SendTouchMotion(touch->id, 1, SDL_FALSE, x, y, 1);
SDL_SendTouchMotion(touch->id, index, SDL_FALSE, x, y, 1);
break;
case ACTION_UP:
SDL_SendFingerDown(touch->id, 1, SDL_FALSE, x, y, p);
// this means a completed gesture
SDL_SendFingerDown(touch->id, index, SDL_FALSE, x, y, p);
break;
case ACTION_POINTER_UP:
// this is an individual finger up - due to some false hits on finger 0 lifting, only honor this event
// if the finger up is anything BUT finger 0, this prevents false action triggers
if (index > 0)
SDL_SendFingerDown(touch->id, index, SDL_FALSE, x, y, p);
//SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
break;
}
@@ -22,6 +22,6 @@
#include "SDL_androidvideo.h"
extern void Android_OnTouch(int action, float x, float y, float p);
extern void Android_OnTouch(int index, int action, float x, float y, float p);
/* vi: set ts=4 sw=4 expandtab: */