aboutsummaryrefslogtreecommitdiff
path: root/src/core.c
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2016-02-10 10:31:06 +0100
committerRay <raysan5@gmail.com>2016-02-10 10:31:06 +0100
commita847df921f94a7fd118fcb608b23f11d8255c236 (patch)
tree9c68194bbcf4998e606529de3633f563e6a9a8f3 /src/core.c
parent687fe2c3c79bac68e6eab3ae393fefed0a7a4b07 (diff)
downloadraylib-a847df921f94a7fd118fcb608b23f11d8255c236.tar.gz
raylib-a847df921f94a7fd118fcb608b23f11d8255c236.zip
Reviewed gestures module
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/core.c b/src/core.c
index 699cc2b7..05ec0c0a 100644
--- a/src/core.c
+++ b/src/core.c
@@ -117,7 +117,8 @@
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
-#define STORAGE_FILENAME "storage.data"
+#define STORAGE_FILENAME "storage.data"
+#define MAX_TOUCH_POINTS 2
//----------------------------------------------------------------------------------
// Types and Structures Definition
@@ -182,7 +183,7 @@ static bool fullscreen = false; // Fullscreen mode (useful only for
static Matrix downscaleView; // Matrix to downscale view (in case screen size bigger than display size)
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
-static Vector2 touchPosition; // Touch position on screen
+static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen
#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
@@ -1228,7 +1229,7 @@ bool IsGamepadButtonUp(int gamepad, int button)
int GetTouchX(void)
{
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
- return (int)touchPosition.x;
+ return (int)touchPosition[0].x;
#else // PLATFORM_DESKTOP, PLATFORM_RPI
return GetMouseX();
#endif
@@ -1238,7 +1239,7 @@ int GetTouchX(void)
int GetTouchY(void)
{
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
- return (int)touchPosition.y;
+ return (int)touchPosition[0].y;
#else // PLATFORM_DESKTOP, PLATFORM_RPI
return GetMouseY();
#endif
@@ -1246,10 +1247,13 @@ int GetTouchY(void)
// Returns touch position XY
// TODO: touch position should be scaled depending on display size and render size
-Vector2 GetTouchPosition(void)
+Vector2 GetTouchPosition(int index)
{
+ Vector2 position = { -1.0f, -1.0f };
+
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
- Vector2 position = touchPosition;
+ if (index < MAX_TOUCH_POINTS) position = touchPosition[index];
+ else TraceLog(WARNING, "Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS);
if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
{
@@ -1263,7 +1267,7 @@ Vector2 GetTouchPosition(void)
position.y = position.y*((float)renderHeight/(float)displayHeight) - renderOffsetY/2;
}
#else // PLATFORM_DESKTOP, PLATFORM_RPI
- Vector2 position = GetMousePosition();
+ if (index == 0) position = GetMousePosition();
#endif
return position;
@@ -1916,8 +1920,13 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
if (type == AINPUT_EVENT_TYPE_MOTION)
{
- touchPosition.x = AMotionEvent_getX(event, 0);
- touchPosition.y = AMotionEvent_getY(event, 0);
+ // Get first touch position
+ touchPosition[0].x = AMotionEvent_getX(event, 0);
+ touchPosition[0].y = AMotionEvent_getY(event, 0);
+
+ // Get second touch position
+ touchPosition[1].x = AMotionEvent_getX(event, 1);
+ touchPosition[1].y = AMotionEvent_getY(event, 1);
}
else if (type == AINPUT_EVENT_TYPE_KEY)
{
@@ -2535,7 +2544,8 @@ static EM_BOOL EmscriptenInputCallback(int eventType, const EmscriptenTouchEvent
gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].targetX, touchEvent->touches[0].targetY };
gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].targetX, touchEvent->touches[1].targetY };
- touchPosition = gestureEvent.position[0];
+ touchPosition[0] = gestureEvent.position[0];
+ touchPosition[1] = gestureEvent.position[1];
// Gesture data is sent to gestures system for processing
ProcessGestureEvent(gestureEvent); // Process obtained gestures data