From 42b7b117104b957414c371871a724019b8d0b59a Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 19 Sep 2014 12:34:25 +0200 Subject: [PATCH] Android: Added support for Tap gesture --- release/win32-mingw/include/raylib.h | 4 +- release/win32-mingw/lib/libraylib.a | Bin 247866 -> 247866 bytes src/core.c | 77 ++++++++++++++++++++++++--- src/raylib.h | 4 +- 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/release/win32-mingw/include/raylib.h b/release/win32-mingw/include/raylib.h index 9c754952..4de67ba2 100644 --- a/release/win32-mingw/include/raylib.h +++ b/release/win32-mingw/include/raylib.h @@ -13,7 +13,8 @@ * Multiple textures support, including DDS and mipmaps generation * Basic 3d support for Shapes, Models, Heightmaps and Billboards * Powerful math module for Vector and Matrix operations [raymath] -* Audio loading and playing with streaming support +* Audio loading and playing with streaming support (WAV and OGG) +* Multiplatform support, including Android devices and Raspberry Pi * * Used external libs: * GLFW3 (www.glfw.org) for window/context management and input @@ -328,6 +329,7 @@ bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad b #endif #if defined(PLATFORM_ANDROID) +bool IsScreenTouched(void); // Detect screen touch event int GetTouchX(void); // Returns touch position X int GetTouchY(void); // Returns touch position Y Vector2 GetTouchPosition(void); // Returns touch position XY diff --git a/release/win32-mingw/lib/libraylib.a b/release/win32-mingw/lib/libraylib.a index c3f76e92154769ef5f85ef4e4965dedb954d402f..6cca6a27406c9d61315b2c5f1c164d44e3763555 100644 GIT binary patch delta 235 zcmdlrfq&No{t43ThK5E)7Di?pm2@Q_Y(vAz3hm;Xb0rQrqX_uMoY8^`7;jc+pYO_K zZn*j2nJ^}(pb=P`>3KbvDv*HK=7yh>RhZ39jVDL&>1!nCm*$nE7U>z8TNpFM7p0~Z zr50xdC6=UuL`)ds(+Y|~ETieUa*WrI&E1|T&$vSqX8m>rPe$c77!PFc_Qdmy-wdH5 SCLoL3OBk89moPFPI|cv>Z$+X2 delta 235 zcmdlrfq&No{t43T1{P)pCI+S(m2@Rw?8yr4;+u0N4mqO;_{N;kVmB}}Ft9W=->lF+ z-<8SCeDlFGVN5VVur|~4dN5TMKmoDM4L>KVFk2XyPmbWz*GSGU%_~VQ(lfF!HfM-0 zN=++DEzSr^EJ+24STMw=6%>P5X47-!7_ULi1sNm0JyD) Required on RPI? //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android! - EGL_BLUE_SIZE, 8, // Alternative: 5 - EGL_GREEN_SIZE, 8, // Alternative: 6 - EGL_RED_SIZE, 8, // Alternative: 5 - //EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 8, // NOTE: Required to use Depth testing! - //EGL_SAMPLES, 4, // 4x Antialiasing (Free on MALI GPUs) + EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5) + EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6) + EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5) + //EGL_ALPHA_SIZE, 8, // ALPHA bit depth + EGL_DEPTH_SIZE, 8, // Depth buffer size (Required to use Depth testing!) + //EGL_STENCIL_SIZE, 8, // Stencil buffer size + //EGL_SAMPLE_BUFFERS, 1, // Activate MSAA + //EGL_SAMPLES, 4, // 4x Antialiasing (Free on MALI GPUs) EGL_NONE }; @@ -1155,6 +1172,51 @@ static int32_t InputCallback(struct android_app *app, AInputEvent *event) touchY = AMotionEvent_getY(event, 0) * ((float)renderHeight / (float)displayHeight) - renderOffsetY/2; } + // Detect TAP event +/* + if (AMotionEvent_getPointerCount(event) > 1 ) + { + // Only support single touch + return false; + } +*/ + int32_t action = AMotionEvent_getAction(event); + unsigned int flags = action & AMOTION_EVENT_ACTION_MASK; + + switch (flags) + { + case AMOTION_EVENT_ACTION_DOWN: + { + touchId = AMotionEvent_getPointerId(event, 0); + tapTouchX = AMotionEvent_getX(event, 0); + tapTouchY = AMotionEvent_getY(event, 0); + + } break; + case AMOTION_EVENT_ACTION_UP: + { + int64_t eventTime = AMotionEvent_getEventTime(event); + int64_t downTime = AMotionEvent_getDownTime(event); + + if (eventTime - downTime <= TAP_TIMEOUT) + { + if (touchId == AMotionEvent_getPointerId(event, 0)) + { + float x = AMotionEvent_getX(event, 0) - tapTouchX; + float y = AMotionEvent_getY(event, 0) - tapTouchY; + + float densityFactor = 1.0f; + + if ( x*x + y*y < TOUCH_SLOP*TOUCH_SLOP * densityFactor) + { + // TAP Detected + touchTap = true; + } + } + } + break; + } + } + //float AMotionEvent_getX(event, size_t pointer_index); //int32_t AMotionEvent_getButtonState(event); // Pressed buttons //int32_t AMotionEvent_getPointerId(event, size_t pointer_index); @@ -1368,6 +1430,9 @@ static void PollInputEvents(void) // TODO: Check virtual keyboard (?) + // Reset touchTap event + touchTap = false; + // Poll Events (registered events) while ((ident = ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0) { diff --git a/src/raylib.h b/src/raylib.h index 9c754952..4de67ba2 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -13,7 +13,8 @@ * Multiple textures support, including DDS and mipmaps generation * Basic 3d support for Shapes, Models, Heightmaps and Billboards * Powerful math module for Vector and Matrix operations [raymath] -* Audio loading and playing with streaming support +* Audio loading and playing with streaming support (WAV and OGG) +* Multiplatform support, including Android devices and Raspberry Pi * * Used external libs: * GLFW3 (www.glfw.org) for window/context management and input @@ -328,6 +329,7 @@ bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad b #endif #if defined(PLATFORM_ANDROID) +bool IsScreenTouched(void); // Detect screen touch event int GetTouchX(void); // Returns touch position X int GetTouchY(void); // Returns touch position Y Vector2 GetTouchPosition(void); // Returns touch position XY