test/threadwin.c
changeset 4429 faa9fc8e7f67
parent 2117 40888832d785
child 5123 dc0dfdd58f27
equal deleted inserted replaced
4428:68dfd6df47da 4429:faa9fc8e7f67
   131 int SDLCALL
   131 int SDLCALL
   132 HandleMouse(void *unused)
   132 HandleMouse(void *unused)
   133 {
   133 {
   134     SDL_Event events[10];
   134     SDL_Event events[10];
   135     int i, found;
   135     int i, found;
   136     Uint32 mask;
       
   137 
   136 
   138     /* Handle mouse events here */
   137     /* Handle mouse events here */
   139     mask =
       
   140         (SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK |
       
   141          SDL_MOUSEBUTTONUPMASK);
       
   142     while (!done) {
   138     while (!done) {
   143         found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask);
   139         found = SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
   144         for (i = 0; i < found; ++i) {
   140         for (i = 0; i < found; ++i) {
   145             switch (events[i].type) {
   141             switch (events[i].type) {
   146                 /* We want to toggle visibility on buttonpress */
   142                 /* We want to toggle visibility on buttonpress */
   147             case SDL_MOUSEBUTTONDOWN:
   143             case SDL_MOUSEBUTTONDOWN:
   148             case SDL_MOUSEBUTTONUP:
   144             case SDL_MOUSEBUTTONUP:
   171 int SDLCALL
   167 int SDLCALL
   172 HandleKeyboard(void *unused)
   168 HandleKeyboard(void *unused)
   173 {
   169 {
   174     SDL_Event events[10];
   170     SDL_Event events[10];
   175     int i, found;
   171     int i, found;
   176     Uint32 mask;
       
   177 
   172 
   178     /* Handle mouse events here */
   173     /* Handle mouse events here */
   179     mask = (SDL_KEYDOWNMASK | SDL_KEYUPMASK);
       
   180     while (!done) {
   174     while (!done) {
   181         found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask);
   175         found = SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP);
   182         for (i = 0; i < found; ++i) {
   176         for (i = 0; i < found; ++i) {
   183             switch (events[i].type) {
   177             switch (events[i].type) {
   184                 /* We want to toggle visibility on buttonpress */
   178                 /* We want to toggle visibility on buttonpress */
   185             case SDL_KEYDOWN:
   179             case SDL_KEYDOWN:
   186             case SDL_KEYUP:
   180             case SDL_KEYUP:
   327     /* Loop, waiting for QUIT */
   321     /* Loop, waiting for QUIT */
   328     while (!done) {
   322     while (!done) {
   329         if (!(init_flags & SDL_INIT_EVENTTHREAD)) {
   323         if (!(init_flags & SDL_INIT_EVENTTHREAD)) {
   330             SDL_PumpEvents();   /* Needed when event thread is off */
   324             SDL_PumpEvents();   /* Needed when event thread is off */
   331         }
   325         }
   332         if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUITMASK)) {
   326         if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT)) {
   333             done = 1;
   327             done = 1;
   334         }
   328         }
   335         /* Give up some CPU so the events can accumulate */
   329         /* Give up some CPU so the events can accumulate */
   336         SDL_Delay(20);
   330         SDL_Delay(20);
   337     }
   331     }