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;
48 self.multipleTouchEnabled = YES;
61 if (window == sdlwindow) {
70 [data.
views removeObject:
self];
72 [
self removeFromSuperview];
75 view = data.
views.lastObject;
79 data.
uiwindow.rootViewController = nil;
90 [data.
views addObject:
self];
101 data.
uiwindow.rootViewController = nil;
113 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
115 CGPoint point = [touch locationInView:self];
118 CGRect bounds =
self.bounds;
119 point.
x /= bounds.size.width;
120 point.y /= bounds.size.height;
126 - (float)pressureForTouch:(UITouch *)touch
129 if ([touch respondsToSelector:
@selector(force)]) {
130 return (
float) touch.force;
137 - (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
139 for (UITouch *touch
in touches) {
140 float pressure = [
self pressureForTouch:touch];
142 if (!firstFingerDown) {
143 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
151 firstFingerDown = touch;
154 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
156 SDL_TRUE, locationInView.x, locationInView.y, pressure);
160 - (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
162 for (UITouch *touch
in touches) {
163 float pressure = [
self pressureForTouch:touch];
165 if (touch == firstFingerDown) {
168 firstFingerDown = nil;
171 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
173 SDL_FALSE, locationInView.x, locationInView.y, pressure);
177 - (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
179 [
self touchesEnded:touches withEvent:event];
182 - (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
184 for (UITouch *touch
in touches) {
185 float pressure = [
self pressureForTouch:touch];
187 if (touch == firstFingerDown) {
188 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
194 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
196 locationInView.x, locationInView.y, pressure);
SDL_uikitviewcontroller * viewcontroller
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
#define SDL_TOUCH_MOUSEID
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.
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)