Skip to content

Commit f28c1ef

Browse files
committed
ADDED: IsTouchDetected()
1 parent eee995e commit f28c1ef

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/core.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto
426426
static pthread_t gamepadThreadId; // Gamepad reading thread id
427427
static 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)
25622570
int 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
43634373
static 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
{

src/raylib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scali
10131013
RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y
10141014

10151015
// Input-related functions: touch
1016+
RLAPI bool IsTouchDetected(void); // Detect if a touch has happened
10161017
RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size)
10171018
RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size)
10181019
RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size)

0 commit comments

Comments
 (0)