summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorubkp <[email protected]>2023-07-19 06:33:10 -0300
committerGitHub <[email protected]>2023-07-19 11:33:10 +0200
commit954c60100f2411dcfb6b57a3a39e96c71e4d2e52 (patch)
tree740073d3e65d1c05f563efd87d81a2f86ef029e3 /src
parenta9ff13a367b7bd166436b12b741b8c8199f1c85f (diff)
downloadraylib-954c60100f2411dcfb6b57a3a39e96c71e4d2e52.tar.gz
raylib-954c60100f2411dcfb6b57a3a39e96c71e4d2e52.zip
Fix GESTURE_DRAG and GESTURE_SWIPE_* issues (mostly) for web (#3183)
Diffstat (limited to 'src')
-rw-r--r--src/rgestures.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/rgestures.h b/src/rgestures.h
index 78dde76e..d8bb3b1d 100644
--- a/src/rgestures.h
+++ b/src/rgestures.h
@@ -178,8 +178,9 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
-#define FORCE_TO_SWIPE 0.0005f // Swipe force, measured in normalized screen units/time
+#define FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time
#define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f)
+#define DRAG_TIMEOUT 0.2f // Drag minimum time for web, measured in seconds
#define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
#define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds
#define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds
@@ -297,7 +298,8 @@ void ProcessGestureEvent(GestureEvent event)
}
else if (event.touchAction == TOUCH_ACTION_UP)
{
- if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.upPosition = event.position[0];
+ // A swipe can happen while the current gesture is drag, but (specially for web) also hold, so set upPosition for both cases
+ if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0];
// NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
@@ -348,7 +350,12 @@ void ProcessGestureEvent(GestureEvent event)
GESTURES.Hold.resetRequired = false;
// Detect GESTURE_DRAG
+#if defined(PLATFORM_WEB)
+ // An alternative check to detect gesture drag is necessary since moveDownPositionA on touch for web is always zero, causing the distance calculation to be inaccurate
+ if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > DRAG_TIMEOUT)
+#else
if (rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG)
+#endif
{
GESTURES.Touch.eventTime = rgGetCurrentTime();
GESTURES.current = GESTURE_DRAG;