Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions CNFGEGLDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,44 +366,54 @@ 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
//Potentially do other things here.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be still my heart! Even better!

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the value of pid to make sure it doesn't overflow the array of touch_is_down

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<MAX_NUM_TOUCHES; i++){
if(touch_is_down[pid+i] == 0){
off++;
continue;
}
HandleMotion(AMotionEvent_getX(event, i-off), AMotionEvent_getY(event, i-off), pid+i);
}
break;
}
}
return 1;
}
else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
{
Expand Down