From fc56f8d9efa544c468df8df44d02a695d6a2e752 Mon Sep 17 00:00:00 2001
From: Ray <raysan5@gmail.com>
Date: Thu, 2 May 2019 09:46:01 +0200
Subject: [PATCH] Work on touch_as_mouse input -WIP-

---
 src/core.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/core.c b/src/core.c
index 22c59a918..18fbb181a 100644
--- a/src/core.c
+++ b/src/core.c
@@ -47,6 +47,9 @@
 *   #define SUPPORT_MOUSE_GESTURES
 *       Mouse gestures are directly mapped like touches and processed by gestures system.
 *
+*   #define SUPPORT_TOUCH_AS_MOUSE
+*       Touch input and mouse input are shared. Mouse functions also return touch information.
+*
 *   #define SUPPORT_BUSY_WAIT_LOOP
 *       Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
 *
@@ -2154,6 +2157,11 @@ bool IsMouseButtonPressed(int button)
     if ((currentMouseState[button] != previousMouseState[button]) && (currentMouseState[button] == 1)) pressed = true;
 #endif
 
+#if defined(PLATFORM_WEB)
+    Vector2 pos = GetTouchPosition(0);
+    if ((pos.x > 0) && (pos.y > 0)) pressed = true;    // There was a touch!
+#endif
+
     return pressed;
 }
 
@@ -2218,11 +2226,21 @@ int GetMouseY(void)
 // Returns mouse position XY
 Vector2 GetMousePosition(void)
 {
+    Vector2 position = { 0.0f, 0.0f };
+
 #if defined(PLATFORM_ANDROID)
-    return GetTouchPosition(0);
+    position = GetTouchPosition(0);
 #else
-    return (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
+#if defined(PLATFORM_WEB)
+    Vector2 pos = GetTouchPosition(0);
+    
+    // Touch position has priority over mouse position
+    if ((pos.x > 0) && (pos.y > 0)) position = pos; // There was a touch!
+#endif
+
+    return position;
 }
 
 // Set mouse position XY