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])) {
45 self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
46 self.autoresizesSubviews = YES;
49 self.multipleTouchEnabled = YES;
63 if (window == sdlwindow) {
72 [data.
views removeObject:
self];
74 [
self removeFromSuperview];
77 view = data.
views.lastObject;
81 data.
uiwindow.rootViewController = nil;
92 [data.
views addObject:
self];
103 data.
uiwindow.rootViewController = nil;
115 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
117 CGPoint point = [touch locationInView:self];
120 CGRect bounds =
self.bounds;
121 point.
x /= bounds.size.width;
122 point.y /= bounds.size.height;
128 - (float)pressureForTouch:(UITouch *)touch
131 if ([touch respondsToSelector:
@selector(force)]) {
132 return (
float) touch.force;
139 - (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
141 for (UITouch *touch
in touches) {
142 float pressure = [
self pressureForTouch:touch];
144 if (!firstFingerDown) {
145 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
146 int clicks = (int) touch.tapCount;
154 firstFingerDown = touch;
157 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
159 SDL_TRUE, locationInView.x, locationInView.y, pressure);
163 - (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
165 for (UITouch *touch
in touches) {
166 float pressure = [
self pressureForTouch:touch];
168 if (touch == firstFingerDown) {
170 int clicks = (int) touch.tapCount;
172 firstFingerDown = nil;
175 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
177 SDL_FALSE, locationInView.x, locationInView.y, pressure);
181 - (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
183 [
self touchesEnded:touches withEvent:event];
186 - (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
188 for (UITouch *touch
in touches) {
189 float pressure = [
self pressureForTouch:touch];
191 if (touch == firstFingerDown) {
192 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
198 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
200 locationInView.x, locationInView.y, pressure);
204 #if TARGET_OS_TV || defined(__IPHONE_9_1) 205 - (
SDL_Scancode)scancodeFromPressType:(UIPressType)presstype
208 case UIPressTypeUpArrow:
210 case UIPressTypeDownArrow:
212 case UIPressTypeLeftArrow:
214 case UIPressTypeRightArrow:
216 case UIPressTypeSelect:
219 case UIPressTypeMenu:
222 case UIPressTypePlayPause:
230 - (
void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
232 for (UIPress *press
in presses) {
233 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
237 [
super pressesBegan:presses withEvent:event];
240 - (
void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
242 for (UIPress *press
in presses) {
243 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
247 [
super pressesEnded:presses withEvent:event];
250 - (
void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
252 for (UIPress *press
in presses) {
253 SDL_Scancode scancode = [
self scancodeFromPressType:press.type];
257 [
super pressesCancelled:presses withEvent:event];
260 - (
void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
263 [
super pressesChanged:presses withEvent:event];
static SDL_Window * window
SDL_uikitviewcontroller * viewcontroller
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
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)
#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)
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.