Added support for mousewheel on iOS
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
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index 7a37cfe..3b2287a 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -66,6 +66,13 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRight];
+#else
+ if (@available(iOS 13.4, *)) {
+ UIPanGestureRecognizer *mouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelGesture:)];
+ mouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskDiscrete;
+ mouseWheelRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirectPointer) ];
+ [self addGestureRecognizer:mouseWheelRecognizer];
+ }
#endif
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -428,6 +435,29 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
+-(void)mouseWheelGesture:(UIPanGestureRecognizer *)gesture
+{
+ if (gesture.state == UIGestureRecognizerStateBegan ||
+ gesture.state == UIGestureRecognizerStateChanged ||
+ gesture.state == UIGestureRecognizerStateEnded) {
+ CGPoint velocity = [gesture velocityInView:self];
+
+ if (velocity.x > 0.0f) {
+ velocity.x = -1.0;
+ } else if (velocity.x < 0.0f) {
+ velocity.x = 1.0f;
+ }
+ if (velocity.y > 0.0f) {
+ velocity.y = -1.0;
+ } else if (velocity.y < 0.0f) {
+ velocity.y = 1.0f;
+ }
+ if (velocity.x != 0.0f || velocity.y != 0.0f) {
+ SDL_SendMouseWheel(sdlwindow, 0, velocity.x, velocity.y, SDL_MOUSEWHEEL_NORMAL);
+ }
+ }
+}
+
#if TARGET_OS_TV
-(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
{