Browse Source

Improved gestures system

pull/109/head
raysan5 8 years ago
parent
commit
17eefed08f
5 changed files with 12 additions and 14 deletions
  1. +3
    -5
      examples/core_gestures_detection.c
  2. +2
    -2
      src/core.c
  3. +3
    -3
      src/gestures.c
  4. +2
    -2
      src/gestures.h
  5. +2
    -2
      src/raylib.h

+ 3
- 5
examples/core_gestures_detection.c View File

@ -43,12 +43,11 @@ int main()
// Update
//----------------------------------------------------------------------------------
lastGesture = currentGesture;
currentGesture = GetGestureDetected();
touchPosition = GetTouchPosition(0);
if (CheckCollisionPointRec(touchPosition, touchArea) && IsGestureDetected())
if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != GESTURE_NONE))
{
currentGesture = GetGestureType();
if (currentGesture != lastGesture)
{
// Store gesture string
@ -78,7 +77,6 @@ int main()
}
}
}
else currentGesture = GESTURE_NONE;
//----------------------------------------------------------------------------------
// Draw

+ 2
- 2
src/core.c View File

@ -1193,7 +1193,7 @@ bool IsMouseButtonPressed(int button)
bool pressed = false;
#if defined(PLATFORM_ANDROID)
if (IsGestureDetected(p">) && (GetGestureType() == GESTURE_TAP)) pressed = true;
if (IsGestureDetected(GESTURE_TAP)) pressed = true;
#else
if ((currentMouseState[button] != previousMouseState[button]) && (currentMouseState[button] == 1)) pressed = true;
#endif
@ -1207,7 +1207,7 @@ bool IsMouseButtonDown(int button)
bool down = false;
#if defined(PLATFORM_ANDROID)
if (IsGestureDetected(p">) && (GetGestureType() == GESTURE_HOLD)) down = true;
if (IsGestureDetected(GESTURE_HOLD)) down = true;
#else
if (GetMouseButtonStatus(button) == 1) down = true;
#endif

+ 3
- 3
src/gestures.c View File

@ -292,14 +292,14 @@ void UpdateGestures(void)
}
// Check if a gesture have been detected
bool IsGestureDetected(void)
bool IsGestureDetected(int gesture)
{
if ((enabledGestures & currentGesture) != GESTURE_NONE) return true;
if ((enabledGestures & currentGesture) == gesture) return true;
else return false;
}
// Check gesture type
int GetGestureType(void)
int GetGestureDetected(void)
{
// Get current gesture only if enabled
return (enabledGestures & currentGesture);

+ 2
- 2
src/gestures.h View File

@ -92,8 +92,8 @@ extern "C" { // Prevents name mangling of functions
//----------------------------------------------------------------------------------
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
void UpdateGestures(void); // Update gestures detected (must be called every frame)
bool IsGestureDetected(void); // Check if a gesture have been detected
int GetGestureType(void); // Get latest detected gesture
bool IsGestureDetected(int gesture); // Check if a gesture have been detected
int GetGestureDetected(void); // Get latest detected gesture
void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags
int GetTouchPointsCount(void); // Get touch points count

+ 2
- 2
src/raylib.h View File

@ -647,8 +647,8 @@ bool IsButtonReleased(int button); // Detect if an android
//------------------------------------------------------------------------------------
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents())
bool IsGestureDetected(void); // Check if a gesture have been detected
int GetGestureType(void); // Get latest detected gesture
bool IsGestureDetected(int gesture); // Check if a gesture have been detected
int GetGestureDetected(void); // Get latest detected gesture
void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags
int GetTouchPointsCount(void); // Get touch points count

Loading…
Cancel
Save