feat(sdl): fixes pinch/swipe on platform sdl
This commit is contained in:
parent
e7edb181dc
commit
39061d936d
|
|
@ -1399,7 +1399,9 @@ void PollInputEvents(void)
|
||||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
||||||
|
|
||||||
// Map touch position to mouse position for convenience
|
// Map touch position to mouse position for convenience
|
||||||
if (CORE.Input.Touch.pointCount == 0) CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
// I believe this was intefering with swipe events on 5.5, maybe the pointCount check fixes this
|
||||||
|
// Uncomment if it breaks mouse, but for now, we'll use the last pointCount
|
||||||
|
// if (CORE.Input.Touch.pointCount == 0) CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||||
|
|
||||||
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||||
bool realTouch = false; // Flag to differentiate real touch gestures from mouse ones
|
bool realTouch = false; // Flag to differentiate real touch gestures from mouse ones
|
||||||
|
|
@ -1709,13 +1711,24 @@ void PollInputEvents(void)
|
||||||
} break;
|
} break;
|
||||||
case SDL_FINGERUP:
|
case SDL_FINGERUP:
|
||||||
{
|
{
|
||||||
|
// fingerup returns a touchCount of 0 which is ignored by rgestures.h
|
||||||
|
// use the last pointCount from down
|
||||||
|
int count = CORE.Input.Touch.pointCount;
|
||||||
UpdateTouchPointsSDL(event.tfinger);
|
UpdateTouchPointsSDL(event.tfinger);
|
||||||
|
CORE.Input.Touch.pointCount = count;
|
||||||
|
|
||||||
touchAction = 0;
|
touchAction = 0;
|
||||||
realTouch = true;
|
realTouch = true;
|
||||||
} break;
|
} break;
|
||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
{
|
{
|
||||||
|
// fingermotion returns a touchCount of 0 on SDL3 pinephone? (not sure why)
|
||||||
|
// which is ignored by rgestures.h
|
||||||
|
// use the last pointCount from down
|
||||||
|
int count = CORE.Input.Touch.pointCount;
|
||||||
UpdateTouchPointsSDL(event.tfinger);
|
UpdateTouchPointsSDL(event.tfinger);
|
||||||
|
CORE.Input.Touch.pointCount = count;
|
||||||
|
|
||||||
touchAction = 2;
|
touchAction = 2;
|
||||||
realTouch = true;
|
realTouch = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
@ -1924,24 +1937,42 @@ void PollInputEvents(void)
|
||||||
// Register touch actions
|
// Register touch actions
|
||||||
gestureEvent.touchAction = touchAction;
|
gestureEvent.touchAction = touchAction;
|
||||||
|
|
||||||
// Assign a pointer ID
|
if (realTouch)
|
||||||
gestureEvent.pointId[0] = 0;
|
{
|
||||||
|
// Register touch points count
|
||||||
|
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
||||||
|
|
||||||
// Register touch points count
|
// we want to track every touch.
|
||||||
gestureEvent.pointCount = 1;
|
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
|
||||||
|
{
|
||||||
|
gestureEvent.pointId[i] = i;
|
||||||
|
gestureEvent.position[i].x = CORE.Input.Touch.position[i].x / (float)GetScreenWidth();
|
||||||
|
gestureEvent.position[i].y = CORE.Input.Touch.position[i].y / (float)GetScreenWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Assign a pointer ID
|
||||||
|
gestureEvent.pointId[0] = 0;
|
||||||
|
|
||||||
// Register touch points position, only one point registered
|
// Register touch points count
|
||||||
if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0];
|
gestureEvent.pointCount = 1;
|
||||||
else gestureEvent.position[0] = GetMousePosition();
|
|
||||||
|
|
||||||
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
|
// Register touch points position, only one point registered
|
||||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0];
|
||||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
else 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
|
// Gesture data is sent to gestures-system for processing
|
||||||
ProcessGestureEvent(gestureEvent);
|
ProcessGestureEvent(gestureEvent);
|
||||||
|
|
||||||
touchAction = -1;
|
touchAction = -1;
|
||||||
|
// not sure how this behaves when mixing Mouse/Touch
|
||||||
|
realTouch = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user