comparison src/video/uikit/SDL_uikitview.m @ 4694:c24ba2cc9583

Merged Jim's Google Summer of Code work from SDL-gsoc2010_gesture
author Sam Lantinga <slouken@libsdl.org>
date Sun, 22 Aug 2010 12:07:55 -0700
parents e2d46c5c7483 f8431f66613d
children a69e36365766
comparison
equal deleted inserted replaced
4638:08d22c54a21f 4694:c24ba2cc9583
22 22
23 #import "SDL_uikitview.h" 23 #import "SDL_uikitview.h"
24 24
25 #include "../../events/SDL_keyboard_c.h" 25 #include "../../events/SDL_keyboard_c.h"
26 #include "../../events/SDL_mouse_c.h" 26 #include "../../events/SDL_mouse_c.h"
27 #include "../../events/SDL_touch_c.h"
27 28
28 #if SDL_IPHONE_KEYBOARD 29 #if SDL_IPHONE_KEYBOARD
29 #import "keyinfotable.h" 30 #import "keyinfotable.h"
30 #import "SDL_uikitappdelegate.h" 31 #import "SDL_uikitappdelegate.h"
31 #import "SDL_uikitwindow.h" 32 #import "SDL_uikitwindow.h"
46 47
47 #if SDL_IPHONE_KEYBOARD 48 #if SDL_IPHONE_KEYBOARD
48 [self initializeKeyboard]; 49 [self initializeKeyboard];
49 #endif 50 #endif
50 51
51 #if FIXME_MULTITOUCH 52 #ifdef FIXED_MULTITOUCH
52 int i; 53 SDL_Touch touch;
53 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { 54 touch.id = 0; //TODO: Should be -1?
54 mice[i].id = i; 55
55 mice[i].driverdata = NULL; 56 //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
56 SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); 57 //EventTouchData* data = (EventTouchData*)(touch.driverdata);
57 } 58
58 self.multipleTouchEnabled = YES; 59 touch.x_min = 0;
59 #endif 60 touch.x_max = frame.size.width;
60 61 touch.native_xres = touch.x_max - touch.x_min;
62 touch.y_min = 0;
63 touch.y_max = frame.size.height;
64 touch.native_yres = touch.y_max - touch.y_min;
65 touch.pressure_min = 0;
66 touch.pressure_max = 1;
67 touch.native_pressureres = touch.pressure_max - touch.pressure_min;
68
69
70 touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
71 #endif
72
61 return self; 73 return self;
62 74
63 } 75 }
64 76
65 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 77 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
66 78
67 NSEnumerator *enumerator = [touches objectEnumerator]; 79 NSEnumerator *enumerator = [touches objectEnumerator];
68 UITouch *touch = (UITouch*)[enumerator nextObject]; 80 UITouch *touch = (UITouch*)[enumerator nextObject];
69 81
70 #if FIXME_MULTITOUCH 82 //NSLog("Click");
71 /* associate touches with mice, so long as we have slots */ 83
72 int i;
73 int found = 0;
74 for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
75
76 /* check if this mouse is already tracking a touch */
77 if (mice[i].driverdata != NULL) {
78 continue;
79 }
80 /*
81 mouse not associated with anything right now,
82 associate the touch with this mouse
83 */
84 found = 1;
85
86 /* save old mouse so we can switch back */
87 int oldMouse = SDL_SelectMouse(-1);
88
89 /* select this slot's mouse */
90 SDL_SelectMouse(i);
91 CGPoint locationInView = [touch locationInView: self];
92
93 /* set driver data to touch object, we'll use touch object later */
94 mice[i].driverdata = [touch retain];
95
96 /* send moved event */
97 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
98
99 /* send mouse down event */
100 SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
101
102 /* re-calibrate relative mouse motion */
103 SDL_GetRelativeMouseState(i, NULL, NULL);
104
105 /* switch back to our old mouse */
106 SDL_SelectMouse(oldMouse);
107
108 /* grab next touch */
109 touch = (UITouch*)[enumerator nextObject];
110 }
111 #else
112 if (touch) { 84 if (touch) {
113 CGPoint locationInView = [touch locationInView: self]; 85 CGPoint locationInView = [touch locationInView: self];
114 86
115 /* send moved event */ 87 /* send moved event */
116 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); 88 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
117 89
118 /* send mouse down event */ 90 /* send mouse down event */
119 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); 91 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
120 } 92 }
93
94 #ifdef FIXED_MULTITOUCH
95 while(touch) {
96 CGPoint locationInView = [touch locationInView: self];
97
98
99 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
100 //FIXME: TODO: Using touch as the fingerId is potentially dangerous
101 //It is also much more efficient than storing the UITouch pointer
102 //and comparing it to the incoming event.
103 SDL_SendFingerDown(touchId,(long)touch,
104 SDL_TRUE,locationInView.x,locationInView.y,
105 1);
106 #else
107 int i;
108 for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
109 if(finger[i] == NULL) {
110 finger[i] = touch;
111 SDL_SendFingerDown(touchId,i,
112 SDL_TRUE,locationInView.x,locationInView.y,
113 1);
114 break;
115 }
116 }
117 #endif
118
119
120
121
122 touch = (UITouch*)[enumerator nextObject];
123 }
121 #endif 124 #endif
122 } 125 }
123 126
124 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 127 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
125 128
126 NSEnumerator *enumerator = [touches objectEnumerator]; 129 NSEnumerator *enumerator = [touches objectEnumerator];
127 UITouch *touch = (UITouch*)[enumerator nextObject]; 130 UITouch *touch = (UITouch*)[enumerator nextObject];
128 131
129 #if FIXME_MULTITOUCH
130 while(touch) {
131 /* search for the mouse slot associated with this touch */
132 int i, found = NO;
133 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
134 if (mice[i].driverdata == touch) {
135 /* found the mouse associate with the touch */
136 [(UITouch*)(mice[i].driverdata) release];
137 mice[i].driverdata = NULL;
138 /* send mouse up */
139 SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
140 /* discontinue search for this touch */
141 found = YES;
142 }
143 }
144
145 /* grab next touch */
146 touch = (UITouch*)[enumerator nextObject];
147 }
148 #else
149 if (touch) { 132 if (touch) {
150 /* send mouse up */ 133 /* send mouse up */
151 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); 134 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
135 }
136
137 #ifdef FIXED_MULTITOUCH
138 while(touch) {
139 CGPoint locationInView = [touch locationInView: self];
140
141
142 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
143 SDL_SendFingerDown(touchId,(long)touch,
144 SDL_FALSE,locationInView.x,locationInView.y,
145 1);
146 #else
147 int i;
148 for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
149 if(finger[i] == touch) {
150 SDL_SendFingerDown(touchId,i,
151 SDL_FALSE,locationInView.x,locationInView.y,
152 1);
153 break;
154 }
155 }
156 #endif
157
158 touch = (UITouch*)[enumerator nextObject];
152 } 159 }
153 #endif 160 #endif
154 } 161 }
155 162
156 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { 163 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
165 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 172 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
166 173
167 NSEnumerator *enumerator = [touches objectEnumerator]; 174 NSEnumerator *enumerator = [touches objectEnumerator];
168 UITouch *touch = (UITouch*)[enumerator nextObject]; 175 UITouch *touch = (UITouch*)[enumerator nextObject];
169 176
170 #if FIXME_MULTITOUCH
171 while(touch) {
172 /* try to find the mouse associated with this touch */
173 int i, found = NO;
174 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
175 if (mice[i].driverdata == touch) {
176 /* found proper mouse */
177 CGPoint locationInView = [touch locationInView: self];
178 /* send moved event */
179 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
180 /* discontinue search */
181 found = YES;
182 }
183 }
184
185 /* grab next touch */
186 touch = (UITouch*)[enumerator nextObject];
187 }
188 #else
189 if (touch) { 177 if (touch) {
190 CGPoint locationInView = [touch locationInView: self]; 178 CGPoint locationInView = [touch locationInView: self];
191 179
192 /* send moved event */ 180 /* send moved event */
193 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); 181 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
182 }
183
184 #ifdef FIXED_MULTITOUCH
185 while(touch) {
186 CGPoint locationInView = [touch locationInView: self];
187
188
189 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
190 SDL_SendTouchMotion(touchId,(long)touch,
191 SDL_FALSE,locationInView.x,locationInView.y,
192 1);
193 #else
194 int i;
195 for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
196 if(finger[i] == touch) {
197 SDL_SendTouchMotion(touchId,i,
198 SDL_FALSE,locationInView.x,locationInView.y,
199 1);
200 break;
201 }
202 }
203 #endif
204
205 touch = (UITouch*)[enumerator nextObject];
194 } 206 }
195 #endif 207 #endif
196 } 208 }
197 209
198 /* 210 /*