diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index 8a72355..b4b760e 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -366,6 +366,11 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_number ) int debuga, debugb, debugc; +#ifndef MAX_NUM_TOUCHES +#define MAX_NUM_TOUCHES 10 +#endif +bool touch_is_down[MAX_NUM_TOUCHES]; + int32_t handle_input(struct android_app* app, AInputEvent* event) { #ifdef ANDROID @@ -373,37 +378,42 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { - int action = AMotionEvent_getAction( event ); - int whichsource = action >> 8; - action &= AMOTION_EVENT_ACTION_MASK; - size_t pointerCount = AMotionEvent_getPointerCount(event); + int pointer_count = AMotionEvent_getPointerCount(event); + int32_t action = AMotionEvent_getAction(event); + int flags = action & AMOTION_EVENT_ACTION_MASK; + int id = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + int pid = AMotionEvent_getPointerId(event, id); + + if(pid > 9 || pointer_count > MAX_NUM_TOUCHES){ + printf("Pointer id larger than MAX_NUM_TOUCHES\n"); + return 0; + } - for (size_t i = 0; i < pointerCount; ++i) - { - int x, y, index; - x = AMotionEvent_getX(event, i); - y = AMotionEvent_getY(event, i); - index = AMotionEvent_getPointerId( event, i ); - - if( action == AMOTION_EVENT_ACTION_POINTER_DOWN || action == AMOTION_EVENT_ACTION_DOWN ) - { - int id = index; - if( action == AMOTION_EVENT_ACTION_POINTER_DOWN && id != whichsource ) continue; - HandleButton( x, y, id, 1 ); - ANativeActivity_showSoftInput( gapp->activity, ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED ); + switch(flags){ + case AMOTION_EVENT_ACTION_POINTER_UP: + case AMOTION_EVENT_ACTION_UP:{ + touch_is_down[pid] = 0; + HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 0); + break; } - else if( action == AMOTION_EVENT_ACTION_POINTER_UP || action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL ) - { - int id = index; - if( action == AMOTION_EVENT_ACTION_POINTER_UP && id != whichsource ) continue; - HandleButton( x, y, id, 0 ); + case AMOTION_EVENT_ACTION_POINTER_DOWN: + case AMOTION_EVENT_ACTION_DOWN:{ + touch_is_down[pid] = 1; + HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 1); + break; } - else if( action == AMOTION_EVENT_ACTION_MOVE ) - { - HandleMotion( x, y, index ); + case AMOTION_EVENT_ACTION_MOVE:{ + int off = 0; //number of touches preceeding i that are not down + for(int i = 0; i-off < pointer_count && pid+i