From 74da3b7a769afdc6bc4681c4f7bbb336e708f096 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 24 Mar 2024 02:37:22 +0800 Subject: [PATCH] Update rcore_ios.c --- src/platforms/rcore_ios.c | 55 +++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/platforms/rcore_ios.c b/src/platforms/rcore_ios.c index d917b9e67..4f2201adf 100644 --- a/src/platforms/rcore_ios.c +++ b/src/platforms/rcore_ios.c @@ -64,7 +64,7 @@ extern void ios_destroy(); - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; -- (void)touchesEstimatedPropertiesUpdated:(NSSet *)touches; +//- (void)touchesEstimatedPropertiesUpdated:(NSSet *)touches; @end /* AppDelegate */ @@ -444,8 +444,6 @@ void PollInputEvents(void) } // TODO: Poll input events for iOS - - // Register touch points count // https://developer.apple.com/documentation/uikit/touches_presses_and_gestures } @@ -653,14 +651,61 @@ void ClosePlatform(void) self.view.multipleTouchEnabled = true; } +- (bool)prefersStatusBarHidden +{ + return true; +} + - (void)update { ios_update(); } -- (bool)prefersStatusBarHidden +void call_gesture(int action) { - return true; +#if defined(SUPPORT_GESTURES_SYSTEM) + GestureEvent gestureEvent = { 0 }; + + gestureEvent.pointCount = CORE.Input.Touch.pointCount; + + // Register touch actions + gestureEvent.touchAction = action; + + for (int i = 0; (i < gestureEvent.pointCount) && (i < MAX_TOUCH_POINTS); i++) + { + gestureEvent.pointId[i] = CORE.Input.Touch.pointId[i]; + gestureEvent.position[i] = CORE.Input.Touch.position[i]; + gestureEvent.position[i].x /= (float)GetScreenWidth(); + gestureEvent.position[i].y /= (float)GetScreenHeight(); + } + + // Gesture data is sent to gestures system for processing + ProcessGestureEvent(gestureEvent); +#endif +} + +// touch callbacks +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + CORE.Input.Touch.pointCount += touches.count; + if (CORE.Input.Touch.pointCount > 0) CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 1; + for(UITouch* touch in touches) call_gesture(TOUCH_ACTION_DOWN); +} +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + CORE.Input.Touch.pointCount -= touches.count; + if (CORE.Input.Touch.pointCount == 0) CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 0; + for(UITouch* touch in touches) call_gesture(TOUCH_ACTION_UP); +} +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + for(UITouch* touch in touches) call_gesture(TOUCH_ACTION_MOVE); +} +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event +{ + CORE.Input.Touch.pointCount = 0; + CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 0; + for(UITouch* touch in touches) call_gesture(TOUCH_ACTION_CANCEL); } @end