test/testgesture.c
changeset 7678 286c42d7c5ed
parent 7677 871d43c6968a
child 7900 cc2289c332eb
equal deleted inserted replaced
7677:871d43c6968a 7678:286c42d7c5ed
    47 #define WIDTH 640
    47 #define WIDTH 640
    48 #define HEIGHT 480
    48 #define HEIGHT 480
    49 #define BPP 4
    49 #define BPP 4
    50 #define DEPTH 32
    50 #define DEPTH 32
    51 
    51 
    52 /*MUST BE A POWER OF 2! */
    52 /* MUST BE A POWER OF 2! */
    53 #define EVENT_BUF_SIZE 256
    53 #define EVENT_BUF_SIZE 256
    54 
    54 
    55 
    55 
    56 #define VERBOSE 0
    56 #define VERBOSE 0
    57 
    57 
   100   pixmem32 = (Uint32*) screen->pixels  + y*screen->pitch/BPP + x;
   100   pixmem32 = (Uint32*) screen->pixels  + y*screen->pitch/BPP + x;
   101 
   101 
   102   SDL_memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
   102   SDL_memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
   103 
   103 
   104   SDL_GetRGB(colour,screen->format,&r,&g,&b);
   104   SDL_GetRGB(colour,screen->format,&r,&g,&b);
   105   /*r = 0;g = 0; b = 0; */
   105   /* r = 0;g = 0; b = 0; */
   106   a = (float)((col>>24)&0xFF);
   106   a = (float)((col>>24)&0xFF);
   107   if(a == 0) a = 0xFF; /*Hack, to make things easier. */
   107   if(a == 0) a = 0xFF; /* Hack, to make things easier. */
   108   a /= 0xFF;
   108   a /= 0xFF;
   109   r = (Uint8)(r*(1-a) + ((col>>16)&0xFF)*(a));
   109   r = (Uint8)(r*(1-a) + ((col>>16)&0xFF)*(a));
   110   g = (Uint8)(g*(1-a) + ((col>> 8)&0xFF)*(a));
   110   g = (Uint8)(g*(1-a) + ((col>> 8)&0xFF)*(a));
   111   b = (Uint8)(b*(1-a) + ((col>> 0)&0xFF)*(a));
   111   b = (Uint8)(b*(1-a) + ((col>> 0)&0xFF)*(a));
   112   colour = SDL_MapRGB( screen->format,r, g, b);
   112   colour = SDL_MapRGB( screen->format,r, g, b);
   125 {
   125 {
   126   float tx,ty;
   126   float tx,ty;
   127   float xr;
   127   float xr;
   128   for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
   128   for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
   129     xr = (float)sqrt(r*r - ty*ty);
   129     xr = (float)sqrt(r*r - ty*ty);
   130     if(r > 0) { /*r > 0 ==> filled circle */
   130     if(r > 0) { /* r > 0 ==> filled circle */
   131       for(tx=-xr+.5f;tx<=xr-.5;tx++) {
   131       for(tx=-xr+.5f;tx<=xr-.5;tx++) {
   132     setpix(screen,x+tx,y+ty,c);
   132     setpix(screen,x+tx,y+ty,c);
   133       }
   133       }
   134     }
   134     }
   135     else {
   135     else {
   155   for(y = 0;y < screen->h;y++)
   155   for(y = 0;y < screen->h;y++)
   156     for(x = 0;x < screen->w;x++)
   156     for(x = 0;x < screen->w;x++)
   157     setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
   157     setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
   158 #endif
   158 #endif
   159 
   159 
   160   /*draw Touch History */
   160   /* draw Touch History */
   161   for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
   161   for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
   162     const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)];
   162     const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)];
   163     float age = (float)(i - eventWrite) / EVENT_BUF_SIZE;
   163     float age = (float)(i - eventWrite) / EVENT_BUF_SIZE;
   164     float x, y;
   164     float x, y;
   165     unsigned int c, col;
   165     unsigned int c, col;
   168        event->type == SDL_FINGERDOWN ||
   168        event->type == SDL_FINGERDOWN ||
   169        event->type == SDL_FINGERUP) {
   169        event->type == SDL_FINGERUP) {
   170       x = event->tfinger.x;
   170       x = event->tfinger.x;
   171       y = event->tfinger.y;
   171       y = event->tfinger.y;
   172 
   172 
   173       /*draw the touch: */
   173       /* draw the touch: */
   174       c = colors[event->tfinger.fingerId%7];
   174       c = colors[event->tfinger.fingerId%7];
   175       col = ((unsigned int)(c*(.1+.85))) | (unsigned int)(0xFF*age)<<24;
   175       col = ((unsigned int)(c*(.1+.85))) | (unsigned int)(0xFF*age)<<24;
   176 
   176 
   177       if(event->type == SDL_FINGERMOTION)
   177       if(event->type == SDL_FINGERMOTION)
   178     drawCircle(screen,x*screen->w,y*screen->h,5,col);
   178     drawCircle(screen,x*screen->w,y*screen->h,5,col);
   208   SDL_RWops *src;
   208   SDL_RWops *src;
   209 
   209 
   210   /* Enable standard application logging */
   210   /* Enable standard application logging */
   211   SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   211   SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   212 
   212 
   213   /*gesture variables */
   213   /* gesture variables */
   214   knob.r = .1f;
   214   knob.r = .1f;
   215   knob.ang = 0;
   215   knob.ang = 0;
   216 
   216 
   217   if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
   217   if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
   218 
   218 
   223     }
   223     }
   224 
   224 
   225   while(!quitting) {
   225   while(!quitting) {
   226     while(SDL_PollEvent(&event))
   226     while(SDL_PollEvent(&event))
   227       {
   227       {
   228     /*Record _all_ events */
   228     /* Record _all_ events */
   229     events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
   229     events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
   230     eventWrite++;
   230     eventWrite++;
   231 
   231 
   232     switch (event.type)
   232     switch (event.type)
   233       {
   233       {