Mercurial > sdl-ios-xcode
comparison src/events/SDL_touch.c @ 4676:99b4560b7aa1
Upgraded touchId/fingerId to long. Changed position variables to floats.
author | jimtla |
---|---|
date | Fri, 30 Jul 2010 23:18:35 +0400 |
parents | 89d5e2201b00 |
children | f8431f66613d |
comparison
equal
deleted
inserted
replaced
4675:641c13b0ce5f | 4676:99b4560b7aa1 |
---|---|
40 { | 40 { |
41 return (0); | 41 return (0); |
42 } | 42 } |
43 | 43 |
44 SDL_Touch * | 44 SDL_Touch * |
45 SDL_GetTouch(int id) | 45 SDL_GetTouch(long id) |
46 { | 46 { |
47 int index = SDL_GetTouchIndexId(id); | 47 int index = SDL_GetTouchIndexId(id); |
48 if (index < 0 || index >= SDL_num_touch) { | 48 if (index < 0 || index >= SDL_num_touch) { |
49 return NULL; | 49 return NULL; |
50 } | 50 } |
59 } | 59 } |
60 return SDL_touchPads[index]; | 60 return SDL_touchPads[index]; |
61 } | 61 } |
62 | 62 |
63 int | 63 int |
64 SDL_GetFingerIndexId(SDL_Touch* touch,int fingerid) | 64 SDL_GetFingerIndexId(SDL_Touch* touch,long fingerid) |
65 { | 65 { |
66 int i; | 66 int i; |
67 for(i = 0;i < touch->num_fingers;i++) | 67 for(i = 0;i < touch->num_fingers;i++) |
68 if(touch->fingers[i]->id == fingerid) | 68 if(touch->fingers[i]->id == fingerid) |
69 return i; | 69 return i; |
70 return -1; | 70 return -1; |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 SDL_Finger * | 74 SDL_Finger * |
75 SDL_GetFinger(SDL_Touch* touch,int id) | 75 SDL_GetFinger(SDL_Touch* touch,long id) |
76 { | 76 { |
77 int index = SDL_GetFingerIndexId(touch,id); | 77 int index = SDL_GetFingerIndexId(touch,id); |
78 if(index < 0 || index >= touch->num_fingers) | 78 if(index < 0 || index >= touch->num_fingers) |
79 return NULL; | 79 return NULL; |
80 return touch->fingers[index]; | 80 return touch->fingers[index]; |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 int | 84 int |
85 SDL_GetTouchIndexId(int id) | 85 SDL_GetTouchIndexId(long id) |
86 { | 86 { |
87 int index; | 87 int index; |
88 SDL_Touch *touch; | 88 SDL_Touch *touch; |
89 | 89 |
90 for (index = 0; index < SDL_num_touch; ++index) { | 90 for (index = 0; index < SDL_num_touch; ++index) { |
144 | 144 |
145 return index; | 145 return index; |
146 } | 146 } |
147 | 147 |
148 void | 148 void |
149 SDL_DelTouch(int id) | 149 SDL_DelTouch(long id) |
150 { | 150 { |
151 int index = SDL_GetTouchIndexId(id); | 151 int index = SDL_GetTouchIndexId(id); |
152 SDL_Touch *touch = SDL_GetTouch(id); | 152 SDL_Touch *touch = SDL_GetTouch(id); |
153 | 153 |
154 if (!touch) { | 154 if (!touch) { |
187 SDL_GetNumTouch(void) | 187 SDL_GetNumTouch(void) |
188 { | 188 { |
189 return SDL_num_touch; | 189 return SDL_num_touch; |
190 } | 190 } |
191 SDL_Window * | 191 SDL_Window * |
192 SDL_GetTouchFocusWindow(int id) | 192 SDL_GetTouchFocusWindow(long id) |
193 { | 193 { |
194 SDL_Touch *touch = SDL_GetTouch(id); | 194 SDL_Touch *touch = SDL_GetTouch(id); |
195 | 195 |
196 if (!touch) { | 196 if (!touch) { |
197 return 0; | 197 return 0; |
198 } | 198 } |
199 return touch->focus; | 199 return touch->focus; |
200 } | 200 } |
201 | 201 |
202 void | 202 void |
203 SDL_SetTouchFocus(int id, SDL_Window * window) | 203 SDL_SetTouchFocus(long id, SDL_Window * window) |
204 { | 204 { |
205 int index = SDL_GetTouchIndexId(id); | 205 int index = SDL_GetTouchIndexId(id); |
206 SDL_Touch *touch = SDL_GetTouch(id); | 206 SDL_Touch *touch = SDL_GetTouch(id); |
207 int i; | 207 int i; |
208 SDL_bool focus; | 208 SDL_bool focus; |
248 } | 248 } |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 int | 252 int |
253 SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger) | 253 SDL_AddFinger(SDL_Touch* touch,SDL_Finger finger) |
254 { | 254 { |
255 int index; | 255 int index; |
256 SDL_Finger **fingers; | 256 SDL_Finger **fingers; |
257 //printf("Adding Finger...\n"); | 257 //printf("Adding Finger...\n"); |
258 if (SDL_GetFingerIndexId(touch,finger->id) != -1) { | 258 if (SDL_GetFingerIndexId(touch,finger.id) != -1) { |
259 SDL_SetError("Finger ID already in use"); | 259 SDL_SetError("Finger ID already in use"); |
260 } | 260 } |
261 | 261 |
262 /* Add the touch to the list of touch */ | 262 /* Add the touch to the list of touch */ |
263 if(touch->num_fingers >= touch->max_fingers){ | 263 if(touch->num_fingers >= touch->max_fingers){ |
280 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger)); | 280 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger)); |
281 if (!touch->fingers[index]) { | 281 if (!touch->fingers[index]) { |
282 SDL_OutOfMemory(); | 282 SDL_OutOfMemory(); |
283 return -1; | 283 return -1; |
284 } | 284 } |
285 *(touch->fingers[index]) = *finger; | 285 *(touch->fingers[index]) = finger; |
286 touch->num_fingers++; | 286 touch->num_fingers++; |
287 | 287 |
288 return index; | 288 return index; |
289 } | 289 } |
290 | 290 |
291 int | 291 int |
292 SDL_DelFinger(SDL_Touch* touch,int fingerid) | 292 SDL_DelFinger(SDL_Touch* touch,long fingerid) |
293 { | 293 { |
294 int index = SDL_GetFingerIndexId(touch,fingerid); | 294 int index = SDL_GetFingerIndexId(touch,fingerid); |
295 SDL_Finger* finger = SDL_GetFinger(touch,fingerid); | 295 SDL_Finger* finger = SDL_GetFinger(touch,fingerid); |
296 | 296 |
297 if (!finger) { | 297 if (!finger) { |
305 return 0; | 305 return 0; |
306 } | 306 } |
307 | 307 |
308 | 308 |
309 int | 309 int |
310 SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure) | 310 SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, float pressure) |
311 { | 311 { |
312 int posted; | 312 int posted; |
313 SDL_Touch* touch = SDL_GetTouch(id); | 313 SDL_Touch* touch = SDL_GetTouch(id); |
314 | 314 |
315 if(!touch) { | 315 if(!touch) { |
328 nf.ydelta = 0; | 328 nf.ydelta = 0; |
329 nf.last_x = x; | 329 nf.last_x = x; |
330 nf.last_y = y; | 330 nf.last_y = y; |
331 nf.last_pressure = pressure; | 331 nf.last_pressure = pressure; |
332 nf.down = SDL_FALSE; | 332 nf.down = SDL_FALSE; |
333 SDL_AddFinger(touch,&nf); | 333 SDL_AddFinger(touch,nf); |
334 finger = &nf; | 334 finger = &nf; |
335 } | 335 } |
336 else if(finger->down) return 0; | 336 else if(finger->down) return 0; |
337 if(x < 0 || y < 0) return 0; //should defer if only a partial input | 337 if(x < 0 || y < 0) return 0; //should defer if only a partial input |
338 posted = 0; | 338 posted = 0; |
339 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { | 339 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { |
340 SDL_Event event; | 340 SDL_Event event; |
341 event.tfinger.type = SDL_FINGERDOWN; | 341 event.tfinger.type = SDL_FINGERDOWN; |
342 event.tfinger.touchId = (Uint8) id; | 342 event.tfinger.touchId = id; |
343 event.tfinger.x = x; | 343 event.tfinger.x = x; |
344 event.tfinger.y = y; | 344 event.tfinger.y = y; |
345 event.tfinger.state = touch->buttonstate; | 345 event.tfinger.state = touch->buttonstate; |
346 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; | 346 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; |
347 event.tfinger.fingerId = fingerid; | 347 event.tfinger.fingerId = fingerid; |
354 if(SDL_DelFinger(touch,fingerid) < 0) return 0; | 354 if(SDL_DelFinger(touch,fingerid) < 0) return 0; |
355 posted = 0; | 355 posted = 0; |
356 if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { | 356 if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { |
357 SDL_Event event; | 357 SDL_Event event; |
358 event.tfinger.type = SDL_FINGERUP; | 358 event.tfinger.type = SDL_FINGERUP; |
359 event.tfinger.touchId = (Uint8) id; | 359 event.tfinger.touchId = id; |
360 event.tfinger.state = touch->buttonstate; | 360 event.tfinger.state = touch->buttonstate; |
361 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; | 361 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; |
362 event.tfinger.fingerId = fingerid; | 362 event.tfinger.fingerId = fingerid; |
363 posted = (SDL_PushEvent(&event) > 0); | 363 posted = (SDL_PushEvent(&event) > 0); |
364 } | 364 } |
365 return posted; | 365 return posted; |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 int | 369 int |
370 SDL_SendTouchMotion(int id, int fingerid, int relative, | 370 SDL_SendTouchMotion(long id, long fingerid, int relative, |
371 int x, int y, int pressure) | 371 float x, float y, float pressure) |
372 { | 372 { |
373 int index = SDL_GetTouchIndexId(id); | 373 int index = SDL_GetTouchIndexId(id); |
374 SDL_Touch *touch = SDL_GetTouch(id); | 374 SDL_Touch *touch = SDL_GetTouch(id); |
375 SDL_Finger *finger = SDL_GetFinger(touch,fingerid); | 375 SDL_Finger *finger = SDL_GetFinger(touch,fingerid); |
376 int posted; | 376 int posted; |
377 int xrel; | 377 float xrel; |
378 int yrel; | 378 float yrel; |
379 int x_max = 0, y_max = 0; | 379 float x_max = 0, y_max = 0; |
380 | 380 |
381 if (!touch) { | 381 if (!touch) { |
382 return SDL_TouchNotFoundError(id); | 382 return SDL_TouchNotFoundError(id); |
383 } | 383 } |
384 if(touch->flush_motion) { | 384 if(touch->flush_motion) { |
442 /* Post the event, if desired */ | 442 /* Post the event, if desired */ |
443 posted = 0; | 443 posted = 0; |
444 if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { | 444 if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { |
445 SDL_Event event; | 445 SDL_Event event; |
446 event.tfinger.type = SDL_FINGERMOTION; | 446 event.tfinger.type = SDL_FINGERMOTION; |
447 event.tfinger.touchId = (Uint8) id; | 447 event.tfinger.touchId = id; |
448 event.tfinger.fingerId = (Uint8) fingerid; | 448 event.tfinger.fingerId = fingerid; |
449 event.tfinger.x = x; | 449 event.tfinger.x = x; |
450 event.tfinger.y = y; | 450 event.tfinger.y = y; |
451 event.tfinger.pressure = pressure; | 451 event.tfinger.pressure = pressure; |
452 event.tfinger.state = touch->buttonstate; | 452 event.tfinger.state = touch->buttonstate; |
453 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; | 453 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; |
458 finger->last_pressure = finger->pressure; | 458 finger->last_pressure = finger->pressure; |
459 return posted; | 459 return posted; |
460 } | 460 } |
461 } | 461 } |
462 int | 462 int |
463 SDL_SendTouchButton(int id, Uint8 state, Uint8 button) | 463 SDL_SendTouchButton(long id, Uint8 state, Uint8 button) |
464 { | 464 { |
465 SDL_Touch *touch = SDL_GetTouch(id); | 465 SDL_Touch *touch = SDL_GetTouch(id); |
466 int posted; | 466 int posted; |
467 Uint32 type; | 467 Uint32 type; |
468 | 468 |
497 /* Post the event, if desired */ | 497 /* Post the event, if desired */ |
498 posted = 0; | 498 posted = 0; |
499 if (SDL_GetEventState(type) == SDL_ENABLE) { | 499 if (SDL_GetEventState(type) == SDL_ENABLE) { |
500 SDL_Event event; | 500 SDL_Event event; |
501 event.type = type; | 501 event.type = type; |
502 event.tbutton.touchId = (Uint8) touch->id; | 502 event.tbutton.touchId = touch->id; |
503 event.tbutton.state = state; | 503 event.tbutton.state = state; |
504 event.tbutton.button = button; | 504 event.tbutton.button = button; |
505 event.tbutton.windowID = touch->focus ? touch->focus->id : 0; | 505 event.tbutton.windowID = touch->focus ? touch->focus->id : 0; |
506 posted = (SDL_PushEvent(&event) > 0); | 506 posted = (SDL_PushEvent(&event) > 0); |
507 } | 507 } |
508 return posted; | 508 return posted; |
509 } | 509 } |
510 | 510 |
511 char * | 511 char * |
512 SDL_GetTouchName(int id) | 512 SDL_GetTouchName(long id) |
513 { | 513 { |
514 SDL_Touch *touch = SDL_GetTouch(id); | 514 SDL_Touch *touch = SDL_GetTouch(id); |
515 if (!touch) { | 515 if (!touch) { |
516 return NULL; | 516 return NULL; |
517 } | 517 } |
518 return touch->name; | 518 return touch->name; |
519 } | 519 } |
520 | 520 |
521 int SDL_TouchNotFoundError(int id) { | 521 int SDL_TouchNotFoundError(long id) { |
522 printf("ERROR: Cannot send touch on non-existent device with id: %i make sure SDL_AddTouch has been called\n",id); | 522 printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); |
523 printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); | 523 printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); |
524 int i; | 524 int i; |
525 for(i=0;i < SDL_num_touch;i++) { | 525 for(i=0;i < SDL_num_touch;i++) { |
526 printf("ERROR: %i\n",SDL_touchPads[i]->id); | 526 printf("ERROR: %li\n",SDL_touchPads[i]->id); |
527 } | 527 } |
528 return 0; | 528 return 0; |
529 } | 529 } |
530 /* vi: set ts=4 sw=4 expandtab: */ | 530 /* vi: set ts=4 sw=4 expandtab: */ |