mirror of https://github.com/encounter/SDL.git
Added support for new mouse APIs in iOS 13.4
This commit is contained in:
parent
e96b05c395
commit
e5d3629931
|
@ -24,5 +24,7 @@
|
|||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -25,12 +25,20 @@
|
|||
|
||||
#include "SDL_touch.h"
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
@interface SDL_uikitview : UIView <UIPointerInteractionDelegate>
|
||||
#else
|
||||
@interface SDL_uikitview : UIView
|
||||
#endif
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame;
|
||||
|
||||
- (void)setSDLWindow:(SDL_Window *)window;
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4));
|
||||
#endif
|
||||
|
||||
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
|
|
|
@ -75,6 +75,12 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
self.multipleTouchEnabled = YES;
|
||||
SDL_AddTouch(directTouchId, SDL_TOUCH_DEVICE_DIRECT, "");
|
||||
#endif
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
if (@available(iOS 13.4, *)) {
|
||||
[self addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -136,6 +142,21 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
sdlwindow = window;
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)){
|
||||
if (request != nil) {
|
||||
CGPoint origin = self.bounds.origin;
|
||||
CGPoint point = request.location;
|
||||
|
||||
point.x -= origin.x;
|
||||
point.y -= origin.y;
|
||||
|
||||
SDL_SendMouseMotion(sdlwindow, 0, 0, (int)point.x, (int)point.y);
|
||||
}
|
||||
return defaultRegion;
|
||||
}
|
||||
#endif /* __IPHONE_13_4 */
|
||||
|
||||
- (SDL_TouchDeviceType)touchTypeForTouch:(UITouch *)touch
|
||||
{
|
||||
#ifdef __IPHONE_9_0
|
||||
|
@ -187,6 +208,18 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
BOOL handled = NO;
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
if (@available(iOS 13.4, *)) {
|
||||
if (touch.type == UITouchTypeIndirectPointer) {
|
||||
/* FIXME: How can we tell the difference between left and right button clicks? */
|
||||
SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
handled = YES;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!handled) {
|
||||
SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
|
||||
SDL_TouchID touchId = [self touchIdForType:touchType];
|
||||
float pressure = [self pressureForTouch:touch];
|
||||
|
@ -202,10 +235,23 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
SDL_TRUE, locationInView.x, locationInView.y, pressure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
BOOL handled = NO;
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
if (@available(iOS 13.4, *)) {
|
||||
if (touch.type == UITouchTypeIndirectPointer) {
|
||||
/* FIXME: How can we tell the difference between left and right button clicks? */
|
||||
SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
handled = YES;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!handled) {
|
||||
SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
|
||||
SDL_TouchID touchId = [self touchIdForType:touchType];
|
||||
float pressure = [self pressureForTouch:touch];
|
||||
|
@ -221,6 +267,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
SDL_FALSE, locationInView.x, locationInView.y, pressure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
|
@ -230,6 +277,17 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
BOOL handled = NO;
|
||||
|
||||
#ifdef __IPHONE_13_4
|
||||
if (@available(iOS 13.4, *)) {
|
||||
if (touch.type == UITouchTypeIndirectPointer) {
|
||||
/* Already handled in pointerInteraction callback */
|
||||
handled = YES;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!handled) {
|
||||
SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
|
||||
SDL_TouchID touchId = [self touchIdForType:touchType];
|
||||
float pressure = [self pressureForTouch:touch];
|
||||
|
@ -243,13 +301,16 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
locationInView.x, locationInView.y, pressure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_TV || defined(__IPHONE_9_1)
|
||||
- (SDL_Scancode)scancodeFromPress:(UIPress*)press
|
||||
{
|
||||
#ifdef __IPHONE_13_4
|
||||
if (press.key != nil) {
|
||||
return (SDL_Scancode)press.key.keyCode;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Presses from Apple TV remote */
|
||||
if (!SDL_AppleTVRemoteOpenedAsJoystick) {
|
||||
|
|
Loading…
Reference in New Issue