aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2014-09-19 12:34:25 +0200
committerraysan5 <raysan5@gmail.com>2014-09-19 12:34:25 +0200
commit42b7b117104b957414c371871a724019b8d0b59a (patch)
tree05773c6809b410c0200ce8b94e48839a41d4dc76 /src
parente915812730641e56efa4014eba2406f25b157615 (diff)
downloadraylib-42b7b117104b957414c371871a724019b8d0b59a.tar.gz
raylib-42b7b117104b957414c371871a724019b8d0b59a.zip
Android: Added support for Tap gesture
Diffstat (limited to 'src')
-rw-r--r--src/core.c77
-rw-r--r--src/raylib.h4
2 files changed, 74 insertions, 7 deletions
diff --git a/src/core.c b/src/core.c
index 5bea82f9..abd60524 100644
--- a/src/core.c
+++ b/src/core.c
@@ -108,6 +108,16 @@ static struct android_app *app; // Android activity
static struct android_poll_source *source; // Android events polling source
static int ident, events;
static bool windowReady = false; // Used to detect display initialization
+
+// Gestures detection variables
+static float tapTouchX, tapTouchY;
+static bool touchTap = false;
+static int32_t touchId;
+const int32_t DOUBLE_TAP_TIMEOUT = 300*1000000;
+const int32_t DOUBLE_TAP_SLOP = 100;
+const int32_t TAP_TIMEOUT = 180*1000000;
+const int32_t TOUCH_SLOP = 8;
+
#elif defined(PLATFORM_RPI)
static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device)
@@ -816,6 +826,11 @@ bool IsGamepadButtonUp(int gamepad, int button)
#endif
#if defined(PLATFORM_ANDROID)
+bool IsScreenTouched(void)
+{
+ return touchTap;
+}
+
// Returns touch position X
int GetTouchX(void)
{
@@ -958,12 +973,14 @@ static void InitDisplay(int width, int height)
{
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> 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