From a1d7b3427ab4110cc8d0228a18c213182959213a Mon Sep 17 00:00:00 2001 From: ImazighenGhost Date: Sun, 15 Jan 2023 10:14:08 +0100 Subject: [PATCH] Updated Touch events, now one can check for pressed and released Touches same as you check for Mouse Buttons... --- src/raylib.h | 4 ++++ src/rcore.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 1c3f77669..84e0798f7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1136,6 +1136,10 @@ RLAPI int GetTouchY(void); // Get touch posit RLAPI Vector2 GetTouchPosition(int index); // Get touch position XY for a touch point index (relative to screen size) RLAPI int GetTouchPointId(int index); // Get touch point identifier for given index RLAPI int GetTouchPointCount(void); // Get number of touch points +bool IsTouchPointPressed(int index); // Check if a Touch point is pressed once (if the finger touch got in contact with the the screen once, a.k.a TAP, also found in gestures) +bool IsTouchPointReleased(int index); // Check if a Touch point has been released once (if the finger touch was in contact with the screen and now is not anymore) +bool IsTouchPointDown(int index); // Check if a Touch Point is being pressed (if the finger touch is in contact with the screen) +bool IsTouchPointUp(int index); // Check if a Touch Point was released (if the finger touch no longer in contact with the screen) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: rgestures) diff --git a/src/rcore.c b/src/rcore.c index 27b1a1f33..785c77dbf 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -3907,6 +3907,40 @@ int GetTouchPointCount(void) return CORE.Input.Touch.pointCount; } +// Check if a Touch point is pressed once (if the finger touch got in contact with the the screen once, a.k.a TAP, also found in gestures) +bool IsTouchPointPressed(int index) +{ + // Compare the previous and current Touch point state + if ((CORE.Input.Touch.currentTouchState[index] == 1) && (CORE.Input.Touch.previousTouchState[index] == 0)) return true; + + return false; +} + +// Check if a Touch point has been released once (if the finger touch was in contact with the screen and now is not anymore) +bool IsTouchPointReleased(int index) +{ + // Compare the previous and current Touch point state + if ((CORE.Input.Touch.currentTouchState[index] == 0) && (CORE.Input.Touch.previousTouchState[index] == 1)) return true; + + return false; +} + +// Check if a Touch Point is being pressed (if the finger touch is in contact with the screen) +bool IsTouchPointDown(int index) +{ + // Get the state of the Touch point + if (CORE.Input.Touch.currentTouchState[index] == 1) return true; + + return false; +} + +// Check if a Touch Point was released (if the finger touch no longer in contact with the screen) +bool IsTouchPointUp(int index) +{ + // Reverse the state of the IsTouchPointDown() function + return !IsTouchPointDown(index); +} + //---------------------------------------------------------------------------------- // Module specific Functions Definition //----------------------------------------------------------------------------------