src/events/SDL_gesture.c
changeset 4664 317a151b79ad
parent 4659 063b9455bd1a
child 4665 c2493813a2f4
     1.1 --- a/src/events/SDL_gesture.c	Tue Jul 13 18:31:09 2010 -0400
     1.2 +++ b/src/events/SDL_gesture.c	Fri Jul 16 20:48:43 2010 -0400
     1.3 @@ -110,40 +110,50 @@
     1.4    return hash;
     1.5  }
     1.6  
     1.7 -int SaveTemplate(DollarTemplate *templ, FILE *fp) {
     1.8 +int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) {
     1.9 +  if(src == NULL) return 0;
    1.10    int i;
    1.11 -  fprintf(fp,"%lu ",templ->hash);
    1.12 +  
    1.13 +  //No Longer storing the Hash, rehash on load
    1.14 +  //fprintf(fp,"%lu ",templ->hash);
    1.15 +  //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
    1.16 +  
    1.17 +  /*
    1.18    for(i = 0;i < DOLLARNPOINTS;i++) {
    1.19      fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y);
    1.20    }
    1.21    fprintf(fp,"\n");
    1.22 +  */
    1.23 +  if(SDL_RWwrite(src,templ->path,sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) return 0;
    1.24 +  return 1;
    1.25  }
    1.26  
    1.27  
    1.28 -int SDL_SaveAllDollarTemplates(FILE *fp) {  
    1.29 +int SDL_SaveAllDollarTemplates(SDL_RWops *src) {  
    1.30    int i,j,rtrn = 0;
    1.31    for(i = 0; i < numGestureTouches; i++) {
    1.32      GestureTouch* touch = &gestureTouch[i];
    1.33      for(j = 0;j < touch->numDollarTemplates; j++) {
    1.34 -	rtrn += SaveTemplate(&touch->dollarTemplate[i],fp);
    1.35 +	rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
    1.36      }
    1.37    }
    1.38    return rtrn;  
    1.39  }
    1.40  
    1.41 -int SDL_SaveDollarTemplate(unsigned long gestureId, FILE *fp) {
    1.42 +int SDL_SaveDollarTemplate(unsigned long gestureId, SDL_RWops *src) {
    1.43    int i,j;
    1.44    for(i = 0; i < numGestureTouches; i++) {
    1.45      GestureTouch* touch = &gestureTouch[i];
    1.46      for(j = 0;j < touch->numDollarTemplates; j++) {
    1.47        if(touch->dollarTemplate[i].hash == gestureId) {
    1.48 -	return SaveTemplate(&touch->dollarTemplate[i],fp);
    1.49 +	return SaveTemplate(&touch->dollarTemplate[i],src);
    1.50        }
    1.51      }
    1.52    }
    1.53  }
    1.54  
    1.55 -int SDL_LoadDollarTemplates(int touchId, FILE *fp) {
    1.56 +int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) {
    1.57 +  if(src == NULL) return 0;
    1.58    int i,loaded = 0;
    1.59    GestureTouch *touch = NULL;
    1.60    if(touchId >= 0) {
    1.61 @@ -153,9 +163,10 @@
    1.62      if(touch == NULL) return -1;
    1.63    }
    1.64  
    1.65 -  while(!feof(fp)) {
    1.66 +  while(1) {
    1.67      DollarTemplate templ;
    1.68 -    fscanf(fp,"%lu ",&templ.hash);
    1.69 +    //fscanf(fp,"%lu ",&templ.hash);
    1.70 +    /*
    1.71      for(i = 0;i < DOLLARNPOINTS; i++) {		
    1.72        int x,y;
    1.73        if(fscanf(fp,"%i %i ",&x,&y) != 2) break;
    1.74 @@ -163,22 +174,26 @@
    1.75        templ.path[i].y = y;
    1.76      }
    1.77      fscanf(fp,"\n");
    1.78 +    */
    1.79 +    if(SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) < DOLLARNPOINTS) break;
    1.80  
    1.81      if(touchId >= 0) {
    1.82 -      if(SDL_AddDollarGesture(touch,templ)) loaded++;
    1.83 +      printf("Adding loaded gesture to 1 touch\n");
    1.84 +      if(SDL_AddDollarGesture(touch,templ.path)) loaded++;
    1.85      }
    1.86      else {
    1.87 +      printf("Adding to: %i touches\n",numGestureTouches);
    1.88        for(i = 0;i < numGestureTouches; i++) {
    1.89 -	if(gestureTouch[i].id == touchId) {
    1.90 -	  touch = &gestureTouch[i];
    1.91 -	  SDL_AddDollarGesture(touch,templ);
    1.92 -	}
    1.93 +	touch = &gestureTouch[i];
    1.94 +	printf("Adding loaded gesture to + touches\n");
    1.95 +	//TODO: What if this fails?
    1.96 +	SDL_AddDollarGesture(touch,templ.path);	
    1.97        }
    1.98        loaded++;
    1.99      }
   1.100    }
   1.101  
   1.102 -  return 1; 
   1.103 +  return loaded; 
   1.104  }
   1.105  
   1.106