test/testgesture.c
changeset 5460 43582fccdc0d
parent 5458 a96fcc853bef
child 5535 96594ac5fd1a
     1.1 --- a/test/testgesture.c	Wed Mar 09 15:09:00 2011 -0800
     1.2 +++ b/test/testgesture.c	Wed Mar 09 15:51:51 2011 -0800
     1.3 @@ -64,7 +64,7 @@
     1.4  
     1.5  void handler (int sig)
     1.6  {
     1.7 -  SDL_Log ("exiting...(%d)\n", sig);
     1.8 +  SDL_Log ("exiting...(%d)", sig);
     1.9    exit (0);
    1.10  }
    1.11  
    1.12 @@ -147,30 +147,28 @@
    1.13  #endif
    1.14  
    1.15    //draw Touch History
    1.16 -  for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) {
    1.17 -    SDL_Event event = events[i&(EVENT_BUF_SIZE-1)];
    1.18 -    int age = eventWrite - i - 1;
    1.19 +  for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
    1.20 +    const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)];
    1.21 +    float age = (float)(i - eventWrite) / EVENT_BUF_SIZE;
    1.22  	float x, y;
    1.23  	unsigned int c, col;
    1.24  
    1.25 -    if(event.type == SDL_FINGERMOTION || 
    1.26 -       event.type == SDL_FINGERDOWN ||
    1.27 -       event.type == SDL_FINGERUP) {
    1.28 -      SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
    1.29 +    if(event->type == SDL_FINGERMOTION || 
    1.30 +       event->type == SDL_FINGERDOWN ||
    1.31 +       event->type == SDL_FINGERUP) {
    1.32 +      SDL_Touch* inTouch = SDL_GetTouch(event->tfinger.touchId);
    1.33        if(inTouch == NULL) continue;
    1.34  
    1.35 -      x = ((float)event.tfinger.x)/inTouch->xres;
    1.36 -      y = ((float)event.tfinger.y)/inTouch->yres;      
    1.37 +      x = ((float)event->tfinger.x)/inTouch->xres;
    1.38 +      y = ((float)event->tfinger.y)/inTouch->yres;      
    1.39        
    1.40        //draw the touch:      
    1.41 -      c = colors[event.tfinger.touchId%7]; 
    1.42 -      col = 
    1.43 -	((unsigned int)(c*(.1+.85))) |
    1.44 -	((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
    1.45 +      c = colors[event->tfinger.fingerId%7]; 
    1.46 +      col = ((unsigned int)(c*(.1+.85))) | (unsigned int)(0xFF*age)<<24;
    1.47  
    1.48 -      if(event.type == SDL_FINGERMOTION)
    1.49 +      if(event->type == SDL_FINGERMOTION)
    1.50  	drawCircle(screen,x*screen->w,y*screen->h,5,col);
    1.51 -      else if(event.type == SDL_FINGERDOWN)
    1.52 +      else if(event->type == SDL_FINGERDOWN)
    1.53  	drawCircle(screen,x*screen->w,y*screen->h,-10,col);     
    1.54      }
    1.55    }
    1.56 @@ -233,12 +231,12 @@
    1.57  		break;
    1.58  	      case SDLK_s:
    1.59  		src = SDL_RWFromFile("gestureSave","w");
    1.60 -		SDL_Log("Wrote %i templates\n",SDL_SaveAllDollarTemplates(src));
    1.61 +		SDL_Log("Wrote %i templates",SDL_SaveAllDollarTemplates(src));
    1.62  		SDL_RWclose(src);
    1.63  		break;
    1.64  	      case SDLK_l:
    1.65  		src = SDL_RWFromFile("gestureSave","r");
    1.66 -		SDL_Log("Loaded: %i\n",SDL_LoadDollarTemplates(-1,src));
    1.67 +		SDL_Log("Loaded: %i",SDL_LoadDollarTemplates(-1,src));
    1.68  		SDL_RWclose(src);
    1.69  		break;
    1.70  	      case SDLK_ESCAPE:
    1.71 @@ -257,7 +255,7 @@
    1.72  	    break;
    1.73  	  case SDL_FINGERMOTION:
    1.74  #if VERBOSE
    1.75 -	    SDL_Log("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
    1.76 +	    SDL_Log("Finger: %i,x: %i, y: %i",event.tfinger.fingerId,
    1.77  	    	   event.tfinger.x,event.tfinger.y);
    1.78  #endif
    1.79  		{
    1.80 @@ -267,24 +265,24 @@
    1.81  	    break;	    
    1.82  	  case SDL_FINGERDOWN:
    1.83  #if VERBOSE
    1.84 -	    SDL_Log("Finger: %"PRIs64" down - x: %i, y: %i\n",
    1.85 +	    SDL_Log("Finger: %"PRIs64" down - x: %i, y: %i",
    1.86  		   event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
    1.87  #endif
    1.88  	    break;
    1.89  	  case SDL_FINGERUP:
    1.90  #if VERBOSE
    1.91 -	    SDL_Log("Finger: %"PRIs64" up - x: %i, y: %i\n",
    1.92 +	    SDL_Log("Finger: %"PRIs64" up - x: %i, y: %i",
    1.93  	    	   event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
    1.94  #endif
    1.95  	    break;
    1.96  	  case SDL_MULTIGESTURE:
    1.97  #if VERBOSE	    
    1.98 -	    SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f\n",
    1.99 +	    SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f",
   1.100  		   event.mgesture.x,
   1.101  		   event.mgesture.y,
   1.102  		   event.mgesture.dTheta,
   1.103  		   event.mgesture.dDist);
   1.104 -	    SDL_Log("MG: numDownTouch = %i\n",event.mgesture.numFingers);
   1.105 +	    SDL_Log("MG: numDownTouch = %i",event.mgesture.numFingers);
   1.106  #endif
   1.107  	    knob.p.x = event.mgesture.x;
   1.108  	    knob.p.y = event.mgesture.y;
   1.109 @@ -292,12 +290,12 @@
   1.110  	    knob.r += event.mgesture.dDist;
   1.111  	    break;
   1.112  	  case SDL_DOLLARGESTURE:
   1.113 -	    SDL_Log("Gesture %"PRIs64" performed, error: %f\n",
   1.114 +	    SDL_Log("Gesture %"PRIs64" performed, error: %f",
   1.115  		   event.dgesture.gestureId,
   1.116  		   event.dgesture.error);
   1.117  	    break;
   1.118  	  case SDL_DOLLARRECORD:
   1.119 -	    SDL_Log("Recorded gesture: %"PRIs64"\n",event.dgesture.gestureId);
   1.120 +	    SDL_Log("Recorded gesture: %"PRIs64"",event.dgesture.gestureId);
   1.121  	    break;
   1.122  	  }
   1.123        }