Skip to content

Commit

Permalink
Added support for mousewheel on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Apr 15, 2020
1 parent 2b7ce8c commit 14661d3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -66,6 +66,13 @@ - (instancetype)initWithFrame:(CGRect)frame
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;
Expand Down Expand Up @@ -428,6 +435,29 @@ - (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)e

#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
{
Expand Down

0 comments on commit 14661d3

Please sign in to comment.