Replaced mouseWheelGesture with GCMouse support on iOS (thanks @russelltg!) Fixes https://github.com/libsdl-org/SDL/issues/6411
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index 61c57b2..e1bc5a2 100644
--- a/src/video/uikit/SDL_uikitevents.m
+++ b/src/video/uikit/SDL_uikitevents.m
@@ -315,6 +315,11 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
}
};
+ mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue)
+ {
+ SDL_SendMouseWheel(SDL_GetMouseFocus(), 0, xValue, yValue, SDL_MOUSEWHEEL_NORMAL);
+ };
+
dispatch_queue_t queue = dispatch_queue_create( "org.libsdl.input.mouse", DISPATCH_QUEUE_SERIAL );
dispatch_set_target_queue( queue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
mouse.handlerQueue = queue;
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index fea10ff..8c48cfa 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -69,16 +69,6 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRight];
-#elif defined(__IPHONE_13_4)
- if (@available(iOS 13.4, *)) {
- UIPanGestureRecognizer *mouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelGesture:)];
- mouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskDiscrete;
- mouseWheelRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirectPointer) ];
- mouseWheelRecognizer.cancelsTouchesInView = NO;
- mouseWheelRecognizer.delaysTouchesBegan = NO;
- mouseWheelRecognizer.delaysTouchesEnded = NO;
- [self addGestureRecognizer:mouseWheelRecognizer];
- }
#endif
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -455,40 +445,6 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
-static CGPoint translation_old = (CGPoint){ 0.0, 0.0 };
-
--(void)mouseWheelGesture:(UIPanGestureRecognizer *)gesture
-{
- if (gesture.state == UIGestureRecognizerStateBegan ||
- gesture.state == UIGestureRecognizerStateChanged) {
-
- CGPoint translation = [gesture translationInView:self];
- CGPoint mouse_wheel = translation;
-
- if (gesture.state == UIGestureRecognizerStateChanged) {
- mouse_wheel.x -= translation_old.x;
- mouse_wheel.y -= translation_old.y;
- }
-
- translation_old = translation;
-
- if (mouse_wheel.x > 0.0f) {
- mouse_wheel.x = 1.0;
- } else if (mouse_wheel.x < 0.0f) {
- mouse_wheel.x = -1.0f;
- }
- if (mouse_wheel.y > 0.0f) {
- mouse_wheel.y = 1.0;
- } else if (mouse_wheel.y < 0.0f) {
- mouse_wheel.y = -1.0f;
- }
-
- if (mouse_wheel.x != 0.0f || mouse_wheel.y != 0.0f) {
- SDL_SendMouseWheel(sdlwindow, 0, mouse_wheel.x, mouse_wheel.y, SDL_MOUSEWHEEL_NORMAL);
- }
- }
-}
-
#if TARGET_OS_TV
-(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
{