diff src/events/SDL_gesture.c @ 4665:c2493813a2f4

Merged changes
author Jim Grandpre <jim.tla@gmail.com>
date Fri, 16 Jul 2010 20:53:44 -0400
parents 317a151b79ad 56a2d70de945
children f8431f66613d
line wrap: on
line diff
--- a/src/events/SDL_gesture.c	Fri Jul 16 20:48:43 2010 -0400
+++ b/src/events/SDL_gesture.c	Fri Jul 16 20:53:44 2010 -0400
@@ -110,8 +110,10 @@
   return hash;
 }
 
-int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) {
+
+static int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) {
   if(src == NULL) return 0;
+
   int i;
   
   //No Longer storing the Hash, rehash on load
@@ -123,6 +125,7 @@
     fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y);
   }
   fprintf(fp,"\n");
+
   */
   if(SDL_RWwrite(src,templ->path,sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) return 0;
   return 1;
@@ -150,6 +153,36 @@
       }
     }
   }
+  SDL_SetError("Unknown gestureId");
+  return -1;
+}
+
+//path is an already sampled set of points
+//Returns the index of the gesture on success, or -1
+static int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
+  if(inTouch == NULL) {
+    if(numGestureTouches == 0) return -1;
+    int i = 0;
+    for(i = 0;i < numGestureTouches; i++) {
+      inTouch = &gestureTouch[i];
+      if(inTouch->numDollarTemplates < MAXTEMPLATES) {
+	DollarTemplate *templ = 
+	  &inTouch->dollarTemplate[inTouch->numDollarTemplates];
+	memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
+	templ->hash = SDL_HashDollar(templ->path);
+	inTouch->numDollarTemplates++;
+      }
+    }
+    return inTouch->numDollarTemplates - 1;
+  }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
+    DollarTemplate *templ = 
+      &inTouch->dollarTemplate[inTouch->numDollarTemplates];
+    memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
+    templ->hash = SDL_HashDollar(templ->path);
+    inTouch->numDollarTemplates++;
+    return inTouch->numDollarTemplates - 1;
+  }
+  return -1;
 }
 
 int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) {
@@ -197,37 +230,6 @@
 }
 
 
-//path is an already sampled set of points
-//Returns the index of the gesture on success, or -1
-int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
-  if(inTouch == NULL) {
-    if(numGestureTouches == 0) return -1;
-    int i = 0;
-    for(i = 0;i < numGestureTouches; i++) {
-      inTouch = &gestureTouch[i];
-      if(inTouch->numDollarTemplates < MAXTEMPLATES) {
-	DollarTemplate *templ = 
-	  &inTouch->dollarTemplate[inTouch->numDollarTemplates];
-	memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
-	templ->hash = SDL_HashDollar(templ->path);
-	inTouch->numDollarTemplates++;
-      }
-    }
-    return inTouch->numDollarTemplates - 1;
-  }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
-    DollarTemplate *templ = 
-      &inTouch->dollarTemplate[inTouch->numDollarTemplates];
-    memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
-    templ->hash = SDL_HashDollar(templ->path);
-    inTouch->numDollarTemplates++;
-    return inTouch->numDollarTemplates - 1;
-  }
-  return -1;
-}
-
-
-
-
 float dollarDifference(Point* points,Point* templ,float ang) {
   //  Point p[DOLLARNPOINTS];
   float dist = 0;
@@ -279,21 +281,6 @@
   return SDL_min(f1,f2);  
 }
 
-float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
-
-  Point points[DOLLARNPOINTS];
-  int numPoints = dollarNormalize(path,points);
-  int i;
- 
-  int bestDiff = 10000;
-  *bestTempl = -1;
-  for(i = 0;i < touch->numDollarTemplates;i++) {
-    int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
-    if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
-  }
-  return bestDiff;
-}
-
 //DollarPath contains raw points, plus (possibly) the calculated length
 int dollarNormalize(DollarPath path,Point *points) {
   int i;
@@ -374,6 +361,21 @@
   return numPoints;
 }
 
+float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
+	
+	Point points[DOLLARNPOINTS];
+	int numPoints = dollarNormalize(path,points);
+	int i;
+	
+	int bestDiff = 10000;
+	*bestTempl = -1;
+	for(i = 0;i < touch->numDollarTemplates;i++) {
+		int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
+		if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
+	}
+	return bestDiff;
+}
+
 int SDL_GestureAddTouch(SDL_Touch* touch) { 
   if(numGestureTouches >= MAXTOUCHES) return -1;