ADDED: IsTouchDetected()

This commit is contained in:
Ray 2020-01-24 19:45:51 +01:00
parent eee995ec3d
commit f28c1ef675
2 changed files with 22 additions and 10 deletions

View file

@ -426,6 +426,8 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto
static pthread_t gamepadThreadId; // Gamepad reading thread id static pthread_t gamepadThreadId; // Gamepad reading thread id
static char gamepadName[64]; // Gamepad name holder static char gamepadName[64]; // Gamepad name holder
#endif #endif
bool touchDetected = false;
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
// Timming system variables // Timming system variables
@ -2427,12 +2429,11 @@ bool IsMouseButtonPressed(int button)
if ((currentMouseState[button] != previousMouseState[button]) && (currentMouseState[button] == 1)) pressed = true; if ((currentMouseState[button] != previousMouseState[button]) && (currentMouseState[button] == 1)) pressed = true;
#endif #endif
/*
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
Vector2 pos = GetTouchPosition(0); if (IsTouchDetected()) pressed = true; // There was a touch!
if ((pos.x > 0) && (pos.y > 0)) pressed = true; // There was a touch!
#endif #endif
*/
return pressed; return pressed;
} }
@ -2504,14 +2505,11 @@ Vector2 GetMousePosition(void)
#else #else
position = (Vector2){ (mousePosition.x + mouseOffset.x)*mouseScale.x, (mousePosition.y + mouseOffset.y)*mouseScale.y }; position = (Vector2){ (mousePosition.x + mouseOffset.x)*mouseScale.x, (mousePosition.y + mouseOffset.y)*mouseScale.y };
#endif #endif
/*
#if defined(PLATFORM_WEB)
Vector2 pos = GetTouchPosition(0);
// Touch position has priority over mouse position #if defined(PLATFORM_WEB)
if ((pos.x > 0) && (pos.y > 0)) position = pos; // There was a touch! if (IsTouchDetected()) position = GetTouchPosition(0);
#endif #endif
*/
return position; return position;
} }
@ -2558,6 +2556,16 @@ int GetMouseWheelMove(void)
#endif #endif
} }
// Detect if a touch has happened
bool IsTouchDetected(void)
{
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
return touchDetected;
#else // PLATFORM_DESKTOP, PLATFORM_RPI
return false;
#endif
}
// Returns touch position X for touch point 0 (relative to screen size) // Returns touch position X for touch point 0 (relative to screen size)
int GetTouchX(void) int GetTouchX(void)
{ {
@ -3718,6 +3726,8 @@ static void PollInputEvents(void)
previousMouseWheelY = currentMouseWheelY; previousMouseWheelY = currentMouseWheelY;
currentMouseWheelY = 0; currentMouseWheelY = 0;
touchDetected = false;
#endif #endif
#if defined(PLATFORM_DESKTOP) #if defined(PLATFORM_DESKTOP)
@ -4362,6 +4372,7 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
// Register touch input events // Register touch input events
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData) static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
{ {
touchDetected = true;
/* /*
for (int i = 0; i < touchEvent->numTouches; i++) for (int i = 0; i < touchEvent->numTouches; i++)
{ {

View file

@ -1013,6 +1013,7 @@ RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scali
RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y
// Input-related functions: touch // Input-related functions: touch
RLAPI bool IsTouchDetected(void); // Detect if a touch has happened
RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size)
RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size)
RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size)