21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_UIKIT
28 #include "../../events/SDL_mouse_c.h"
29 #include "../../events/SDL_touch_c.h"
30 #include "../../events/SDL_events_c.h"
38 #define MAX_MOUSE_BUTTONS 5
41 #if !SDL_JOYSTICK_DISABLED
52 - (instancetype)initWithFrame:(CGRect)frame
54 if ((
self = [super initWithFrame:
frame])) {
57 UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
58 swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
59 [
self addGestureRecognizer:swipeUp];
61 UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
62 swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
63 [
self addGestureRecognizer:swipeDown];
65 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
66 swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
67 [
self addGestureRecognizer:swipeLeft];
69 UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
70 swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
71 [
self addGestureRecognizer:swipeRight];
72 #elif defined(__IPHONE_13_4)
73 if (@available(iOS 13.4, *)) {
74 UIPanGestureRecognizer *mouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelGesture:)];
75 mouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskDiscrete;
76 mouseWheelRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirectPointer) ];
77 mouseWheelRecognizer.cancelsTouchesInView = NO;
78 mouseWheelRecognizer.delaysTouchesBegan = NO;
79 mouseWheelRecognizer.delaysTouchesEnded = NO;
80 [
self addGestureRecognizer:mouseWheelRecognizer];
84 self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
85 self.autoresizesSubviews = YES;
91 self.multipleTouchEnabled = YES;
95 #if !TARGET_OS_TV && defined(__IPHONE_13_4)
96 if (@available(iOS 13.4, *)) {
97 [
self addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]];
109 if (
window == sdlwindow) {
118 [
data.views removeObject:
self];
120 [
self removeFromSuperview];
123 view =
data.views.lastObject;
125 data.viewcontroller.view = view;
127 data.uiwindow.rootViewController = nil;
128 data.uiwindow.rootViewController =
data.viewcontroller;
130 [
data.uiwindow layoutIfNeeded];
138 [
data.views addObject:
self];
141 [
data.viewcontroller.view removeFromSuperview];
142 data.viewcontroller.view =
self;
149 data.uiwindow.rootViewController = nil;
150 data.uiwindow.rootViewController =
data.viewcontroller;
155 [
data.uiwindow layoutIfNeeded];
161 #if !TARGET_OS_TV && defined(__IPHONE_13_4)
162 - (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)){
164 CGPoint origin =
self.bounds.origin;
165 CGPoint point = request.location;
172 return [UIPointerRegion regionWithRect:self.bounds identifier:nil];
175 - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)){
179 return [UIPointerStyle hiddenPointerStyle];
187 if ([touch respondsToSelector:
@selector((
type))]) {
188 if (touch.type == UITouchTypeIndirect) {
202 return directTouchId;
204 return indirectTouchId;
208 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
210 CGPoint point = [touch locationInView:self];
213 CGRect bounds =
self.bounds;
214 point.x /= bounds.size.width;
215 point.y /= bounds.size.height;
221 - (float)pressureForTouch:(UITouch *)touch
224 if ([touch respondsToSelector:
@selector(force)]) {
225 return (
float) touch.force;
232 - (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
234 for (UITouch *touch
in touches) {
237 #if !TARGET_OS_TV && defined(__IPHONE_13_4)
238 if (@available(iOS 13.4, *)) {
239 if (touch.type == UITouchTypeIndirectPointer) {
243 for (
i = 1;
i <= MAX_MOUSE_BUTTONS; ++
i) {
271 SDL_TouchID touchId = [
self touchIdForType:touchType];
272 float pressure = [
self pressureForTouch:touch];
280 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
282 SDL_TRUE, locationInView.x, locationInView.y, pressure);
287 - (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
289 for (UITouch *touch
in touches) {
292 #if !TARGET_OS_TV && defined(__IPHONE_13_4)
293 if (@available(iOS 13.4, *)) {
294 if (touch.type == UITouchTypeIndirectPointer) {
298 for (
i = 1;
i <= MAX_MOUSE_BUTTONS; ++
i) {
326 SDL_TouchID touchId = [
self touchIdForType:touchType];
327 float pressure = [
self pressureForTouch:touch];
335 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
337 SDL_FALSE, locationInView.x, locationInView.y, pressure);
342 - (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
344 [
self touchesEnded:touches withEvent:event];
347 - (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
349 for (UITouch *touch
in touches) {
352 #if !TARGET_OS_TV && defined(__IPHONE_13_4)
353 if (@available(iOS 13.4, *)) {
354 if (touch.type == UITouchTypeIndirectPointer) {
362 SDL_TouchID touchId = [
self touchIdForType:touchType];
363 float pressure = [
self pressureForTouch:touch];
369 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
371 locationInView.x, locationInView.y, pressure);
376 #if TARGET_OS_TV || defined(__IPHONE_9_1)
380 if ([press respondsToSelector:
@selector((
key))]) {
381 if (press.key != nil) {
387 #if !SDL_JOYSTICK_DISABLED
390 switch (press.type) {
391 case UIPressTypeUpArrow:
393 case UIPressTypeDownArrow:
395 case UIPressTypeLeftArrow:
397 case UIPressTypeRightArrow:
399 case UIPressTypeSelect:
402 case UIPressTypeMenu:
405 case UIPressTypePlayPause:
417 - (
void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
420 for (UIPress *press
in presses) {
425 [
super pressesBegan:presses withEvent:event];
428 - (
void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
431 for (UIPress *press
in presses) {
436 [
super pressesEnded:presses withEvent:event];
439 - (
void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
442 for (UIPress *press
in presses) {
447 [
super pressesCancelled:presses withEvent:event];
450 - (
void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
453 [
super pressesChanged:presses withEvent:event];
458 -(
void)mouseWheelGesture:(UIPanGestureRecognizer *)gesture
460 if (gesture.state == UIGestureRecognizerStateBegan ||
461 gesture.state == UIGestureRecognizerStateChanged ||
462 gesture.state == UIGestureRecognizerStateEnded) {
463 CGPoint velocity = [gesture velocityInView:self];
465 if (velocity.x > 0.0f) {
467 }
else if (velocity.x < 0.0f) {
470 if (velocity.y > 0.0f) {
472 }
else if (velocity.y < 0.0f) {
475 if (velocity.x != 0.0f || velocity.y != 0.0f) {
482 -(
void)swipeGesture:(UISwipeGestureRecognizer *)gesture
485 if (gesture.state == UIGestureRecognizerStateEnded) {
486 #if !SDL_JOYSTICK_DISABLED
490 switch (gesture.direction) {
491 case UISwipeGestureRecognizerDirectionUp:
494 case UISwipeGestureRecognizerDirectionDown:
497 case UISwipeGestureRecognizerDirectionLeft:
500 case UISwipeGestureRecognizerDirectionRight:
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
int SDL_SendKeyboardKeyAutoRelease(SDL_Scancode scancode)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_AppleTVRemoteOpenedAsJoystick
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLint GLint GLint x
GLuint GLuint GLsizei GLenum type
SDL_Scancode
The SDL keyboard scancode representation.
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, SDL_bool down, float x, float y, float pressure)
int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, float x, float y, float pressure)
@ SDL_TOUCH_DEVICE_DIRECT
@ SDL_TOUCH_DEVICE_INDIRECT_RELATIVE
SDL_bool SDL_HasGCKeyboard(void)
SDL_bool SDL_HasGCMouse(void)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.