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" 43 UITouch * __weak firstFingerDown;
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;
72 self.multipleTouchEnabled = YES;
86 if (window == sdlwindow) {
95 [data.
views removeObject:
self];
97 [
self removeFromSuperview];
100 view = data.
views.lastObject;
104 data.
uiwindow.rootViewController = nil;
115 [data.
views addObject:
self];
126 data.
uiwindow.rootViewController = nil;
138 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
140 CGPoint point = [touch locationInView:self];
143 CGRect bounds =
self.bounds;
144 point.x /= bounds.size.width;
145 point.y /= bounds.size.height;
151 - (float)pressureForTouch:(UITouch *)touch
154 if ([touch respondsToSelector:
@selector(force)]) {
155 return (
float) touch.force;
162 - (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
164 for (UITouch *touch
in touches) {
165 float pressure = [
self pressureForTouch:touch];
167 if (!firstFingerDown) {
168 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
169 int clicks = (int) touch.tapCount;
177 firstFingerDown = touch;
180 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
182 SDL_TRUE, locationInView.x, locationInView.y, pressure);
186 - (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
188 for (UITouch *touch
in touches) {
189 float pressure = [
self pressureForTouch:touch];
191 if (touch == firstFingerDown) {
193 int clicks = (int) touch.tapCount;
195 firstFingerDown = nil;
198 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
200 SDL_FALSE, locationInView.x, locationInView.y, pressure);
204 - (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
206 [
self touchesEnded:touches withEvent:event];
209 - (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
211 for (UITouch *touch
in touches) {
212 float pressure = [
self pressureForTouch:touch];
214 if (touch == firstFingerDown) {
215 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
221 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
223 locationInView.x, locationInView.y, pressure);
227 #if TARGET_OS_TV || defined(__IPHONE_9_1) 228 - (
SDL_Scancode)scancodeFromPressType:(UIPressType)presstype
231 case UIPressTypeUpArrow:
233 case UIPressTypeDownArrow:
235 case UIPressTypeLeftArrow:
237 case UIPressTypeRightArrow:
239 case UIPressTypeSelect:
242 case UIPressTypeMenu:
245 case UIPressTypePlayPause:
253 - (
void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
256 for (UIPress *press
in presses) {
257 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
261 [
super pressesBegan:presses withEvent:event];
264 - (
void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
267 for (UIPress *press
in presses) {
268 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
272 [
super pressesEnded:presses withEvent:event];
275 - (
void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
278 for (UIPress *press
in presses) {
279 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
283 [
super pressesCancelled:presses withEvent:event];
286 - (
void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
289 [
super pressesChanged:presses withEvent:event];
294 -(
void)swipeGesture:(UISwipeGestureRecognizer *)gesture
297 if (gesture.state == UIGestureRecognizerStateEnded) {
301 switch (gesture.direction) {
302 case UISwipeGestureRecognizerDirectionUp:
306 case UISwipeGestureRecognizerDirectionDown:
310 case UISwipeGestureRecognizerDirectionLeft:
314 case UISwipeGestureRecognizerDirectionRight:
SDL_uikitviewcontroller * viewcontroller
int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define SDL_TOUCH_MOUSEID
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
EGLSurface EGLNativeWindowType * window
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
The type used to identify a window.
int SDL_AppleTVRemoteOpenedAsJoystick
SDL_Scancode
The SDL keyboard scancode representation.