diff options
| author | ubkp <[email protected]> | 2023-07-16 08:07:29 -0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-16 13:07:29 +0200 |
| commit | b980268ba7fd1fb5083546ca3f0b20f3390fe128 (patch) | |
| tree | 1187343523312ad6227e344b12225b89f0fa7c4c /src | |
| parent | 22895ba14fab982ca74ec1526b48b924d1174e60 (diff) | |
| download | raylib-b980268ba7fd1fb5083546ca3f0b20f3390fe128.tar.gz raylib-b980268ba7fd1fb5083546ca3f0b20f3390fe128.zip | |
[example] Core Input Gestures for Web (#3172)
* [example] Core Input Gestures for Web
* Fix Doubletap for web
* Changes TAP_TIMEOUT and rgGetCurrentTime to seconds
Diffstat (limited to 'src')
| -rw-r--r-- | src/rcore.c | 6 | ||||
| -rw-r--r-- | src/rgestures.h | 16 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/rcore.c b/src/rcore.c index 6fd7a4fe..45495bb1 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -5593,8 +5593,14 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int gestureEvent.position[0].y /= (float)GetScreenHeight(); // Gesture data is sent to gestures-system for processing +#if defined(PLATFORM_WEB) + // Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself + if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent); +#else ProcessGestureEvent(gestureEvent); #endif + +#endif } // GLFW3 Cursor Position Callback, runs on mouse move diff --git a/src/rgestures.h b/src/rgestures.h index 749f440a..78dde76e 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -127,7 +127,7 @@ void SetGesturesEnabled(unsigned int flags); // Enable a set of gestu bool IsGestureDetected(int gesture); // Check if a gesture have been detected int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +float GetGestureHoldDuration(void); // Get gesture hold time in seconds Vector2 GetGestureDragVector(void); // Get gesture drag vector float GetGestureDragAngle(void); // Get gesture drag angle Vector2 GetGesturePinchVector(void); // Get gesture pinch delta @@ -181,8 +181,8 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #define FORCE_TO_SWIPE 0.0005f // 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 MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f) -#define TAP_TIMEOUT 300 // Tap minimum time, measured in milliseconds -#define PINCH_TIMEOUT 300 // Pinch minimum time, measured in milliseconds +#define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds +#define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds #define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f) //---------------------------------------------------------------------------------- @@ -209,7 +209,7 @@ typedef struct { } Touch; struct { bool resetRequired; // HOLD reset to get first touch point again - double timeDuration; // HOLD duration in milliseconds + double timeDuration; // HOLD duration in seconds } Hold; struct { Vector2 vector; // DRAG vector (between initial and current position) @@ -522,7 +522,7 @@ static float rgVector2Distance(Vector2 v1, Vector2 v2) return result; } -// Time measure returned are milliseconds +// Time measure returned are seconds static double rgGetCurrentTime(void) { double time = 0; @@ -536,7 +536,7 @@ static double rgGetCurrentTime(void) QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation! QueryPerformanceCounter(¤tTime); - time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds + time = (double)currentTime/clockFrequency; // Time in seconds #endif #if defined(__linux__) @@ -545,7 +545,7 @@ static double rgGetCurrentTime(void) clock_gettime(CLOCK_MONOTONIC, &now); unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds - time = ((double)nowTime/1000000.0); // Time in miliseconds + time = ((double)nowTime*1e-9); // Time in seconds #endif #if defined(__APPLE__) @@ -561,7 +561,7 @@ static double rgGetCurrentTime(void) mach_port_deallocate(mach_task_self(), cclock); unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds - time = ((double)nowTime/1000000.0); // Time in miliseconds + time = ((double)nowTime*1e-9); // Time in seconds #endif #endif |
