aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-01-24 19:17:08 +0100
committerraysan5 <raysan5@gmail.com>2016-01-24 19:17:08 +0100
commit41959eeae10d7d01fbd2abc19ccae4fc65aae031 (patch)
tree2022710dc5a1624db4795c67a0bc2319de5b1c37 /src
parent08da91047e8a2c593c3bc40b31c4796ae6cbb26d (diff)
downloadraylib-41959eeae10d7d01fbd2abc19ccae4fc65aae031.tar.gz
raylib-41959eeae10d7d01fbd2abc19ccae4fc65aae031.zip
Added support for mouse gestures (need testing)
Mouse input is interpreted as touches to allow mouse gestures detection... and get an unified inputs system for all platforms!
Diffstat (limited to 'src')
-rw-r--r--src/core.c42
-rw-r--r--src/raylib.h5
2 files changed, 39 insertions, 8 deletions
diff --git a/src/core.c b/src/core.c
index 7a5de04e..811f082a 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1197,23 +1197,31 @@ bool IsGamepadButtonUp(int gamepad, int button)
}
#endif
-#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
// Returns touch position X
int GetTouchX(void)
{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
return (int)touchPosition.x;
+#else // PLATFORM_DESKTOP, PLATFORM_RPI
+ return GetMouseX();
+#endif
}
// Returns touch position Y
int GetTouchY(void)
{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
return (int)touchPosition.y;
+#else // PLATFORM_DESKTOP, PLATFORM_RPI
+ return GetMouseY();
+#endif
}
// Returns touch position XY
// TODO: touch position should be scaled depending on display size and render size
Vector2 GetTouchPosition(void)
{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
Vector2 position = touchPosition;
if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
@@ -1227,10 +1235,12 @@ Vector2 GetTouchPosition(void)
position.x = position.x*((float)renderWidth/(float)displayWidth) - renderOffsetX/2;
position.y = position.y*((float)renderHeight/(float)displayHeight) - renderOffsetY/2;
}
+#else // PLATFORM_DESKTOP, PLATFORM_RPI
+ Vector2 position = GetMousePosition();
+#endif
return position;
}
-#endif
#if defined(PLATFORM_ANDROID)
// Detect if a button has been pressed once
@@ -1633,6 +1643,28 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
{
currentMouseState[button] = action;
+
+ // TODO: Test mouse gestures
+
+#define ENABLE_MOUSE_GESTURES
+#if defined(ENABLE_MOUSE_GESTURES)
+ // Process mouse events as touches to be able to use mouse-gestures
+ GestureEvent gestureEvent;
+
+ // Register touch actions
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) gestureEvent.touchAction = TOUCH_DOWN;
+ else if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) gestureEvent.touchAction = TOUCH_MOVE;
+ else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) gestureEvent.touchAction = TOUCH_UP;
+
+ // Register touch points count
+ gestureEvent.pointCount = 1;
+
+ // Register touch points position, only one point registered
+ gestureEvent.position[0] = GetMousePosition();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+#endif
}
// GLFW3 Char Key Callback, runs on key pressed (get char value)
@@ -1976,11 +2008,9 @@ static bool GetMouseButtonStatus(int button)
// Poll (store) all input events
static void PollInputEvents(void)
{
-#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
-
- // TODO: Remove this requirement...
+ // NOTE: Gestures update must be called every frame to reset gestures correctly
+ // because ProcessGestureEvent() is just called on an event, not every frame
UpdateGestures();
-#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
// Mouse input polling
diff --git a/src/raylib.h b/src/raylib.h
index 73200556..41fa3f7d 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -598,13 +598,15 @@ bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad b
bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed
#endif
-#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
int GetTouchX(void); // Returns touch position X (relative to screen size)
int GetTouchY(void); // Returns touch position Y (relative to screen size)
Vector2 GetTouchPosition(void); // Returns touch position XY (relative to screen size)
+
+#if defined(PLATFORM_ANDROID)
bool IsButtonPressed(int button); // Detect if an android physic button has been pressed
bool IsButtonDown(int button); // Detect if an android physic button is being pressed
bool IsButtonReleased(int button); // Detect if an android physic button has been released
+#endif
//------------------------------------------------------------------------------------
// Gestures and Touch Handling Functions (Module: gestures)
@@ -621,7 +623,6 @@ Vector2 GetGestureDragVector(void); // Get gesture drag vect
int GetGestureHoldDuration(void); // Get gesture hold time in frames
float GetGesturePinchDelta(void); // Get gesture pinch delta
float GetGesturePinchAngle(void); // Get gesture pinch angle
-#endif
//------------------------------------------------------------------------------------
// Camera System Functions (Module: camera)