comparison src/events/SDL_touch.c @ 4648:0350b634c044

Fixed windo build errors. Should now be compilable.
author jimtla
date Thu, 03 Jun 2010 13:21:35 -0400
parents eea1bf53effa
children 7dbcd71216df
comparison
equal deleted inserted replaced
4647:be2250bb482b 4648:0350b634c044
24 /* General touch handling code for SDL */ 24 /* General touch handling code for SDL */
25 25
26 #include "SDL_events.h" 26 #include "SDL_events.h"
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
30 #include <stdio.h>
29 31
30 32
31 static int SDL_num_touch = 0; 33 static int SDL_num_touch = 0;
32 static SDL_Touch **SDL_touchPads = NULL; 34 static SDL_Touch **SDL_touchPads = NULL;
33 35
97 99
98 int 100 int
99 SDL_AddTouch(const SDL_Touch * touch, char *name) 101 SDL_AddTouch(const SDL_Touch * touch, char *name)
100 { 102 {
101 SDL_Touch **touchPads; 103 SDL_Touch **touchPads;
102 int selected_touch; 104 int index,length;
103 int index;
104 size_t length;
105 105
106 if (SDL_GetTouchIndexId(touch->id) != -1) { 106 if (SDL_GetTouchIndexId(touch->id) != -1) {
107 SDL_SetError("Touch ID already in use"); 107 SDL_SetError("Touch ID already in use");
108 } 108 }
109 109
250 int 250 int
251 SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger) 251 SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
252 { 252 {
253 int index; 253 int index;
254 SDL_Finger **fingers; 254 SDL_Finger **fingers;
255 size_t length;
256 //printf("Adding Finger...\n"); 255 //printf("Adding Finger...\n");
257 if (SDL_GetFingerIndexId(touch,finger->id) != -1) { 256 if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
258 SDL_SetError("Finger ID already in use"); 257 SDL_SetError("Finger ID already in use");
259 } 258 }
260 259
261 /* Add the touch to the list of touch */ 260 /* Add the touch to the list of touch */
262 if(touch->num_fingers >= touch->max_fingers){ 261 if(touch->num_fingers >= touch->max_fingers){
263 printf("Making room for it!\n"); 262 //printf("Making room for it!\n");
264 fingers = (SDL_Finger **) SDL_realloc(touch->fingers, 263 fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
265 (touch->num_fingers + 1) * sizeof(SDL_Finger *)); 264 (touch->num_fingers + 1) * sizeof(SDL_Finger *));
266 touch->max_fingers = touch->num_fingers+1; 265 touch->max_fingers = touch->num_fingers+1;
267 if (!fingers) { 266 if (!fingers) {
268 SDL_OutOfMemory(); 267 SDL_OutOfMemory();
269 return -1; 268 return -1;
270 } 269 } else {
271 else { 270 touch->max_fingers = touch->num_fingers+1;
272 touch->max_fingers = touch->num_fingers+1; 271 touch->fingers = fingers;
273 touch->fingers = fingers; 272 }
274 } 273 }
275 }
276 274
277 index = touch->num_fingers; 275 index = touch->num_fingers;
278 //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index); 276 //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
279 277
280 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger)); 278 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
293 { 291 {
294 int index = SDL_GetFingerIndexId(touch,fingerid); 292 int index = SDL_GetFingerIndexId(touch,fingerid);
295 SDL_Finger* finger = SDL_GetFinger(touch,fingerid); 293 SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
296 294
297 if (!finger) { 295 if (!finger) {
298 return; 296 return -1;
299 } 297 }
300 298
301 299
302 SDL_free(finger); 300 SDL_free(finger);
303 touch->num_fingers--; 301 touch->num_fingers--;
304 touch->fingers[index] = touch->fingers[touch->num_fingers]; 302 touch->fingers[index] = touch->fingers[touch->num_fingers];
303 return 0;
305 } 304 }
306 305
307 306
308 int 307 int
309 SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure) 308 SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
368 367
369 if (!touch || touch->flush_motion) { 368 if (!touch || touch->flush_motion) {
370 return 0; 369 return 0;
371 } 370 }
372 371
373 if(finger == NULL) 372 if(finger == NULL) {
374 SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure); 373 SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);
375 else { 374 return 0;
376 /* the relative motion is calculated regarding the last position */
377 if (relative) {
378 xrel = x;
379 yrel = y;
380 x = (finger->last_x + x);
381 y = (finger->last_y + y);
382 } else { 375 } else {
383 if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/ 376 /* the relative motion is calculated regarding the last position */
384 if(y < 0) y = finger->last_y; /*The other is marked as -1*/ 377 if (relative) {
385 if(pressure < 0) pressure = finger->last_pressure; 378 xrel = x;
386 xrel = x - finger->last_x; 379 yrel = y;
387 yrel = y - finger->last_y; 380 x = (finger->last_x + x);
381 y = (finger->last_y + y);
382 } else {
383 if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
384 if(y < 0) y = finger->last_y; /*The other is marked as -1*/
385 if(pressure < 0) pressure = finger->last_pressure;
386 xrel = x - finger->last_x;
387 yrel = y - finger->last_y;
388 }
389
390 /* Drop events that don't change state */
391 if (!xrel && !yrel) {
392 #if 0
393 printf("Touch event didn't change state - dropped!\n");
394 #endif
395 return 0;
396 }
397
398 /* Update internal touch coordinates */
399
400 finger->x = x;
401 finger->y = y;
402
403 /*Should scale to window? Normalize? Maintain Aspect?*/
404 //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
405
406 /* make sure that the pointers find themselves inside the windows */
407 /* only check if touch->xmax is set ! */
408 /*
409 if (x_max && touch->x > x_max) {
410 touch->x = x_max;
411 } else if (touch->x < 0) {
412 touch->x = 0;
413 }
414
415 if (y_max && touch->y > y_max) {
416 touch->y = y_max;
417 } else if (touch->y < 0) {
418 touch->y = 0;
419 }
420 */
421 finger->xdelta = xrel;
422 finger->ydelta = yrel;
423 finger->pressure = pressure;
424
425
426
427 /* Post the event, if desired */
428 posted = 0;
429 if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
430 SDL_Event event;
431 event.tfinger.type = SDL_FINGERMOTION;
432 event.tfinger.touchId = (Uint8) id;
433 event.tfinger.fingerId = (Uint8) fingerid;
434 event.tfinger.x = x;
435 event.tfinger.y = y;
436 event.tfinger.pressure = pressure;
437 event.tfinger.state = touch->buttonstate;
438 event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
439 posted = (SDL_PushEvent(&event) > 0);
440 }
441 finger->last_x = finger->x;
442 finger->last_y = finger->y;
443 finger->last_pressure = finger->pressure;
444 return posted;
388 } 445 }
389
390 /* Drop events that don't change state */
391 if (!xrel && !yrel) {
392 #if 0
393 printf("Touch event didn't change state - dropped!\n");
394 #endif
395 return 0;
396 }
397
398 /* Update internal touch coordinates */
399
400 finger->x = x;
401 finger->y = y;
402
403 /*Should scale to window? Normalize? Maintain Aspect?*/
404 //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
405
406 /* make sure that the pointers find themselves inside the windows */
407 /* only check if touch->xmax is set ! */
408 /*
409 if (x_max && touch->x > x_max) {
410 touch->x = x_max;
411 } else if (touch->x < 0) {
412 touch->x = 0;
413 }
414
415 if (y_max && touch->y > y_max) {
416 touch->y = y_max;
417 } else if (touch->y < 0) {
418 touch->y = 0;
419 }
420 */
421 finger->xdelta = xrel;
422 finger->ydelta = yrel;
423 finger->pressure = pressure;
424
425
426
427 /* Post the event, if desired */
428 posted = 0;
429 if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
430 SDL_Event event;
431 event.tfinger.type = SDL_FINGERMOTION;
432 event.tfinger.touchId = (Uint8) id;
433 event.tfinger.fingerId = (Uint8) fingerid;
434 event.tfinger.x = x;
435 event.tfinger.y = y;
436 event.tfinger.pressure = pressure;
437 event.tfinger.state = touch->buttonstate;
438 event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
439 posted = (SDL_PushEvent(&event) > 0);
440 }
441 finger->last_x = finger->x;
442 finger->last_y = finger->y;
443 finger->last_pressure = finger->pressure;
444 return posted;
445 }
446 } 446 }
447 int 447 int
448 SDL_SendTouchButton(int id, Uint8 state, Uint8 button) 448 SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
449 { 449 {
450 SDL_Touch *touch = SDL_GetTouch(id); 450 SDL_Touch *touch = SDL_GetTouch(id);
481 /* Post the event, if desired */ 481 /* Post the event, if desired */
482 posted = 0; 482 posted = 0;
483 if (SDL_GetEventState(type) == SDL_ENABLE) { 483 if (SDL_GetEventState(type) == SDL_ENABLE) {
484 SDL_Event event; 484 SDL_Event event;
485 event.type = type; 485 event.type = type;
486 event.tbutton.touchId = (Uint8) index; 486 event.tbutton.touchId = (Uint8) touch->id;
487 event.tbutton.state = state; 487 event.tbutton.state = state;
488 event.tbutton.button = button; 488 event.tbutton.button = button;
489 event.tbutton.windowID = touch->focus ? touch->focus->id : 0; 489 event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
490 posted = (SDL_PushEvent(&event) > 0); 490 posted = (SDL_PushEvent(&event) > 0);
491 } 491 }