Reviewed some compilation issues #1997
This commit is contained in:
parent
59cabc7d11
commit
1627f34032
@ -254,7 +254,12 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||
# Android toolchain (must be provided for desired architecture and compiler)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/$(ANDROID_COMPILER_ARCH)-linux-androideabi$(ANDROID_API_VERSION)-clang
|
||||
ifeq ($(ANDROID_ARCH),arm)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/$(ANDROID_COMPILER_ARCH)-linux-androideabi$(ANDROID_API_VERSION)-clang
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),arm64)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/$(ANDROID_COMPILER_ARCH)-linux-android$(ANDROID_API_VERSION)-clang
|
||||
endif
|
||||
# It seems from Android NDK r22 onwards we need to use llvm-ar
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/llvm-ar
|
||||
endif
|
||||
|
46
src/core.c
46
src/core.c
@ -5021,10 +5021,10 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
// Register touch actions
|
||||
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_DOWN;
|
||||
else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_UP;
|
||||
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
|
||||
// NOTE: TOUCH_MOVE event is registered in MouseCursorPosCallback()
|
||||
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseCursorPosCallback()
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
@ -5055,7 +5055,7 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
gestureEvent.touchAction = TOUCH_MOVE;
|
||||
gestureEvent.touchAction = TOUCH_ACTION_MOVE;
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
@ -5302,9 +5302,9 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||
// Register touch points position
|
||||
CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
|
||||
|
||||
// Normalize gestureEvent.position[x] for screenWidth and screenHeight
|
||||
gestureEvent.position[i].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[i].y /= (float)GetScreenHeight();
|
||||
// Normalize CORE.Input.Touch.position[x] for screenWidth and screenHeight
|
||||
CORE.Input.Touch.position[i].x /= (float)GetScreenWidth();
|
||||
CORE.Input.Touch.position[i].y /= (float)GetScreenHeight();
|
||||
}
|
||||
|
||||
int32_t action = AMotionEvent_getAction(event);
|
||||
@ -5319,9 +5319,10 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
||||
|
||||
// Register touch actions
|
||||
if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_DOWN;
|
||||
else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_UP;
|
||||
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
|
||||
if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
|
||||
else if (flags == AMOTION_EVENT_ACTION_CANCEL) gestureEvent.touchAction = TOUCH_ACTION_CANCEL;
|
||||
|
||||
for (int i = 0; (i < gestureEvent.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
@ -5380,9 +5381,10 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
||||
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
||||
|
||||
// Register touch actions
|
||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_DOWN;
|
||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_UP;
|
||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_MOVE;
|
||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
|
||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHCANCEL) gestureEvent.touchAction = TOUCH_ACTION_CANCEL;
|
||||
|
||||
for (int i = 0; (i < gestureEvent.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
@ -5915,7 +5917,7 @@ static void *EventThread(void *arg)
|
||||
struct input_event event = { 0 };
|
||||
InputEventWorker *worker = (InputEventWorker *)arg;
|
||||
|
||||
int touchAction = -1; // 0-TOUCH_UP, 1-TOUCH_DOWN, 2-TOUCH_MOVE
|
||||
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||
bool gestureUpdate = false; // Flag to note gestures require to update
|
||||
|
||||
while (!CORE.Window.shouldClose)
|
||||
@ -5931,7 +5933,7 @@ static void *EventThread(void *arg)
|
||||
CORE.Input.Mouse.currentPosition.x += event.value;
|
||||
CORE.Input.Touch.position[0].x = CORE.Input.Mouse.currentPosition.x;
|
||||
|
||||
touchAction = 2; // TOUCH_MOVE
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
@ -5940,7 +5942,7 @@ static void *EventThread(void *arg)
|
||||
CORE.Input.Mouse.currentPosition.y += event.value;
|
||||
CORE.Input.Touch.position[0].y = CORE.Input.Mouse.currentPosition.y;
|
||||
|
||||
touchAction = 2; // TOUCH_MOVE
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
@ -5956,7 +5958,7 @@ static void *EventThread(void *arg)
|
||||
CORE.Input.Mouse.currentPosition.x = (event.value - worker->absRange.x)*CORE.Window.screen.width/worker->absRange.width; // Scale acording to absRange
|
||||
CORE.Input.Touch.position[0].x = (event.value - worker->absRange.x)*CORE.Window.screen.width/worker->absRange.width; // Scale acording to absRange
|
||||
|
||||
touchAction = 2; // TOUCH_MOVE
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
@ -5965,7 +5967,7 @@ static void *EventThread(void *arg)
|
||||
CORE.Input.Mouse.currentPosition.y = (event.value - worker->absRange.y)*CORE.Window.screen.height/worker->absRange.height; // Scale acording to absRange
|
||||
CORE.Input.Touch.position[0].y = (event.value - worker->absRange.y)*CORE.Window.screen.height/worker->absRange.height; // Scale acording to absRange
|
||||
|
||||
touchAction = 2; // TOUCH_MOVE
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
@ -6001,7 +6003,7 @@ static void *EventThread(void *arg)
|
||||
{
|
||||
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
|
||||
|
||||
touchAction = 0; // TOUCH_UP
|
||||
touchAction = 0; // TOUCH_ACTION_UP
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
@ -6009,7 +6011,7 @@ static void *EventThread(void *arg)
|
||||
{
|
||||
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 1;
|
||||
|
||||
touchAction = 1; // TOUCH_DOWN
|
||||
touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
gestureUpdate = true;
|
||||
}
|
||||
}
|
||||
@ -6024,8 +6026,8 @@ static void *EventThread(void *arg)
|
||||
{
|
||||
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = event.value;
|
||||
|
||||
if (event.value > 0) touchAction = 1; // TOUCH_DOWN
|
||||
else touchAction = 0; // TOUCH_UP
|
||||
if (event.value > 0) touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
else touchAction = 0; // TOUCH_ACTION_UP
|
||||
gestureUpdate = true;
|
||||
}
|
||||
|
||||
|
157
src/gestures.h
157
src/gestures.h
@ -61,36 +61,45 @@
|
||||
// Types and Structures Definition
|
||||
// NOTE: Below types are required for GESTURES_STANDALONE usage
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
#ifndef __cplusplus
|
||||
// Boolean type
|
||||
typedef enum { false, true } bool;
|
||||
#endif
|
||||
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
|
||||
// Gestures type
|
||||
// NOTE: It could be used as flags to enable only some gestures
|
||||
typedef enum {
|
||||
GESTURE_NONE = 0,
|
||||
GESTURE_TAP = 1,
|
||||
GESTURE_DOUBLETAP = 2,
|
||||
GESTURE_HOLD = 4,
|
||||
GESTURE_DRAG = 8,
|
||||
GESTURE_SWIPE_RIGHT = 16,
|
||||
GESTURE_SWIPE_LEFT = 32,
|
||||
GESTURE_SWIPE_UP = 64,
|
||||
GESTURE_SWIPE_DOWN = 128,
|
||||
GESTURE_PINCH_IN = 256,
|
||||
GESTURE_PINCH_OUT = 512
|
||||
} Gestures;
|
||||
// Boolean type
|
||||
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
||||
#include <stdbool.h>
|
||||
#elif !defined(__cplusplus) && !defined(bool)
|
||||
typedef enum bool { false, true } bool;
|
||||
#endif
|
||||
|
||||
typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction;
|
||||
#if !defined(RL_VECTOR2_TYPE)
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
#endif
|
||||
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
// Gestures type
|
||||
// NOTE: It could be used as flags to enable only some gestures
|
||||
typedef enum {
|
||||
GESTURE_NONE = 0,
|
||||
GESTURE_TAP = 1,
|
||||
GESTURE_DOUBLETAP = 2,
|
||||
GESTURE_HOLD = 4,
|
||||
GESTURE_DRAG = 8,
|
||||
GESTURE_SWIPE_RIGHT = 16,
|
||||
GESTURE_SWIPE_LEFT = 32,
|
||||
GESTURE_SWIPE_UP = 64,
|
||||
GESTURE_SWIPE_DOWN = 128,
|
||||
GESTURE_PINCH_IN = 256,
|
||||
GESTURE_PINCH_OUT = 512
|
||||
} Gesture;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TOUCH_ACTION_UP = 0,
|
||||
TOUCH_ACTION_DOWN,
|
||||
TOUCH_ACTION_MOVE,
|
||||
TOUCH_ACTION_CANCEL
|
||||
} TouchAction;
|
||||
|
||||
// Gesture event
|
||||
typedef struct {
|
||||
@ -115,11 +124,12 @@ extern "C" { // Prevents name mangling of functions
|
||||
|
||||
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
|
||||
void UpdateGestures(void); // Update gestures detected (must be called every frame)
|
||||
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
|
||||
bool IsGestureDetected(int gesture); // Check if a gesture have been detected
|
||||
int GetGestureDetected(void); // Get latest detected gesture
|
||||
int GetTouchPointCount(void); // Get touch points count
|
||||
|
||||
float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds
|
||||
Vector2 GetGestureDragVector(void); // Get gesture drag vector
|
||||
float GetGestureDragAngle(void); // Get gesture drag angle
|
||||
@ -194,7 +204,7 @@ typedef struct {
|
||||
Vector2 downDragPosition; // Touch drag position
|
||||
Vector2 moveDownPositionA; // First touch down position on move
|
||||
Vector2 moveDownPositionB; // Second touch down position on move
|
||||
int tapCounter; // TAP counter (one tap implies TOUCH_DOWN and TOUCH_UP actions)
|
||||
int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions)
|
||||
} Touch;
|
||||
struct {
|
||||
bool resetRequired; // HOLD reset to get first touch point again
|
||||
@ -222,19 +232,16 @@ typedef struct {
|
||||
//----------------------------------------------------------------------------------
|
||||
static GesturesData GESTURES = {
|
||||
.Touch.firstId = -1,
|
||||
.current = GESTURE_NONE, // No current gesture detected
|
||||
.current = GESTURE_NONE, // No current gesture detected
|
||||
.enabledFlags = 0b0000001111111111 // All gestures supported by default
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
// Some required math functions provided by raymath.h
|
||||
static float Vector2Angle(Vector2 initialPosition, Vector2 finalPosition);
|
||||
static float Vector2Distance(Vector2 v1, Vector2 v2);
|
||||
#endif
|
||||
static double GetCurrentTime(void);
|
||||
static float rgVector2Angle(Vector2 initialPosition, Vector2 finalPosition);
|
||||
static float rgVector2Distance(Vector2 v1, Vector2 v2);
|
||||
static double rgGetCurrentTime(void);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
@ -259,14 +266,14 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
// Reset required variables
|
||||
GESTURES.Touch.pointCount = event.pointCount; // Required on UpdateGestures()
|
||||
|
||||
if (GESTURES.Touch.pointCount < 2)
|
||||
if (GESTURES.Touch.pointCount == 1) // One touch point
|
||||
{
|
||||
if (event.touchAction == TOUCH_DOWN)
|
||||
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||
{
|
||||
GESTURES.Touch.tapCounter++; // Tap counter
|
||||
|
||||
// Detect GESTURE_DOUBLE_TAP
|
||||
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((GetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (Vector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
|
||||
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((rgGetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (rgVector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
|
||||
{
|
||||
GESTURES.current = GESTURE_DOUBLETAP;
|
||||
GESTURES.Touch.tapCounter = 0;
|
||||
@ -281,19 +288,19 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
GESTURES.Touch.downDragPosition = event.position[0];
|
||||
|
||||
GESTURES.Touch.upPosition = GESTURES.Touch.downPositionA;
|
||||
GESTURES.Touch.eventTime = GetCurrentTime();
|
||||
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||
|
||||
GESTURES.Touch.firstId = event.pointId[0];
|
||||
|
||||
GESTURES.Drag.vector = (Vector2){ 0.0f, 0.0f };
|
||||
}
|
||||
else if (event.touchAction == TOUCH_UP)
|
||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||
{
|
||||
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.upPosition = event.position[0];
|
||||
|
||||
// NOTE: GESTURES.Drag.intensity dependend on the resolution of the screen
|
||||
GESTURES.Drag.distance = Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((GetCurrentTime() - GESTURES.Swipe.timeDuration));
|
||||
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.timeDuration));
|
||||
|
||||
GESTURES.Swipe.start = false;
|
||||
|
||||
@ -301,7 +308,7 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
if ((GESTURES.Drag.intensity > FORCE_TO_SWIPE) && (GESTURES.Touch.firstId == event.pointId[0]))
|
||||
{
|
||||
// NOTE: Angle should be inverted in Y
|
||||
GESTURES.Drag.angle = 360.0f - Vector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.angle = 360.0f - rgVector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
|
||||
if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right
|
||||
else if ((GESTURES.Drag.angle > 30) && (GESTURES.Drag.angle < 120)) GESTURES.current = GESTURE_SWIPE_UP; // Up
|
||||
@ -321,13 +328,13 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
GESTURES.Touch.downDragPosition = (Vector2){ 0.0f, 0.0f };
|
||||
GESTURES.Touch.pointCount = 0;
|
||||
}
|
||||
else if (event.touchAction == TOUCH_MOVE)
|
||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||
{
|
||||
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.eventTime = GetCurrentTime();
|
||||
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||
|
||||
if (!GESTURES.Swipe.start)
|
||||
{
|
||||
GESTURES.Swipe.timeDuration = GetCurrentTime();
|
||||
GESTURES.Swipe.timeDuration = rgGetCurrentTime();
|
||||
GESTURES.Swipe.start = true;
|
||||
}
|
||||
|
||||
@ -340,9 +347,9 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
GESTURES.Hold.resetRequired = false;
|
||||
|
||||
// Detect GESTURE_DRAG
|
||||
if (Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG)
|
||||
if (rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG)
|
||||
{
|
||||
GESTURES.Touch.eventTime = GetCurrentTime();
|
||||
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||
GESTURES.current = GESTURE_DRAG;
|
||||
}
|
||||
}
|
||||
@ -351,24 +358,24 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
GESTURES.Drag.vector.y = GESTURES.Touch.moveDownPositionA.y - GESTURES.Touch.downDragPosition.y;
|
||||
}
|
||||
}
|
||||
else // Two touch points
|
||||
else if (GESTURES.Touch.pointCount == 2) // Two touch points
|
||||
{
|
||||
if (event.touchAction == TOUCH_DOWN)
|
||||
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||
{
|
||||
GESTURES.Touch.downPositionA = event.position[0];
|
||||
GESTURES.Touch.downPositionB = event.position[1];
|
||||
|
||||
//GESTURES.Pinch.distance = Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
|
||||
//GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
|
||||
|
||||
GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x;
|
||||
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
|
||||
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
}
|
||||
else if (event.touchAction == TOUCH_MOVE)
|
||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||
{
|
||||
GESTURES.Pinch.distance = Vector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
|
||||
GESTURES.Touch.downPositionA = GESTURES.Touch.moveDownPositionA;
|
||||
GESTURES.Touch.downPositionB = GESTURES.Touch.moveDownPositionB;
|
||||
@ -379,21 +386,21 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
|
||||
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
|
||||
|
||||
if ((Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (Vector2Distance(GESTURES.Touch.downPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
|
||||
if ((rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.downPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
|
||||
{
|
||||
if ((Vector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) - GESTURES.Pinch.distance) < 0) GESTURES.current = GESTURE_PINCH_IN;
|
||||
if ((rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) - GESTURES.Pinch.distance) < 0) GESTURES.current = GESTURE_PINCH_IN;
|
||||
else GESTURES.current = GESTURE_PINCH_OUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
}
|
||||
|
||||
// NOTE: Angle should be inverted in Y
|
||||
GESTURES.Pinch.angle = 360.0f - Vector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
GESTURES.Pinch.angle = 360.0f - rgVector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
}
|
||||
else if (event.touchAction == TOUCH_UP)
|
||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||
{
|
||||
GESTURES.Pinch.distance = 0.0f;
|
||||
GESTURES.Pinch.angle = 0.0f;
|
||||
@ -403,6 +410,10 @@ void ProcessGestureEvent(GestureEvent event)
|
||||
GESTURES.current = GESTURE_NONE;
|
||||
}
|
||||
}
|
||||
else if (GESTURES.Touch.pointCount > 2) // More than two touch points
|
||||
{
|
||||
// TODO.
|
||||
}
|
||||
}
|
||||
|
||||
// Update gestures detected (must be called every frame)
|
||||
@ -414,13 +425,13 @@ void UpdateGestures(void)
|
||||
if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) && (GESTURES.Touch.pointCount < 2))
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
}
|
||||
|
||||
if (((GetCurrentTime() - GESTURES.Touch.eventTime) > TAP_TIMEOUT) && (GESTURES.current == GESTURE_DRAG) && (GESTURES.Touch.pointCount < 2))
|
||||
if (((rgGetCurrentTime() - GESTURES.Touch.eventTime) > TAP_TIMEOUT) && (GESTURES.current == GESTURE_DRAG) && (GESTURES.Touch.pointCount < 2))
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
GESTURES.Hold.resetRequired = true;
|
||||
}
|
||||
|
||||
@ -445,7 +456,7 @@ float GetGestureHoldDuration(void)
|
||||
|
||||
double time = 0.0;
|
||||
|
||||
if (GESTURES.current == GESTURE_HOLD) time = GetCurrentTime() - GESTURES.Hold.timeDuration;
|
||||
if (GESTURES.current == GESTURE_HOLD) time = rgGetCurrentTime() - GESTURES.Hold.timeDuration;
|
||||
|
||||
return (float)time;
|
||||
}
|
||||
@ -453,7 +464,7 @@ float GetGestureHoldDuration(void)
|
||||
// Get drag vector (between initial touch point to current)
|
||||
Vector2 GetGestureDragVector(void)
|
||||
{
|
||||
// NOTE: drag vector is calculated on one touch points TOUCH_MOVE
|
||||
// NOTE: drag vector is calculated on one touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Drag.vector;
|
||||
}
|
||||
@ -462,7 +473,7 @@ Vector2 GetGestureDragVector(void)
|
||||
// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise
|
||||
float GetGestureDragAngle(void)
|
||||
{
|
||||
// NOTE: drag angle is calculated on one touch points TOUCH_UP
|
||||
// NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP
|
||||
|
||||
return GESTURES.Drag.angle;
|
||||
}
|
||||
@ -471,7 +482,7 @@ float GetGestureDragAngle(void)
|
||||
Vector2 GetGesturePinchVector(void)
|
||||
{
|
||||
// NOTE: The position values used for GESTURES.Pinch.distance are not modified like the position values of [core.c]-->GetTouchPosition(int index)
|
||||
// NOTE: pinch distance is calculated on two touch points TOUCH_MOVE
|
||||
// NOTE: pinch distance is calculated on two touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Pinch.vector;
|
||||
}
|
||||
@ -480,7 +491,7 @@ Vector2 GetGesturePinchVector(void)
|
||||
// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise
|
||||
float GetGesturePinchAngle(void)
|
||||
{
|
||||
// NOTE: pinch angle is calculated on two touch points TOUCH_MOVE
|
||||
// NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Pinch.angle;
|
||||
}
|
||||
@ -488,9 +499,8 @@ float GetGesturePinchAngle(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
// Get angle from two-points vector with X-axis
|
||||
static float Vector2Angle(Vector2 v1, Vector2 v2)
|
||||
static float rgVector2Angle(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
|
||||
|
||||
@ -500,7 +510,7 @@ static float Vector2Angle(Vector2 v1, Vector2 v2)
|
||||
}
|
||||
|
||||
// Calculate distance between two Vector2
|
||||
static float Vector2Distance(Vector2 v1, Vector2 v2)
|
||||
static float rgVector2Distance(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float result;
|
||||
|
||||
@ -511,10 +521,9 @@ static float Vector2Distance(Vector2 v1, Vector2 v2)
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Time measure returned are milliseconds
|
||||
static double GetCurrentTime(void)
|
||||
static double rgGetCurrentTime(void)
|
||||
{
|
||||
double time = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user