From 07a2c00e842723970ace9eb0154e838b47d3fe82 Mon Sep 17 00:00:00 2001 From: AudioMorphology Date: Sat, 14 Jan 2017 16:18:06 +0000 Subject: [PATCH] modified: core.c --- src/core.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/src/core.c b/src/core.c index fdf5d48d..424e5725 100644 --- a/src/core.c +++ b/src/core.c @@ -2910,24 +2910,79 @@ static void InitTouch(void) static void *TouchThread(void *arg) { struct input_event ev; + GestureEvent gestureEvent; while (!windowShouldClose) { if (read(touchStream, &ev, sizeof(ev)) == (int)sizeof(ev)) { - // if pressure > 0 then simulate left mouse button click - if (ev.type == EV_ABS && ev.code == 24 && ev.value == 0) currentMouseState[0] = 0; - if (ev.type == EV_ABS && ev.code == 24 && ev.value > 0) currentMouseState[0] = 1; + if (ev.type == EV_ABS && ev.code == 24 && ev.value == 0 && currentMouseState[0] == 1) + { + currentMouseState[0] = 0; + gestureEvent.touchAction = TOUCH_UP; + gestureEvent.pointCount = 1; + gestureEvent.pointerId[0] = 0; + gestureEvent.pointerId[1] = 1; + gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[0].x /= (float)GetScreenWidth(); + gestureEvent.position[0].y /= (float)GetScreenHeight(); + gestureEvent.position[1].x /= (float)GetScreenWidth(); + gestureEvent.position[1].y /= (float)GetScreenHeight(); + ProcessGestureEvent(gestureEvent); + } + if (ev.type == EV_ABS && ev.code == 24 && ev.value > 0 && currentMouseState[0] == 0) + { + currentMouseState[0] = 1; + gestureEvent.touchAction = TOUCH_DOWN; + gestureEvent.pointCount = 1; + gestureEvent.pointerId[0] = 0; + gestureEvent.pointerId[1] = 1; + gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[0].x /= (float)GetScreenWidth(); + gestureEvent.position[0].y /= (float)GetScreenHeight(); + gestureEvent.position[1].x /= (float)GetScreenWidth(); + gestureEvent.position[1].y /= (float)GetScreenHeight(); + ProcessGestureEvent(gestureEvent); + } // x & y values supplied by event4 have been scaled & de-jittered using tslib calibration data - if (ev.type == EV_ABS && ev.code == 0) mousePosition.x = ev.value; - if (ev.type == EV_ABS && ev.code == 1) mousePosition.y = ev.value; - - if (mousePosition.x < 0) mousePosition.x = 0; - if (mousePosition.y < 0) mousePosition.y = 0; - - if (mousePosition.x > screenWidth) mousePosition.x = screenWidth; - if (mousePosition.y > screenHeight) mousePosition.y = screenHeight; + if (ev.type == EV_ABS && ev.code == 0) + { + mousePosition.x = ev.value; + if (mousePosition.x < 0) mousePosition.x = 0; + if (mousePosition.x > screenWidth) mousePosition.x = screenWidth; + gestureEvent.touchAction = TOUCH_MOVE; + gestureEvent.pointCount = 1; + gestureEvent.pointerId[0] = 0; + gestureEvent.pointerId[1] = 1; + gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[0].x /= (float)GetScreenWidth(); + gestureEvent.position[0].y /= (float)GetScreenHeight(); + gestureEvent.position[1].x /= (float)GetScreenWidth(); + gestureEvent.position[1].y /= (float)GetScreenHeight(); + ProcessGestureEvent(gestureEvent); + } + if (ev.type == EV_ABS && ev.code == 1) + { + mousePosition.y = ev.value; + if (mousePosition.y < 0) mousePosition.y = 0; + if (mousePosition.y > screenHeight) mousePosition.y = screenHeight; + gestureEvent.touchAction = TOUCH_MOVE; + gestureEvent.pointCount = 1; + gestureEvent.pointerId[0] = 0; + gestureEvent.pointerId[1] = 1; + gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y }; + gestureEvent.position[0].x /= (float)GetScreenWidth(); + gestureEvent.position[0].y /= (float)GetScreenHeight(); + gestureEvent.position[1].x /= (float)GetScreenWidth(); + gestureEvent.position[1].y /= (float)GetScreenHeight(); + ProcessGestureEvent(gestureEvent); + } + } } return NULL;