mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Added support for mousewheel on iOS
This commit is contained in:
parent
2b7ce8c51d
commit
14661d3f30
@ -66,6 +66,13 @@ 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];
|
||||||
|
#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
|
#endif
|
||||||
|
|
||||||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
@ -428,6 +435,29 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||||||
|
|
||||||
#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
|
#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
|
#if TARGET_OS_TV
|
||||||
-(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
|
-(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user