Advertisement
Guest User

SDL 1.2 Multitouch sample

a guest
Jul 5th, 2011
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <SDL.h>
  2.  
  3. SDL_Surface *screen;
  4.  
  5. Uint32 colors[SDL_MAXMOUSE];
  6.  
  7. void put_square(int x, int y, int color)
  8. {
  9.     SDL_Rect rect = { x - 5, y - 5, 10, 10};
  10.     SDL_FillRect(screen, &rect, color);
  11. }
  12.  
  13. static Uint32 timer(Uint32 interval, void * param)
  14. {
  15.     SDL_Event event;
  16.     event.type = SDL_VIDEOEXPOSE;
  17.     SDL_PushEvent(&event);
  18.     return interval;
  19. }
  20.  
  21. int main(int argc, char **argv)
  22. {
  23.     SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
  24.  
  25.     screen = SDL_SetVideoMode(0, 0, 32, SDL_HWSURFACE | SDL_FULLSCREEN);
  26.  
  27.     printf("Starting\n");
  28.  
  29.     colors[0] = SDL_MapRGB(screen->format, 255, 0, 0);
  30.     colors[1] = SDL_MapRGB(screen->format, 0, 255, 0);
  31.     colors[2] = SDL_MapRGB(screen->format, 0, 0, 255);
  32.     colors[3] = SDL_MapRGB(screen->format, 255, 0, 255);
  33.     colors[4] = SDL_MapRGB(screen->format, 255, 255, 0);
  34.     colors[5] = SDL_MapRGB(screen->format, 0, 255, 255);
  35.  
  36.     SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
  37.     SDL_Flip(screen);
  38.  
  39.     SDL_AddTimer(20, timer, NULL);
  40.  
  41.     SDL_Event event;
  42.     while (SDL_WaitEvent(&event)) {
  43.         switch (event.type) {
  44.             case SDL_QUIT:
  45.                 goto quit;
  46.             case SDL_MOUSEMOTION:
  47.                 put_square(event.motion.x, event.motion.y, colors[event.motion.which]);
  48.                 break;
  49.             case SDL_VIDEOEXPOSE:
  50.                 SDL_Flip(screen);
  51.                 break;
  52.         }
  53.     }
  54.  
  55. quit:
  56.     printf("Quitting\n");
  57.     SDL_Quit();
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement