Review the gesture handling for SDL
This commit is contained in:
parent
668e298c66
commit
dfdd4b9e0e
|
|
@ -970,6 +970,9 @@ void PollInputEvents(void)
|
|||
// https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages
|
||||
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||
|
||||
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||
bool gestureUpdate = false; // Flag to note gestures require to update
|
||||
|
||||
// Register previous keys states
|
||||
// NOTE: Android supports up to 260 keys
|
||||
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
|
||||
|
|
@ -1084,59 +1087,15 @@ void PollInputEvents(void)
|
|||
{
|
||||
CORE.Input.Mouse.currentButtonState[event.button.button - 1] = 1;
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
// Register touch actions
|
||||
if ((CORE.Input.Mouse.currentButtonState[event.button.button - 1] == 1) && (CORE.Input.Mouse.previousButtonState[event.button.button - 1] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if ((CORE.Input.Mouse.currentButtonState[event.button.button - 1] == 0) && (CORE.Input.Mouse.previousButtonState[event.button.button - 1] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
|
||||
// Register touch points count
|
||||
gestureEvent.pointCount = 1;
|
||||
|
||||
// Register touch points position, only one point registered
|
||||
gestureEvent.position[0] = GetMousePosition();
|
||||
|
||||
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
|
||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||
|
||||
// Gesture data is sent to gestures-system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
#endif
|
||||
touchAction = 1;
|
||||
gestureUpdate = true;
|
||||
} break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
CORE.Input.Mouse.currentButtonState[event.button.button - 1] = 0;
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
// Register touch actions
|
||||
if ((CORE.Input.Mouse.currentButtonState[event.button.button - 1] == 1) && (CORE.Input.Mouse.previousButtonState[event.button.button - 1] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if ((CORE.Input.Mouse.currentButtonState[event.button.button - 1] == 0) && (CORE.Input.Mouse.previousButtonState[event.button.button - 1] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
|
||||
// Register touch points count
|
||||
gestureEvent.pointCount = 1;
|
||||
|
||||
// Register touch points position, only one point registered
|
||||
gestureEvent.position[0] = GetMousePosition();
|
||||
|
||||
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
|
||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||
|
||||
// Gesture data is sent to gestures-system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
#endif
|
||||
touchAction = 0;
|
||||
gestureUpdate = true;
|
||||
} break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
|
|
@ -1157,30 +1116,9 @@ void PollInputEvents(void)
|
|||
CORE.Input.Mouse.currentPosition.y = (float)event.motion.y;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
|
||||
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
gestureEvent.touchAction = TOUCH_ACTION_MOVE;
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
|
||||
// Register touch points count
|
||||
gestureEvent.pointCount = 1;
|
||||
|
||||
// Register touch points position, only one point registered
|
||||
gestureEvent.position[0] = CORE.Input.Touch.position[0];
|
||||
|
||||
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
|
||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||
|
||||
// Gesture data is sent to gestures-system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
#endif
|
||||
touchAction = 2;
|
||||
gestureUpdate = true;
|
||||
} break;
|
||||
|
||||
// Check gamepad events
|
||||
|
|
@ -1203,6 +1141,33 @@ void PollInputEvents(void)
|
|||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
if (gestureUpdate)
|
||||
{
|
||||
// Process mouse events as touches to be able to use mouse-gestures
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
// Register touch actions
|
||||
gestureEvent.touchAction = touchAction;
|
||||
|
||||
// Assign a pointer ID
|
||||
gestureEvent.pointId[0] = 0;
|
||||
|
||||
// Register touch points count
|
||||
gestureEvent.pointCount = 1;
|
||||
|
||||
// Register touch points position, only one point registered
|
||||
gestureEvent.position[0] = GetMousePosition();
|
||||
|
||||
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
|
||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||
|
||||
// Gesture data is sent to gestures-system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user