21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_UIKIT 27 #include "../../events/SDL_mouse_c.h" 28 #include "../../events/SDL_touch_c.h" 29 #include "../../events/SDL_events_c.h" 39 UITouch * __weak firstFingerDown;
42 - (instancetype)initWithFrame:(CGRect)frame
44 if ((
self = [super initWithFrame:
frame])) {
47 UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
48 swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
49 [
self addGestureRecognizer:swipeUp];
51 UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
52 swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
53 [
self addGestureRecognizer:swipeDown];
55 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
56 swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
57 [
self addGestureRecognizer:swipeLeft];
59 UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
60 swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
61 [
self addGestureRecognizer:swipeRight];
64 self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
65 self.autoresizesSubviews = YES;
68 self.multipleTouchEnabled = YES;
82 if (window == sdlwindow) {
91 [data.
views removeObject:
self];
93 [
self removeFromSuperview];
96 view = data.
views.lastObject;
100 data.
uiwindow.rootViewController = nil;
111 [data.
views addObject:
self];
122 data.
uiwindow.rootViewController = nil;
134 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
136 CGPoint point = [touch locationInView:self];
139 CGRect bounds =
self.bounds;
140 point.x /= bounds.size.width;
141 point.y /= bounds.size.height;
147 - (float)pressureForTouch:(UITouch *)touch
150 if ([touch respondsToSelector:
@selector(force)]) {
151 return (
float) touch.force;
158 - (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
160 for (UITouch *touch
in touches) {
161 float pressure = [
self pressureForTouch:touch];
163 if (!firstFingerDown) {
164 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
165 int clicks = (int) touch.tapCount;
173 firstFingerDown = touch;
176 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
178 SDL_TRUE, locationInView.x, locationInView.y, pressure);
182 - (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
184 for (UITouch *touch
in touches) {
185 float pressure = [
self pressureForTouch:touch];
187 if (touch == firstFingerDown) {
189 int clicks = (int) touch.tapCount;
191 firstFingerDown = nil;
194 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
196 SDL_FALSE, locationInView.x, locationInView.y, pressure);
200 - (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
202 [
self touchesEnded:touches withEvent:event];
205 - (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
207 for (UITouch *touch
in touches) {
208 float pressure = [
self pressureForTouch:touch];
210 if (touch == firstFingerDown) {
211 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
217 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
219 locationInView.x, locationInView.y, pressure);
223 #if TARGET_OS_TV || defined(__IPHONE_9_1) 224 - (
SDL_Scancode)scancodeFromPressType:(UIPressType)presstype
227 case UIPressTypeUpArrow:
229 case UIPressTypeDownArrow:
231 case UIPressTypeLeftArrow:
233 case UIPressTypeRightArrow:
235 case UIPressTypeSelect:
238 case UIPressTypeMenu:
241 case UIPressTypePlayPause:
249 - (
void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
251 for (UIPress *press
in presses) {
252 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
256 [
super pressesBegan:presses withEvent:event];
259 - (
void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
261 for (UIPress *press
in presses) {
262 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
266 [
super pressesEnded:presses withEvent:event];
269 - (
void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
271 for (UIPress *press
in presses) {
272 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
276 [
super pressesCancelled:presses withEvent:event];
279 - (
void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
282 [
super pressesChanged:presses withEvent:event];
287 -(
void)swipeGesture:(UISwipeGestureRecognizer *)gesture
290 if (gesture.state == UIGestureRecognizerStateEnded) {
293 switch (gesture.direction) {
294 case UISwipeGestureRecognizerDirectionUp:
298 case UISwipeGestureRecognizerDirectionDown:
302 case UISwipeGestureRecognizerDirectionLeft:
306 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.
SDL_Scancode
The SDL keyboard scancode representation.