test/testgesture.c
changeset 9273 9f1c18388f2c
parent 9235 ba9988f0daec
child 9274 f95cc158ed4f
equal deleted inserted replaced
9272:5c894fec85b9 9273:9f1c18388f2c
    31 #define EVENT_BUF_SIZE 256
    31 #define EVENT_BUF_SIZE 256
    32 
    32 
    33 
    33 
    34 #define VERBOSE 0
    34 #define VERBOSE 0
    35 
    35 
    36 static SDL_Window *window;
       
    37 static SDL_Event events[EVENT_BUF_SIZE];
    36 static SDL_Event events[EVENT_BUF_SIZE];
    38 static int eventWrite;
    37 static int eventWrite;
    39 
    38 
    40 
    39 
    41 static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
    40 static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
   121   drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
   120   drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
   122   drawCircle(screen,(k.p.x+k.r/2*SDL_cosf(k.ang))*screen->w,
   121   drawCircle(screen,(k.p.x+k.r/2*SDL_cosf(k.ang))*screen->w,
   123                 (k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
   122                 (k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
   124 }
   123 }
   125 
   124 
   126 void DrawScreen(SDL_Surface* screen)
   125 void DrawScreen(SDL_Surface* screen, SDL_Window* window)
   127 {
   126 {
   128   int i;
   127   int i;
   129 #if 1
   128 #if 1
   130   SDL_FillRect(screen, NULL, 0);
   129   SDL_FillRect(screen, NULL, 0);
   131 #else
   130 #else
   163     drawKnob(screen,knob);
   162     drawKnob(screen,knob);
   164 
   163 
   165   SDL_UpdateWindowSurface(window);
   164   SDL_UpdateWindowSurface(window);
   166 }
   165 }
   167 
   166 
   168 SDL_Surface* initScreen(int width,int height)
   167 /* Returns a new SDL_Window if window is NULL or window if not. */
       
   168 SDL_Window* initWindow(SDL_Window *window, int width,int height)
   169 {
   169 {
   170   if (!window) {
   170   if (!window) {
   171     window = SDL_CreateWindow("Gesture Test",
   171     window = SDL_CreateWindow("Gesture Test",
   172                               SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
   172                               SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
   173                               width, height, SDL_WINDOW_RESIZABLE);
   173                               width, height, SDL_WINDOW_RESIZABLE);
   174   }
   174   }
   175   if (!window) {
   175   if (!window) {
   176     return NULL;
   176     return NULL;
   177   }
   177   }
   178   return SDL_GetWindowSurface(window);
   178   return window;
   179 }
   179 }
   180 
   180 
   181 int main(int argc, char* argv[])
   181 int main(int argc, char* argv[])
   182 {
   182 {
       
   183   SDL_Window *window = NULL;
   183   SDL_Surface *screen;
   184   SDL_Surface *screen;
   184   SDL_Event event;
   185   SDL_Event event;
   185   SDL_bool quitting = SDL_FALSE;
   186   SDL_bool quitting = SDL_FALSE;
   186   SDL_RWops *stream;
   187   SDL_RWops *stream;
   187 
   188 
   192   knob.r = .1f;
   193   knob.r = .1f;
   193   knob.ang = 0;
   194   knob.ang = 0;
   194 
   195 
   195   if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
   196   if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
   196 
   197 
   197   if (!(screen = initScreen(WIDTH,HEIGHT)))
   198   if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
       
   199       !(screen = SDL_GetWindowSurface(window)))
   198     {
   200     {
   199       SDL_Quit();
   201       SDL_Quit();
   200       return 1;
   202       return 1;
   201     }
   203     }
   202 
   204 
   242         break;
   244         break;
   243         }
   245         }
   244         break;
   246         break;
   245       case SDL_WINDOWEVENT:
   247       case SDL_WINDOWEVENT:
   246             if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
   248             if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
   247           if (!(screen = initScreen(event.window.data1, event.window.data2)))
   249           if (!(window = initWindow(window, event.window.data1, event.window.data2)) ||
       
   250               !(screen = SDL_GetWindowSurface(window)))
   248           {
   251           {
   249         SDL_Quit();
   252         SDL_Quit();
   250         return 1;
   253         return 1;
   251           }
   254           }
   252             }
   255             }
   291       case SDL_DOLLARRECORD:
   294       case SDL_DOLLARRECORD:
   292         SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
   295         SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
   293         break;
   296         break;
   294       }
   297       }
   295       }
   298       }
   296     DrawScreen(screen);
   299     DrawScreen(screen, window);
   297   }
   300   }
   298   SDL_Quit();
   301   SDL_Quit();
   299   return 0;
   302   return 0;
   300 }
   303 }
   301 
   304