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!
This commit is contained in:
parent
08da91047e
commit
41959eeae1
42
src/core.c
42
src/core.c
@ -1197,23 +1197,31 @@ bool IsGamepadButtonUp(int gamepad, int button)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
|
||||||
// Returns touch position X
|
// Returns touch position X
|
||||||
int GetTouchX(void)
|
int GetTouchX(void)
|
||||||
{
|
{
|
||||||
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
||||||
return (int)touchPosition.x;
|
return (int)touchPosition.x;
|
||||||
|
#else // PLATFORM_DESKTOP, PLATFORM_RPI
|
||||||
|
return GetMouseX();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns touch position Y
|
// Returns touch position Y
|
||||||
int GetTouchY(void)
|
int GetTouchY(void)
|
||||||
{
|
{
|
||||||
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
||||||
return (int)touchPosition.y;
|
return (int)touchPosition.y;
|
||||||
|
#else // PLATFORM_DESKTOP, PLATFORM_RPI
|
||||||
|
return GetMouseY();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns touch position XY
|
// Returns touch position XY
|
||||||
// TODO: touch position should be scaled depending on display size and render size
|
// TODO: touch position should be scaled depending on display size and render size
|
||||||
Vector2 GetTouchPosition(void)
|
Vector2 GetTouchPosition(void)
|
||||||
{
|
{
|
||||||
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
||||||
Vector2 position = touchPosition;
|
Vector2 position = touchPosition;
|
||||||
|
|
||||||
if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
|
if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
|
||||||
@ -1227,10 +1235,12 @@ Vector2 GetTouchPosition(void)
|
|||||||
position.x = position.x*((float)renderWidth/(float)displayWidth) - renderOffsetX/2;
|
position.x = position.x*((float)renderWidth/(float)displayWidth) - renderOffsetX/2;
|
||||||
position.y = position.y*((float)renderHeight/(float)displayHeight) - renderOffsetY/2;
|
position.y = position.y*((float)renderHeight/(float)displayHeight) - renderOffsetY/2;
|
||||||
}
|
}
|
||||||
|
#else // PLATFORM_DESKTOP, PLATFORM_RPI
|
||||||
|
Vector2 position = GetMousePosition();
|
||||||
|
#endif
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
// Detect if a button has been pressed once
|
// 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)
|
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
currentMouseState[button] = action;
|
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)
|
// 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
|
// Poll (store) all input events
|
||||||
static void PollInputEvents(void)
|
static void PollInputEvents(void)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
// NOTE: Gestures update must be called every frame to reset gestures correctly
|
||||||
|
// because ProcessGestureEvent() is just called on an event, not every frame
|
||||||
// TODO: Remove this requirement...
|
|
||||||
UpdateGestures();
|
UpdateGestures();
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
// Mouse input polling
|
// Mouse input polling
|
||||||
|
@ -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
|
bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
|
||||||
int GetTouchX(void); // Returns touch position X (relative to screen size)
|
int GetTouchX(void); // Returns touch position X (relative to screen size)
|
||||||
int GetTouchY(void); // Returns touch position Y (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)
|
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 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 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
|
bool IsButtonReleased(int button); // Detect if an android physic button has been released
|
||||||
|
#endif
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Gestures and Touch Handling Functions (Module: gestures)
|
// 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
|
int GetGestureHoldDuration(void); // Get gesture hold time in frames
|
||||||
float GetGesturePinchDelta(void); // Get gesture pinch delta
|
float GetGesturePinchDelta(void); // Get gesture pinch delta
|
||||||
float GetGesturePinchAngle(void); // Get gesture pinch angle
|
float GetGesturePinchAngle(void); // Get gesture pinch angle
|
||||||
#endif
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Camera System Functions (Module: camera)
|
// Camera System Functions (Module: camera)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user