Mercurial > sdl-ios-xcode
comparison src/events/SDL_touch.c @ 4641:49a97daea6ec
Added touch event definitions. Heavily modified events/SDL_touch*.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Thu, 27 May 2010 01:21:37 -0400 |
parents | f068a6dfc858 |
children | 057e8762d2a1 |
comparison
equal
deleted
inserted
replaced
4640:f068a6dfc858 | 4641:49a97daea6ec |
---|---|
27 #include "SDL_events_c.h" | 27 #include "SDL_events_c.h" |
28 #include "../video/SDL_sysvideo.h" | 28 #include "../video/SDL_sysvideo.h" |
29 | 29 |
30 | 30 |
31 static int SDL_num_touch = 0; | 31 static int SDL_num_touch = 0; |
32 static int SDL_current_touch = -1; | 32 static SDL_Touch **SDL_touchPads = NULL; |
33 static SDL_Touch **SDL_touch = NULL; | |
34 | 33 |
35 | 34 |
36 /* Public functions */ | 35 /* Public functions */ |
37 int | 36 int |
38 SDL_TouchInit(void) | 37 SDL_TouchInit(void) |
39 { | 38 { |
40 return (0); | 39 return (0); |
41 } | 40 } |
42 | |
43 SDL_Touch * | 41 SDL_Touch * |
44 SDL_GetTouch(int index) | 42 SDL_GetTouch(int id) |
45 { | 43 { |
44 int index = SDL_GetTouchIndexId(id); | |
46 if (index < 0 || index >= SDL_num_touch) { | 45 if (index < 0 || index >= SDL_num_touch) { |
47 return NULL; | 46 return NULL; |
48 } | 47 } |
49 return SDL_touch[index]; | 48 return SDL_touchPads[index]; |
50 } | 49 } |
51 | 50 |
52 static int | 51 SDL_Finger * |
52 SDL_GetFinger(SDL_Touch* touch,int id) | |
53 { | |
54 int index = SDL_GetFingerIndexId(touch,id); | |
55 if(index < 0 || index >= touch->num_fingers) | |
56 return NULL; | |
57 return touch->fingers[index]; | |
58 } | |
59 | |
60 int | |
61 SDL_GetFingerIndexId(SDL_Touch* touch,int fingerid) | |
62 { | |
63 int i; | |
64 for(i = 0;i < touch->num_fingers;i++) | |
65 if(touch->fingers[i]->id == fingerid) | |
66 return i; | |
67 return -1; | |
68 } | |
69 | |
70 int | |
53 SDL_GetTouchIndexId(int id) | 71 SDL_GetTouchIndexId(int id) |
54 { | 72 { |
55 int index; | 73 int index; |
56 SDL_Touch *touch; | 74 SDL_Touch *touch; |
57 | 75 |
58 for (index = 0; index < SDL_num_touch; ++index) { | 76 for (index = 0; index < SDL_num_touch; ++index) { |
59 touch = SDL_GetTouch(index); | 77 touch = SDL_touchPads[index]; |
60 if (touch->id == id) { | 78 if (touch->id == id) { |
61 return index; | 79 return index; |
62 } | 80 } |
63 } | 81 } |
64 return -1; | 82 return -1; |
66 | 84 |
67 int | 85 int |
68 SDL_AddTouch(const SDL_Touch * touch, char *name, int pressure_max, | 86 SDL_AddTouch(const SDL_Touch * touch, char *name, int pressure_max, |
69 int pressure_min, int ends) | 87 int pressure_min, int ends) |
70 { | 88 { |
71 SDL_Touch **touch; | 89 SDL_Touch **touchPads; |
72 int selected_touch; | 90 int selected_touch; |
73 int index; | 91 int index; |
74 size_t length; | 92 size_t length; |
75 | 93 |
76 if (SDL_GetTouchIndexId(touch->id) != -1) { | 94 if (SDL_GetTouchIndexId(touch->id) != -1) { |
77 SDL_SetError("Touch ID already in use"); | 95 SDL_SetError("Touch ID already in use"); |
78 } | 96 } |
79 | 97 |
80 /* Add the touch to the list of touch */ | 98 /* Add the touch to the list of touch */ |
81 touch = (SDL_Touch **) SDL_realloc(SDL_touch, | 99 touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads, |
82 (SDL_num_touch + 1) * sizeof(*touch)); | 100 (SDL_num_touch + 1) * sizeof(*touch)); |
83 if (!touch) { | 101 if (!touchPads) { |
84 SDL_OutOfMemory(); | 102 SDL_OutOfMemory(); |
85 return -1; | 103 return -1; |
86 } | 104 } |
87 | 105 |
88 SDL_touch = touch; | 106 SDL_touchPads = touchPads; |
89 index = SDL_num_touch++; | 107 index = SDL_num_touch++; |
90 | 108 |
91 SDL_touch[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touch[index])); | 109 SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index])); |
92 if (!SDL_touch[index]) { | 110 if (!SDL_touchPads[index]) { |
93 SDL_OutOfMemory(); | 111 SDL_OutOfMemory(); |
94 return -1; | 112 return -1; |
95 } | 113 } |
96 *SDL_touch[index] = *touch; | 114 *SDL_touchPads[index] = *touch; |
97 | 115 |
98 /* we're setting the touch properties */ | 116 /* we're setting the touch properties */ |
99 length = 0; | 117 length = 0; |
100 length = SDL_strlen(name); | 118 length = SDL_strlen(name); |
101 SDL_touch[index]->focus = 0; | 119 SDL_touchPads[index]->focus = 0; |
102 SDL_touch[index]->name = SDL_malloc((length + 2) * sizeof(char)); | 120 SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char)); |
103 SDL_strlcpy(SDL_touch[index]->name, name, length + 1); | 121 SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1); |
104 SDL_touch[index]->pressure_max = pressure_max; | 122 SDL_touchPads[index]->pressure_max = pressure_max; |
105 SDL_touch[index]->pressure_min = pressure_min; | 123 SDL_touchPads[index]->pressure_min = pressure_min; |
106 SDL_touch[index]->cursor_shown = SDL_TRUE; | 124 |
107 selected_touch = SDL_SelectTouch(index); | |
108 SDL_touch[index]->cur_cursor = NULL; | |
109 SDL_touch[index]->def_cursor = | |
110 /* we're assuming that all touch are in the computer sensing zone */ | |
111 SDL_touch[index]->proximity = SDL_TRUE; | |
112 /* we're assuming that all touch are working in the absolute position mode | |
113 thanx to that, the users that don't want to use many touch don't have to | |
114 worry about anything */ | |
115 SDL_touch[index]->relative_mode = SDL_FALSE; | |
116 SDL_touch[index]->current_end = 0; | |
117 SDL_touch[index]->total_ends = ends; | |
118 SDL_SelectTouch(selected_touch); | |
119 | 125 |
120 return index; | 126 return index; |
121 } | 127 } |
122 | 128 |
123 void | 129 void |
124 SDL_DelTouch(int index) | 130 SDL_DelTouch(int id) |
125 { | 131 { |
126 SDL_Touch *touch = SDL_GetTouch(index); | 132 int index = SDL_GetTouchIndexId(id); |
133 SDL_Touch *touch = SDL_GetTouch(id); | |
127 | 134 |
128 if (!touch) { | 135 if (!touch) { |
129 return; | 136 return; |
130 } | 137 } |
131 | 138 |
132 touch->def_cursor = NULL; | 139 |
133 SDL_free(touch->name); | 140 SDL_free(touch->name); |
134 | 141 |
135 if (touch->FreeTouch) { | 142 if (touch->FreeTouch) { |
136 touch->FreeTouch(touch); | 143 touch->FreeTouch(touch); |
137 } | 144 } |
138 SDL_free(touch); | 145 SDL_free(touch); |
139 | 146 |
140 SDL_touch[index] = NULL; | 147 SDL_num_touch--; |
141 } | 148 SDL_touchPads[index] = SDL_touchPads[SDL_num_touch]; |
142 | |
143 void | |
144 SDL_ResetTouch(int index) | |
145 { | |
146 SDL_Touch *touch = SDL_GetTouch(index); | |
147 | |
148 if (!touch) { | |
149 return; | |
150 } | |
151 | |
152 /* FIXME */ | |
153 } | 149 } |
154 | 150 |
155 void | 151 void |
156 SDL_TouchQuit(void) | 152 SDL_TouchQuit(void) |
157 { | 153 { |
158 int i; | 154 int i; |
159 | 155 |
160 for (i = 0; i < SDL_num_touch; ++i) { | 156 for (i = SDL_num_touch-1; i > 0 ; --i) { |
161 SDL_DelTouch(i); | 157 SDL_DelTouch(i); |
162 } | 158 } |
163 SDL_num_touch = 0; | 159 SDL_num_touch = 0; |
164 SDL_current_touch = -1; | 160 |
165 | 161 if (SDL_touchPads) { |
166 if (SDL_touch) { | 162 SDL_free(SDL_touchPads); |
167 SDL_free(SDL_touch); | 163 SDL_touchPads = NULL; |
168 SDL_touch = NULL; | |
169 } | 164 } |
170 } | 165 } |
171 | 166 |
172 int | 167 int |
173 SDL_GetNumTouch(void) | 168 SDL_GetNumTouch(void) |
174 { | 169 { |
175 return SDL_num_touch; | 170 return SDL_num_touch; |
176 } | 171 } |
177 | |
178 int | |
179 SDL_SelectTouch(int index) | |
180 { | |
181 if (index >= 0 && index < SDL_num_touch) { | |
182 SDL_current_touch = index; | |
183 } | |
184 return SDL_current_touch; | |
185 } | |
186 | |
187 SDL_Window * | 172 SDL_Window * |
188 SDL_GetTouchFocusWindow(int index) | 173 SDL_GetTouchFocusWindow(int id) |
189 { | 174 { |
190 SDL_Touch *touch = SDL_GetTouch(index); | 175 SDL_Touch *touch = SDL_GetTouch(id); |
191 | 176 |
192 if (!touch) { | 177 if (!touch) { |
193 return 0; | 178 return 0; |
194 } | 179 } |
195 return touch->focus; | 180 return touch->focus; |
196 } | 181 } |
197 | 182 |
198 static int SDLCALL | |
199 FlushTouchMotion(void *param, SDL_Event * event) | |
200 { | |
201 if (event->type == SDL_TOUCHMOTION | |
202 && event->motion.which == (Uint8) SDL_current_touch) { | |
203 return 0; | |
204 } else { | |
205 return 1; | |
206 } | |
207 } | |
208 | |
209 int | |
210 SDL_SetRelativeTouchMode(int index, SDL_bool enabled) | |
211 { | |
212 SDL_Touch *touch = SDL_GetTouch(index); | |
213 | |
214 if (!touch) { | |
215 return -1; | |
216 } | |
217 | |
218 /* Flush pending touch motion */ | |
219 touch->flush_motion = SDL_TRUE; | |
220 SDL_PumpEvents(); | |
221 touch->flush_motion = SDL_FALSE; | |
222 SDL_FilterEvents(FlushTouchMotion, touch); | |
223 | |
224 /* Set the relative mode */ | |
225 touch->relative_mode = enabled; | |
226 | |
227 | |
228 | |
229 if (!enabled) { | |
230 /* Restore the expected touch position */ | |
231 SDL_WarpTouchInWindow(touch->focus, touch->x, touch->y); | |
232 } | |
233 return 0; | |
234 } | |
235 | |
236 SDL_bool | |
237 SDL_GetRelativeTouchMode(int index) | |
238 { | |
239 SDL_Touch *touch = SDL_GetTouch(index); | |
240 | |
241 if (!touch) { | |
242 return SDL_FALSE; | |
243 } | |
244 return touch->relative_mode; | |
245 } | |
246 | |
247 Uint8 | |
248 SDL_GetTouchState(int *x, int *y) | |
249 { | |
250 SDL_Touch *touch = SDL_GetTouch(SDL_current_touch); | |
251 | |
252 if (!touch) { | |
253 if (x) { | |
254 *x = 0; | |
255 } | |
256 if (y) { | |
257 *y = 0; | |
258 } | |
259 return 0; | |
260 } | |
261 | |
262 if (x) { | |
263 *x = touch->x; | |
264 } | |
265 if (y) { | |
266 *y = touch->y; | |
267 } | |
268 return touch->buttonstate; | |
269 } | |
270 | |
271 Uint8 | |
272 SDL_GetRelativeTouchState(int index, int *x, int *y) | |
273 { | |
274 SDL_Touch *touch = SDL_GetTouch(index); | |
275 | |
276 if (!touch) { | |
277 if (x) { | |
278 *x = 0; | |
279 } | |
280 if (y) { | |
281 *y = 0; | |
282 } | |
283 return 0; | |
284 } | |
285 | |
286 if (x) { | |
287 *x = touch->xdelta; | |
288 } | |
289 if (y) { | |
290 *y = touch->ydelta; | |
291 } | |
292 touch->xdelta = 0; | |
293 touch->ydelta = 0; | |
294 return touch->buttonstate; | |
295 } | |
296 | |
297 void | 183 void |
298 SDL_SetTouchFocus(int id, SDL_Window * window) | 184 SDL_SetTouchFocus(int id, SDL_Window * window) |
299 { | 185 { |
300 int index = SDL_GetTouchIndexId(id); | 186 int index = SDL_GetTouchIndexId(id); |
301 SDL_Touch *touch = SDL_GetTouch(index); | 187 SDL_Touch *touch = SDL_GetTouch(id); |
302 int i; | 188 int i; |
303 SDL_bool focus; | 189 SDL_bool focus; |
304 | 190 |
305 if (!touch || (touch->focus == window)) { | 191 if (!touch || (touch->focus == window)) { |
306 return; | 192 return; |
310 if (touch->focus) { | 196 if (touch->focus) { |
311 focus = SDL_FALSE; | 197 focus = SDL_FALSE; |
312 for (i = 0; i < SDL_num_touch; ++i) { | 198 for (i = 0; i < SDL_num_touch; ++i) { |
313 SDL_Touch *check; | 199 SDL_Touch *check; |
314 if (i != index) { | 200 if (i != index) { |
315 check = SDL_GetTouch(i); | 201 check = SDL_touchPads[i]; |
316 if (check && check->focus == touch->focus) { | 202 if (check && check->focus == touch->focus) { |
317 focus = SDL_TRUE; | 203 focus = SDL_TRUE; |
318 break; | 204 break; |
319 } | 205 } |
320 } | 206 } |
329 if (touch->focus) { | 215 if (touch->focus) { |
330 focus = SDL_FALSE; | 216 focus = SDL_FALSE; |
331 for (i = 0; i < SDL_num_touch; ++i) { | 217 for (i = 0; i < SDL_num_touch; ++i) { |
332 SDL_Touch *check; | 218 SDL_Touch *check; |
333 if (i != index) { | 219 if (i != index) { |
334 check = SDL_GetTouch(i); | 220 check = SDL_touchPads[i]; |
335 if (check && check->focus == touch->focus) { | 221 if (check && check->focus == touch->focus) { |
336 focus = SDL_TRUE; | 222 focus = SDL_TRUE; |
337 break; | 223 break; |
338 } | 224 } |
339 } | 225 } |
342 SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0); | 228 SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0); |
343 } | 229 } |
344 } | 230 } |
345 } | 231 } |
346 | 232 |
347 int | 233 int |
348 SDL_SendProximity(int id, int x, int y, int type) | 234 SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger) |
235 { | |
236 int index; | |
237 SDL_Finger **fingers; | |
238 size_t length; | |
239 | |
240 if (SDL_GetFingerIndexId(touch,finger->id) != -1) { | |
241 SDL_SetError("Finger ID already in use"); | |
242 } | |
243 | |
244 /* Add the touch to the list of touch */ | |
245 fingers = (SDL_Finger **) SDL_realloc(touch->fingers, | |
246 (touch->num_fingers + 1) * sizeof(*touch)); | |
247 if (!fingers) { | |
248 SDL_OutOfMemory(); | |
249 return -1; | |
250 } | |
251 | |
252 touch->fingers = fingers; | |
253 index = SDL_num_touch++; | |
254 | |
255 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(*(touch->fingers[index]))); | |
256 if (!touch->fingers[index]) { | |
257 SDL_OutOfMemory(); | |
258 return -1; | |
259 } | |
260 *touch->fingers[index] = *finger; | |
261 | |
262 return index; | |
263 } | |
264 | |
265 int | |
266 SDL_DelFinger(SDL_Touch* touch,int fingerid) | |
267 { | |
268 int index = SLD_GetFingerIndexId(touch,fingerid); | |
269 SDL_Finger* finger = SDL_GetFinger(touch,fingerid); | |
270 | |
271 if (!finger) { | |
272 return; | |
273 } | |
274 | |
275 | |
276 SDL_free(finger); | |
277 touch->num_fingers--; | |
278 touch->fingers[index] = touch->fingers[touch->num_fingers]; | |
279 } | |
280 | |
281 | |
282 int | |
283 SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure) | |
284 { | |
285 SDL_Touch* touch = SDL_GetTouch(id); | |
286 if(down) { | |
287 SDL_Finger nf; | |
288 nf.id = id; | |
289 nf.x = x; | |
290 nf.y = y; | |
291 nf.pressure = pressure; | |
292 nf.xdelta = 0; | |
293 nf.ydelta = 0; | |
294 nf.last_x = x; | |
295 nf.last_y = y; | |
296 SDL_AddFinger(touch,&nf); | |
297 | |
298 posted = 0; | |
299 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { | |
300 SDL_Event event; | |
301 event.tfinger.type = SDL_FINGERDOWN; | |
302 event.tfinger.touchId = (Uint8) id; | |
303 event.tfinger.state = touch->buttonstate; | |
304 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; | |
305 event.fingerId = id; | |
306 posted = (SDL_PushEvent(&event) > 0); | |
307 } | |
308 return posted; | |
309 } | |
310 else { | |
311 SDL_DelFinger(touch,id); | |
312 posted = 0; | |
313 if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { | |
314 SDL_Event event; | |
315 event.tfinger.type = SDL_FINGERUP; | |
316 event.tfinger.touchId = (Uint8) id; | |
317 event.tfinger.state = touch->buttonstate; | |
318 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; | |
319 event.fingerId = id; | |
320 posted = (SDL_PushEvent(&event) > 0); | |
321 } | |
322 return posted; | |
323 } | |
324 } | |
325 | |
326 int | |
327 SDL_SendTouchMotion(int id, int fingerid, int relative, | |
328 int x, int y, int pressure) | |
349 { | 329 { |
350 int index = SDL_GetTouchIndexId(id); | 330 int index = SDL_GetTouchIndexId(id); |
351 SDL_Touch *touch = SDL_GetTouch(index); | 331 SDL_Touch *touch = SDL_GetTouch(id); |
352 int posted = 0; | 332 SDL_Finger *finger = SDL_GetFinger(touch,fingerid); |
353 | |
354 if (!touch) { | |
355 return 0; | |
356 } | |
357 | |
358 touch->last_x = x; | |
359 touch->last_y = y; | |
360 if (SDL_GetEventState(type) == SDL_ENABLE) { | |
361 SDL_Event event; | |
362 event.proximity.which = (Uint8) index; | |
363 event.proximity.x = x; | |
364 event.proximity.y = y; | |
365 event.proximity.cursor = touch->current_end; | |
366 event.proximity.type = type; | |
367 /* FIXME: is this right? */ | |
368 event.proximity.windowID = touch->focus ? touch->focus->id : 0; | |
369 posted = (SDL_PushEvent(&event) > 0); | |
370 if (type == SDL_PROXIMITYIN) { | |
371 touch->proximity = SDL_TRUE; | |
372 } else { | |
373 touch->proximity = SDL_FALSE; | |
374 } | |
375 } | |
376 return posted; | |
377 } | |
378 | |
379 int | |
380 SDL_SendTouchMotion(int id, int relative, int x, int y, int pressure) | |
381 { | |
382 int index = SDL_GetTouchIndexId(id); | |
383 SDL_Touch *touch = SDL_GetTouch(index); | |
384 int posted; | 333 int posted; |
385 int xrel; | 334 int xrel; |
386 int yrel; | 335 int yrel; |
387 int x_max = 0, y_max = 0; | 336 int x_max = 0, y_max = 0; |
388 | 337 |
389 if (!touch || touch->flush_motion) { | 338 if (!touch || touch->flush_motion) { |
390 return 0; | 339 return 0; |
391 } | 340 } |
392 | 341 |
393 /* if the touch is out of proximity we don't to want to have any motion from it */ | |
394 if (touch->proximity == SDL_FALSE) { | |
395 touch->last_x = x; | |
396 touch->last_y = y; | |
397 return 0; | |
398 } | |
399 | |
400 /* the relative motion is calculated regarding the system cursor last position */ | 342 /* the relative motion is calculated regarding the system cursor last position */ |
401 if (relative) { | 343 if (relative) { |
402 xrel = x; | 344 xrel = x; |
403 yrel = y; | 345 yrel = y; |
404 x = (touch->last_x + x); | 346 x = (finger->last_x + x); |
405 y = (touch->last_y + y); | 347 y = (finger->last_y + y); |
406 } else { | 348 } else { |
407 xrel = x - touch->last_x; | 349 xrel = x - finger->last_x; |
408 yrel = y - touch->last_y; | 350 yrel = y - finger->last_y; |
409 } | 351 } |
410 | 352 |
411 /* Drop events that don't change state */ | 353 /* Drop events that don't change state */ |
412 if (!xrel && !yrel) { | 354 if (!xrel && !yrel) { |
413 #if 0 | 355 #if 0 |
415 #endif | 357 #endif |
416 return 0; | 358 return 0; |
417 } | 359 } |
418 | 360 |
419 /* Update internal touch coordinates */ | 361 /* Update internal touch coordinates */ |
420 if (touch->relative_mode == SDL_FALSE) { | 362 |
421 touch->x = x; | 363 finger->x = x; |
422 touch->y = y; | 364 finger->y = y; |
423 } else { | 365 |
424 touch->x += xrel; | 366 /*Should scale to window? Normalize? Maintain Aspect?*/ |
425 touch->y += yrel; | 367 //SDL_GetWindowSize(touch->focus, &x_max, &y_max); |
426 } | |
427 | |
428 SDL_GetWindowSize(touch->focus, &x_max, &y_max); | |
429 | 368 |
430 /* make sure that the pointers find themselves inside the windows */ | 369 /* make sure that the pointers find themselves inside the windows */ |
431 /* only check if touch->xmax is set ! */ | 370 /* only check if touch->xmax is set ! */ |
371 /* | |
432 if (x_max && touch->x > x_max) { | 372 if (x_max && touch->x > x_max) { |
433 touch->x = x_max; | 373 touch->x = x_max; |
434 } else if (touch->x < 0) { | 374 } else if (touch->x < 0) { |
435 touch->x = 0; | 375 touch->x = 0; |
436 } | 376 } |
438 if (y_max && touch->y > y_max) { | 378 if (y_max && touch->y > y_max) { |
439 touch->y = y_max; | 379 touch->y = y_max; |
440 } else if (touch->y < 0) { | 380 } else if (touch->y < 0) { |
441 touch->y = 0; | 381 touch->y = 0; |
442 } | 382 } |
443 | 383 */ |
444 touch->xdelta += xrel; | 384 finger->xdelta += xrel; |
445 touch->ydelta += yrel; | 385 finger->ydelta += yrel; |
446 touch->pressure = pressure; | 386 finger->pressure = pressure; |
447 | 387 |
448 | 388 |
449 | 389 |
450 /* Post the event, if desired */ | 390 /* Post the event, if desired */ |
451 posted = 0; | 391 posted = 0; |
452 if (SDL_GetEventState(SDL_TOUCHMOTION) == SDL_ENABLE && | 392 if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { |
453 touch->proximity == SDL_TRUE) { | |
454 SDL_Event event; | 393 SDL_Event event; |
455 event.motion.type = SDL_TOUCHMOTION; | 394 event.tfinger.type = SDL_FINGERMOTION; |
456 event.motion.which = (Uint8) index; | 395 event.tfinger.which = (Uint8) index; |
457 event.motion.state = touch->buttonstate; | 396 event.tfinger.state = touch->buttonstate; |
458 event.motion.x = touch->x; | 397 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; |
459 event.motion.y = touch->y; | |
460 event.motion.z = touch->z; | |
461 event.motion.pressure = touch->pressure; | |
462 event.motion.pressure_max = touch->pressure_max; | |
463 event.motion.pressure_min = touch->pressure_min; | |
464 event.motion.rotation = 0; | |
465 event.motion.tilt_x = 0; | |
466 event.motion.tilt_y = 0; | |
467 event.motion.cursor = touch->current_end; | |
468 event.motion.xrel = xrel; | |
469 event.motion.yrel = yrel; | |
470 event.motion.windowID = touch->focus ? touch->focus->id : 0; | |
471 posted = (SDL_PushEvent(&event) > 0); | 398 posted = (SDL_PushEvent(&event) > 0); |
472 } | 399 } |
473 touch->last_x = touch->x; | 400 finger->last_x = finger->x; |
474 touch->last_y = touch->y; | 401 finger->last_y = finger->y; |
475 return posted; | 402 return posted; |
476 } | 403 } |
477 | 404 |
478 int | 405 int |
479 SDL_SendTouchButton(int id, Uint8 state, Uint8 button) | 406 SDL_SendTouchButton(int id, Uint8 state, Uint8 button) |
480 { | 407 { |
481 int index = SDL_GetTouchIndexId(id); | 408 SDL_Touch *touch = SDL_GetTouch(id); |
482 SDL_Touch *touch = SDL_GetTouch(index); | |
483 int posted; | 409 int posted; |
484 Uint32 type; | 410 Uint32 type; |
485 | 411 |
486 if (!touch) { | 412 if (!touch) { |
487 return 0; | 413 return 0; |
513 /* Post the event, if desired */ | 439 /* Post the event, if desired */ |
514 posted = 0; | 440 posted = 0; |
515 if (SDL_GetEventState(type) == SDL_ENABLE) { | 441 if (SDL_GetEventState(type) == SDL_ENABLE) { |
516 SDL_Event event; | 442 SDL_Event event; |
517 event.type = type; | 443 event.type = type; |
518 event.button.which = (Uint8) index; | 444 event.tbutton.which = (Uint8) index; |
519 event.button.state = state; | 445 event.tbutton.state = state; |
520 event.button.button = button; | 446 event.tbutton.button = button; |
521 event.button.x = touch->x; | 447 event.tbutton.windowID = touch->focus ? touch->focus->id : 0; |
522 event.button.y = touch->y; | |
523 event.button.windowID = touch->focus ? touch->focus->id : 0; | |
524 posted = (SDL_PushEvent(&event) > 0); | 448 posted = (SDL_PushEvent(&event) > 0); |
525 } | 449 } |
526 return posted; | 450 return posted; |
527 } | 451 } |
528 | 452 |
529 int | |
530 SDL_SendTouchWheel(int index, int x, int y) | |
531 { | |
532 SDL_Touch *touch = SDL_GetTouch(index); | |
533 int posted; | |
534 | |
535 if (!touch || (!x && !y)) { | |
536 return 0; | |
537 } | |
538 | |
539 /* Post the event, if desired */ | |
540 posted = 0; | |
541 if (SDL_GetEventState(SDL_TOUCHWHEEL) == SDL_ENABLE) { | |
542 SDL_Event event; | |
543 event.type = SDL_TOUCHWHEEL; | |
544 event.wheel.which = (Uint8) index; | |
545 event.wheel.x = x; | |
546 event.wheel.y = y; | |
547 event.wheel.windowID = touch->focus ? touch->focus->id : 0; | |
548 posted = (SDL_PushEvent(&event) > 0); | |
549 } | |
550 return posted; | |
551 } | |
552 | |
553 | |
554 char * | 453 char * |
555 SDL_GetTouchName(int index) | 454 SDL_GetTouchName(int id) |
556 { | 455 { |
557 SDL_Touch *touch = SDL_GetTouch(index); | 456 SDL_Touch *touch = SDL_GetTouch(id); |
558 if (!touch) { | 457 if (!touch) { |
559 return NULL; | 458 return NULL; |
560 } | 459 } |
561 return touch->name; | 460 return touch->name; |
562 } | 461 } |
563 | 462 |
564 void | |
565 SDL_ChangeEnd(int id, int end) | |
566 { | |
567 int index = SDL_GetTouchIndexId(id); | |
568 SDL_Touch *touch = SDL_GetTouch(index); | |
569 | |
570 if (touch) { | |
571 touch->current_end = end; | |
572 } | |
573 } | |
574 | |
575 /* vi: set ts=4 sw=4 expandtab: */ | 463 /* vi: set ts=4 sw=4 expandtab: */ |