Replaced mouseWheelGesture with GCMouse support on iOS (thanks @russelltg!)

Fixes https://github.com/libsdl-org/SDL/issues/6411
main
Sam Lantinga 2022-10-22 09:37:34 -07:00
parent 2ebaafa6c9
commit 413500ab69
2 changed files with 5 additions and 44 deletions

View File

@ -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_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 ) ); dispatch_set_target_queue( queue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
mouse.handlerQueue = queue; mouse.handlerQueue = queue;

View File

@ -69,16 +69,6 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight; swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRight]; [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 #endif
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@ -455,40 +445,6 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */ #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 #if TARGET_OS_TV
-(void)swipeGesture:(UISwipeGestureRecognizer *)gesture -(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
{ {