comparison src/events/SDL_gesture.c @ 4678:f8431f66613d

Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
author jimtla
date Sat, 31 Jul 2010 20:02:54 +0400
parents c2493813a2f4
children 5378f2d0754f
comparison
equal deleted inserted replaced
4677:31607094315c 4678:f8431f66613d
44 44
45 45
46 typedef struct { 46 typedef struct {
47 Point p; 47 Point p;
48 float pressure; 48 float pressure;
49 int id; 49 SDL_FingerID id;
50 } Finger; 50 } Finger;
51 51
52 52
53 typedef struct { 53 typedef struct {
54 float length; 54 float length;
69 Point path[DOLLARNPOINTS]; 69 Point path[DOLLARNPOINTS];
70 unsigned long hash; 70 unsigned long hash;
71 } DollarTemplate; 71 } DollarTemplate;
72 72
73 typedef struct { 73 typedef struct {
74 int id; 74 SDL_GestureID id;
75 Point res; 75 Point res;
76 Point centroid; 76 Point centroid;
77 TouchPoint gestureLast[MAXFINGERS]; 77 TouchPoint gestureLast[MAXFINGERS];
78 int numDownFingers; 78 int numDownFingers;
79 79
85 85
86 GestureTouch gestureTouch[MAXTOUCHES]; 86 GestureTouch gestureTouch[MAXTOUCHES];
87 int numGestureTouches = 0; 87 int numGestureTouches = 0;
88 SDL_bool recordAll; 88 SDL_bool recordAll;
89 89
90 int SDL_RecordGesture(int touchId) { 90 int SDL_RecordGesture(SDL_TouchID touchId) {
91 int i; 91 int i;
92 if(touchId < 0) recordAll = SDL_TRUE; 92 if(touchId < 0) recordAll = SDL_TRUE;
93 for(i = 0;i < numGestureTouches; i++) { 93 for(i = 0;i < numGestureTouches; i++) {
94 if((touchId < 0) || (gestureTouch[i].id == touchId)) { 94 if((touchId < 0) || (gestureTouch[i].id == touchId)) {
95 gestureTouch[i].recording = SDL_TRUE; 95 gestureTouch[i].recording = SDL_TRUE;
141 } 141 }
142 } 142 }
143 return rtrn; 143 return rtrn;
144 } 144 }
145 145
146 int SDL_SaveDollarTemplate(unsigned long gestureId, SDL_RWops *src) { 146 int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) {
147 int i,j; 147 int i,j;
148 for(i = 0; i < numGestureTouches; i++) { 148 for(i = 0; i < numGestureTouches; i++) {
149 GestureTouch* touch = &gestureTouch[i]; 149 GestureTouch* touch = &gestureTouch[i];
150 for(j = 0;j < touch->numDollarTemplates; j++) { 150 for(j = 0;j < touch->numDollarTemplates; j++) {
151 if(touch->dollarTemplate[i].hash == gestureId) { 151 if(touch->dollarTemplate[i].hash == gestureId) {
183 return inTouch->numDollarTemplates - 1; 183 return inTouch->numDollarTemplates - 1;
184 } 184 }
185 return -1; 185 return -1;
186 } 186 }
187 187
188 int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) { 188 int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) {
189 if(src == NULL) return 0; 189 if(src == NULL) return 0;
190 int i,loaded = 0; 190 int i,loaded = 0;
191 GestureTouch *touch = NULL; 191 GestureTouch *touch = NULL;
192 if(touchId >= 0) { 192 if(touchId >= 0) {
193 for(i = 0;i < numGestureTouches; i++) 193 for(i = 0;i < numGestureTouches; i++)
392 392
393 numGestureTouches++; 393 numGestureTouches++;
394 return 0; 394 return 0;
395 } 395 }
396 396
397 GestureTouch * SDL_GetGestureTouch(int id) { 397 GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) {
398 int i; 398 int i;
399 for(i = 0;i < numGestureTouches; i++) { 399 for(i = 0;i < numGestureTouches; i++) {
400 //printf("%i ?= %i\n",gestureTouch[i].id,id); 400 //printf("%i ?= %i\n",gestureTouch[i].id,id);
401 if(gestureTouch[i].id == id) return &gestureTouch[i]; 401 if(gestureTouch[i].id == id) return &gestureTouch[i];
402 } 402 }
412 event.mgesture.dTheta = dTheta; 412 event.mgesture.dTheta = dTheta;
413 event.mgesture.dDist = dDist; 413 event.mgesture.dDist = dDist;
414 return SDL_PushEvent(&event) > 0; 414 return SDL_PushEvent(&event) > 0;
415 } 415 }
416 416
417 int SDL_SendGestureDollar(GestureTouch* touch,int gestureId,float error) { 417 int SDL_SendGestureDollar(GestureTouch* touch,
418 SDL_GestureID gestureId,float error) {
418 SDL_Event event; 419 SDL_Event event;
419 event.dgesture.type = SDL_DOLLARGESTURE; 420 event.dgesture.type = SDL_DOLLARGESTURE;
420 event.dgesture.touchId = touch->id; 421 event.dgesture.touchId = touch->id;
421 /* 422 /*
422 //TODO: Add this to give location of gesture? 423 //TODO: Add this to give location of gesture?
427 event.dgesture.error = error; 428 event.dgesture.error = error;
428 return SDL_PushEvent(&event) > 0; 429 return SDL_PushEvent(&event) > 0;
429 } 430 }
430 431
431 432
432 int SDL_SendDollarRecord(GestureTouch* touch,int gestureId) { 433 int SDL_SendDollarRecord(GestureTouch* touch,SDL_GestureID gestureId) {
433 SDL_Event event; 434 SDL_Event event;
434 event.dgesture.type = SDL_DOLLARRECORD; 435 event.dgesture.type = SDL_DOLLARRECORD;
435 event.dgesture.touchId = touch->id; 436 event.dgesture.touchId = touch->id;
436 event.dgesture.gestureId = gestureId; 437 event.dgesture.gestureId = gestureId;
437 438
487 float error; 488 float error;
488 error = dollarRecognize(inTouch->gestureLast[j].dollarPath, 489 error = dollarRecognize(inTouch->gestureLast[j].dollarPath,
489 &bestTempl,inTouch); 490 &bestTempl,inTouch);
490 if(bestTempl >= 0){ 491 if(bestTempl >= 0){
491 //Send Event 492 //Send Event
492 int gestureId = inTouch->dollarTemplate[bestTempl].hash; 493 unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
493 SDL_SendGestureDollar(inTouch,gestureId,error); 494 SDL_SendGestureDollar(inTouch,gestureId,error);
494 printf("Dollar error: %f\n",error); 495 printf("Dollar error: %f\n",error);
495 } 496 }
496 } 497 }
497 inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; 498 inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];