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"
46- (instancetype)initWithFrame:(CGRect)frame
48 if ((
self = [super initWithFrame:
frame])) {
51 UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
52 swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
53 [
self addGestureRecognizer:swipeUp];
55 UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
56 swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
57 [
self addGestureRecognizer:swipeDown];
59 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
60 swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
61 [
self addGestureRecognizer:swipeLeft];
63 UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
64 swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
65 [
self addGestureRecognizer:swipeRight];
68 self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
69 self.autoresizesSubviews = YES;
75 self.multipleTouchEnabled = YES;
96 [
data.views removeObject:
self];
98 [
self removeFromSuperview];
101 view =
data.views.lastObject;
103 data.viewcontroller.view = view;
105 data.uiwindow.rootViewController = nil;
106 data.uiwindow.rootViewController =
data.viewcontroller;
108 [
data.uiwindow layoutIfNeeded];
116 [
data.views addObject:
self];
119 [
data.viewcontroller.view removeFromSuperview];
120 data.viewcontroller.view =
self;
127 data.uiwindow.rootViewController = nil;
128 data.uiwindow.rootViewController =
data.viewcontroller;
133 [
data.uiwindow layoutIfNeeded];
142 if ([touch respondsToSelector:
@selector((
type))]) {
143 if (touch.type == UITouchTypeIndirect) {
157 return directTouchId;
159 return indirectTouchId;
163- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
165 CGPoint point = [touch locationInView:self];
168 CGRect bounds =
self.bounds;
169 point.x /= bounds.size.width;
170 point.y /= bounds.size.height;
176- (float)pressureForTouch:(UITouch *)touch
179 if ([touch respondsToSelector:
@selector(force)]) {
180 return (
float) touch.force;
187- (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
189 for (UITouch *touch
in touches) {
191 SDL_TouchID touchId = [
self touchIdForType:touchType];
192 float pressure = [
self pressureForTouch:touch];
200 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
202 SDL_TRUE, locationInView.x, locationInView.y, pressure);
206- (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
208 for (UITouch *touch
in touches) {
210 SDL_TouchID touchId = [
self touchIdForType:touchType];
211 float pressure = [
self pressureForTouch:touch];
219 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
221 SDL_FALSE, locationInView.x, locationInView.y, pressure);
225- (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
227 [
self touchesEnded:touches withEvent:event];
230- (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
232 for (UITouch *touch
in touches) {
234 SDL_TouchID touchId = [
self touchIdForType:touchType];
235 float pressure = [
self pressureForTouch:touch];
241 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
243 locationInView.x, locationInView.y, pressure);
247#if TARGET_OS_TV || defined(__IPHONE_9_1)
248- (
SDL_Scancode)scancodeFromPressType:(UIPressType)presstype
251 case UIPressTypeUpArrow:
253 case UIPressTypeDownArrow:
255 case UIPressTypeLeftArrow:
257 case UIPressTypeRightArrow:
259 case UIPressTypeSelect:
262 case UIPressTypeMenu:
265 case UIPressTypePlayPause:
273- (
void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
276 for (UIPress *press
in presses) {
277 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
281 [
super pressesBegan:presses withEvent:event];
284- (
void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
287 for (UIPress *press
in presses) {
288 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
292 [
super pressesEnded:presses withEvent:event];
295- (
void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
298 for (UIPress *press
in presses) {
299 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
303 [
super pressesCancelled:presses withEvent:event];
306- (
void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
309 [
super pressesChanged:presses withEvent:event];
314-(
void)swipeGesture:(UISwipeGestureRecognizer *)gesture
317 if (gesture.state == UIGestureRecognizerStateEnded) {
321 switch (gesture.direction) {
322 case UISwipeGestureRecognizerDirectionUp:
326 case UISwipeGestureRecognizerDirectionDown:
330 case UISwipeGestureRecognizerDirectionLeft:
334 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_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint GLuint GLsizei GLenum type
SDL_Scancode
The SDL keyboard scancode representation.
int SDL_AppleTVRemoteOpenedAsJoystick
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
@ SDL_TOUCH_DEVICE_DIRECT
@ SDL_TOUCH_DEVICE_INDIRECT_RELATIVE
EGLSurface EGLNativeWindowType * window
The type used to identify a window.