Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] All swipe gestures are being interpreted as GESTURE_SWIPE_LEFT on web browsers with Touch Screen. #3141

Closed
3 tasks done
ghost opened this issue Jun 29, 2023 · 3 comments · Fixed by #3151
Closed
3 tasks done

Comments

@ghost
Copy link

ghost commented Jun 29, 2023

  • I tested it on latest raylib version from master branch.
  • I checked and there was a similar issue #2418 already reported, but no solution was found at the time.
  • My code has no errors or misuse of raylib.

Issue description

All swipe gestures are being interpreted as GESTURE_SWIPE_LEFT on web browsers with Touch Screen:

  • Firefox, on Android;
  • Chrome, on Android;
  • Firefox with Responsive Design Mode and Touch Simulation enabled, on Linux;
  • Chrome with Toogle Device Toolbar enabled, on Linux;

After some investigation, it appears that the event.position[0] assigned to GESTURES.Touch.downPositionA at rgestures.h#L286 is usually normalized. However, for some reason, on the Web (HTML5) build, when Touch or Touch Emulation are used, the value being passed to GESTURES.Touch.downPositionA is not normalized, therefore causing the GESTURES.Drag.angle calculation at rgestures.h#L310 to get a wrong result.

The swipe gestures are correctly interpreted on Chrome or Firefox on Linux without Touch Emulation.

Probably not the best solution, but a workaround would be adding the following at rgestures.h#L309:

#if defined( PLATFORM_WEB )
    if (GESTURES.Touch.downPositionA.x > 1.0f || GESTURES.Touch.downPositionA.y > 1.0f)
    {
        GESTURES.Touch.downPositionA.x = Normalize(GESTURES.Touch.downPositionA.x, 0.0f, GetScreenWidth());
        GESTURES.Touch.downPositionA.y = Normalize(GESTURES.Touch.downPositionA.y, 0.0f, GetScreenHeight());
    }
#endif

If there isn't any better solution, I can try to send a PR.

Environment

Platform: Linux (x86_64)
Operating System: Linux Mint 21.1
OpenGL version: 3.1 Mesa 22.0.5
GPU: Intel HD Graphics 3000

Platform: Android
Operating System: Android 5.1.1
OpenGL version: OpenGL ES 1.1/2.0
GPU: Mali-400

Issue Screenshot

On Firefox (114.2.0) and Chrome (95.0.4638.74) for Android:
img1

On Firefox (102.11.0esr 64-bit) for Linux:
img2

On Chrome (114.0.5735.106 64-bit) for Linux:
img3

Code Example

Minimal reproduction code to test the issue:

#include "raylib.h"

#if defined(PLATFORM_WEB)
    #include <emscripten/emscripten.h>
#endif

int lastSwipe = GESTURE_NONE;

void Update(void) {
    const int gesture = GetGestureDetected();
    if (gesture == GESTURE_SWIPE_UP || gesture == GESTURE_SWIPE_RIGHT || gesture == GESTURE_SWIPE_LEFT || gesture == GESTURE_SWIPE_DOWN) { lastSwipe = gesture; }

    BeginDrawing();
    ClearBackground(RAYWHITE);
    DrawRectangleLinesEx({0, 0, 400, 400}, 2.0f, BLACK);
    DrawText("Swipe on the screen.", 95, 195, 20, BLACK);
    DrawText("Last swipe:", 25, 20, 20, BLACK);
    DrawRectangle(70, 50, 20, 20, lastSwipe == GESTURE_SWIPE_UP    ? BLUE : LIGHTGRAY);
    DrawRectangle(50, 70, 20, 20, lastSwipe == GESTURE_SWIPE_LEFT  ? BLUE : LIGHTGRAY);
    DrawRectangle(90, 70, 20, 20, lastSwipe == GESTURE_SWIPE_RIGHT ? BLUE : LIGHTGRAY);
    DrawRectangle(70, 90, 20, 20, lastSwipe == GESTURE_SWIPE_DOWN  ? BLUE : LIGHTGRAY);
    EndDrawing();
}

int main(void) {
    InitWindow(400, 400, "Swipe Test");
    #if defined(PLATFORM_WEB)
        emscripten_set_main_loop(Update, 0, 1);
    #else
        SetTargetFPS(60);
        while (!WindowShouldClose()) { Update(); }
    #endif
    CloseWindow();
    return 0;
}
@ghost ghost changed the title [core] All swipe gestures are being interpreted as GESTURE_SWIPE_LEFT on web browsers with Touch Screen. [core] All swipe gestures are being interpreted as GESTURE_SWIPE_LEFT on web browsers with Touch Screen. Jun 29, 2023
@ghost ghost mentioned this issue Jul 3, 2023
@ghost
Copy link
Author

ghost commented Jul 3, 2023

After some more investigation, found that the gestureEvent.position[i] was indeed missing the normalization on PLATFORM_WEB at rcore.c#L6119. Adding it fixes the issue.

@SAOMDVN
Copy link
Contributor

SAOMDVN commented Jul 3, 2023

Hi @ubkp. Nice work on the PR! Do you experience incorrect Pinch behaviour on your devices too? (I mentioned it in #1963)
I hope you can take a look at this issue

@ghost
Copy link
Author

ghost commented Jul 4, 2023

@SAOMDVN Thank you :)

I took a look at the GESTURE_PINCH_IN and GESTURE_PINCH_OUT and can confirm the problem you reported at #1963.

I'll reply there to keep the issues organized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant