@@ -426,6 +426,8 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto
426426static pthread_t gamepadThreadId ; // Gamepad reading thread id
427427static char gamepadName [64 ]; // Gamepad name holder
428428#endif
429+
430+ bool touchDetected = false;
429431//-----------------------------------------------------------------------------------
430432
431433// Timming system variables
@@ -2427,12 +2429,11 @@ bool IsMouseButtonPressed(int button)
24272429 if ((currentMouseState [button ] != previousMouseState [button ]) && (currentMouseState [button ] == 1 )) pressed = true;
24282430#endif
24292431
2430- /*
2432+
24312433#if defined(PLATFORM_WEB )
2432- Vector2 pos = GetTouchPosition(0);
2433- if ((pos.x > 0) && (pos.y > 0)) pressed = true; // There was a touch!
2434+ if (IsTouchDetected ()) pressed = true; // There was a touch!
24342435#endif
2435- */
2436+
24362437 return pressed ;
24372438}
24382439
@@ -2504,14 +2505,11 @@ Vector2 GetMousePosition(void)
25042505#else
25052506 position = (Vector2 ){ (mousePosition .x + mouseOffset .x )* mouseScale .x , (mousePosition .y + mouseOffset .y )* mouseScale .y };
25062507#endif
2507- /*
2508- #if defined(PLATFORM_WEB)
2509- Vector2 pos = GetTouchPosition(0);
25102508
2511- // Touch position has priority over mouse position
2512- if ((pos.x > 0) && (pos.y > 0)) position = pos; // There was a touch!
2509+ #if defined( PLATFORM_WEB )
2510+ if (IsTouchDetected ()) position = GetTouchPosition ( 0 );
25132511#endif
2514- */
2512+
25152513 return position ;
25162514}
25172515
@@ -2558,6 +2556,16 @@ int GetMouseWheelMove(void)
25582556#endif
25592557}
25602558
2559+ // Detect if a touch has happened
2560+ bool IsTouchDetected (void )
2561+ {
2562+ #if defined(PLATFORM_ANDROID ) || defined(PLATFORM_WEB )
2563+ return touchDetected ;
2564+ #else // PLATFORM_DESKTOP, PLATFORM_RPI
2565+ return false;
2566+ #endif
2567+ }
2568+
25612569// Returns touch position X for touch point 0 (relative to screen size)
25622570int GetTouchX (void )
25632571{
@@ -3718,6 +3726,8 @@ static void PollInputEvents(void)
37183726
37193727 previousMouseWheelY = currentMouseWheelY ;
37203728 currentMouseWheelY = 0 ;
3729+
3730+ touchDetected = false;
37213731#endif
37223732
37233733#if defined(PLATFORM_DESKTOP )
@@ -4362,6 +4372,7 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
43624372// Register touch input events
43634373static EM_BOOL EmscriptenTouchCallback (int eventType , const EmscriptenTouchEvent * touchEvent , void * userData )
43644374{
4375+ touchDetected = true;
43654376 /*
43664377 for (int i = 0; i < touchEvent->numTouches; i++)
43674378 {
0 commit comments