test/testwm.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
child 1686 8d7fecceb9ef
     1.1 --- a/test/testwm.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/test/testwm.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -15,28 +15,28 @@
     1.4  
     1.5  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.6  static void
     1.7 -quit (int rc)
     1.8 +quit(int rc)
     1.9  {
    1.10 -    SDL_Quit ();
    1.11 -    exit (rc);
    1.12 +    SDL_Quit();
    1.13 +    exit(rc);
    1.14  }
    1.15  
    1.16  int
    1.17 -SetVideoMode (int w, int h)
    1.18 +SetVideoMode(int w, int h)
    1.19  {
    1.20      SDL_Surface *screen;
    1.21      int i;
    1.22      Uint8 *buffer;
    1.23      SDL_Color palette[256];
    1.24  
    1.25 -    screen = SDL_SetVideoMode (w, h, video_bpp, video_flags);
    1.26 +    screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
    1.27      if (screen == NULL) {
    1.28 -        fprintf (stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.29 -                 w, h, video_bpp, SDL_GetError ());
    1.30 +        fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.31 +                w, h, video_bpp, SDL_GetError());
    1.32          return (-1);
    1.33      }
    1.34 -    printf ("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
    1.35 -            "fullscreen" : "windowed");
    1.36 +    printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
    1.37 +           "fullscreen" : "windowed");
    1.38  
    1.39      /* Set the surface pixels and refresh! */
    1.40      for (i = 0; i < 256; ++i) {
    1.41 @@ -44,26 +44,26 @@
    1.42          palette[i].g = 255 - i;
    1.43          palette[i].b = 255 - i;
    1.44      }
    1.45 -    SDL_SetColors (screen, palette, 0, 256);
    1.46 -    if (SDL_LockSurface (screen) < 0) {
    1.47 -        fprintf (stderr, "Couldn't lock display surface: %s\n",
    1.48 -                 SDL_GetError ());
    1.49 +    SDL_SetColors(screen, palette, 0, 256);
    1.50 +    if (SDL_LockSurface(screen) < 0) {
    1.51 +        fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.52 +                SDL_GetError());
    1.53          return (-1);
    1.54      }
    1.55      buffer = (Uint8 *) screen->pixels;
    1.56      for (i = 0; i < screen->h; ++i) {
    1.57 -        memset (buffer, (i * 255) / screen->h,
    1.58 -                screen->w * screen->format->BytesPerPixel);
    1.59 +        memset(buffer, (i * 255) / screen->h,
    1.60 +               screen->w * screen->format->BytesPerPixel);
    1.61          buffer += screen->pitch;
    1.62      }
    1.63 -    SDL_UnlockSurface (screen);
    1.64 -    SDL_UpdateRect (screen, 0, 0, 0, 0);
    1.65 +    SDL_UnlockSurface(screen);
    1.66 +    SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.67  
    1.68      return (0);
    1.69  }
    1.70  
    1.71  SDL_Surface *
    1.72 -LoadIconSurface (char *file, Uint8 ** maskp)
    1.73 +LoadIconSurface(char *file, Uint8 ** maskp)
    1.74  {
    1.75      SDL_Surface *icon;
    1.76      Uint8 *pixels;
    1.77 @@ -73,9 +73,9 @@
    1.78      *maskp = NULL;
    1.79  
    1.80      /* Load the icon surface */
    1.81 -    icon = SDL_LoadBMP (file);
    1.82 +    icon = SDL_LoadBMP(file);
    1.83      if (icon == NULL) {
    1.84 -        fprintf (stderr, "Couldn't load %s: %s\n", file, SDL_GetError ());
    1.85 +        fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
    1.86          return (NULL);
    1.87      }
    1.88  
    1.89 @@ -89,28 +89,28 @@
    1.90  
    1.91  
    1.92      if (icon->format->palette == NULL) {
    1.93 -        fprintf (stderr, "Icon must have a palette!\n");
    1.94 -        SDL_FreeSurface (icon);
    1.95 +        fprintf(stderr, "Icon must have a palette!\n");
    1.96 +        SDL_FreeSurface(icon);
    1.97          return (NULL);
    1.98      }
    1.99  
   1.100      /* Set the colorkey */
   1.101 -    SDL_SetColorKey (icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels));
   1.102 +    SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels));
   1.103  
   1.104      /* Create the mask */
   1.105      pixels = (Uint8 *) icon->pixels;
   1.106 -    printf ("Transparent pixel: (%d,%d,%d)\n",
   1.107 -            icon->format->palette->colors[*pixels].r,
   1.108 -            icon->format->palette->colors[*pixels].g,
   1.109 -            icon->format->palette->colors[*pixels].b);
   1.110 +    printf("Transparent pixel: (%d,%d,%d)\n",
   1.111 +           icon->format->palette->colors[*pixels].r,
   1.112 +           icon->format->palette->colors[*pixels].g,
   1.113 +           icon->format->palette->colors[*pixels].b);
   1.114      mlen = (icon->w * icon->h + 7) / 8;
   1.115 -    mask = (Uint8 *) malloc (mlen);
   1.116 +    mask = (Uint8 *) malloc(mlen);
   1.117      if (mask == NULL) {
   1.118 -        fprintf (stderr, "Out of memory!\n");
   1.119 -        SDL_FreeSurface (icon);
   1.120 +        fprintf(stderr, "Out of memory!\n");
   1.121 +        SDL_FreeSurface(icon);
   1.122          return (NULL);
   1.123      }
   1.124 -    memset (mask, 0, mlen);
   1.125 +    memset(mask, 0, mlen);
   1.126      for (i = 0; i < icon->h; i++)
   1.127          for (j = 0; j < icon->w; j++) {
   1.128              int pindex = i * icon->pitch + j;
   1.129 @@ -123,60 +123,60 @@
   1.130  }
   1.131  
   1.132  void
   1.133 -HotKey_ToggleFullScreen (void)
   1.134 +HotKey_ToggleFullScreen(void)
   1.135  {
   1.136      SDL_Surface *screen;
   1.137  
   1.138 -    screen = SDL_GetVideoSurface ();
   1.139 -    if (SDL_WM_ToggleFullScreen (screen)) {
   1.140 -        printf ("Toggled fullscreen mode - now %s\n",
   1.141 -                (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
   1.142 +    screen = SDL_GetVideoSurface();
   1.143 +    if (SDL_WM_ToggleFullScreen(screen)) {
   1.144 +        printf("Toggled fullscreen mode - now %s\n",
   1.145 +               (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
   1.146      } else {
   1.147 -        printf ("Unable to toggle fullscreen mode\n");
   1.148 +        printf("Unable to toggle fullscreen mode\n");
   1.149          video_flags ^= SDL_FULLSCREEN;
   1.150 -        SetVideoMode (screen->w, screen->h);
   1.151 +        SetVideoMode(screen->w, screen->h);
   1.152      }
   1.153  }
   1.154  
   1.155  void
   1.156 -HotKey_ToggleGrab (void)
   1.157 +HotKey_ToggleGrab(void)
   1.158  {
   1.159      SDL_GrabMode mode;
   1.160  
   1.161 -    printf ("Ctrl-G: toggling input grab!\n");
   1.162 -    mode = SDL_WM_GrabInput (SDL_GRAB_QUERY);
   1.163 +    printf("Ctrl-G: toggling input grab!\n");
   1.164 +    mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
   1.165      if (mode == SDL_GRAB_ON) {
   1.166 -        printf ("Grab was on\n");
   1.167 +        printf("Grab was on\n");
   1.168      } else {
   1.169 -        printf ("Grab was off\n");
   1.170 +        printf("Grab was off\n");
   1.171      }
   1.172 -    mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
   1.173 +    mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
   1.174      if (mode == SDL_GRAB_ON) {
   1.175 -        printf ("Grab is now on\n");
   1.176 +        printf("Grab is now on\n");
   1.177      } else {
   1.178 -        printf ("Grab is now off\n");
   1.179 +        printf("Grab is now off\n");
   1.180      }
   1.181  }
   1.182  
   1.183  void
   1.184 -HotKey_Iconify (void)
   1.185 +HotKey_Iconify(void)
   1.186  {
   1.187 -    printf ("Ctrl-Z: iconifying window!\n");
   1.188 -    SDL_WM_IconifyWindow ();
   1.189 +    printf("Ctrl-Z: iconifying window!\n");
   1.190 +    SDL_WM_IconifyWindow();
   1.191  }
   1.192  
   1.193  void
   1.194 -HotKey_Quit (void)
   1.195 +HotKey_Quit(void)
   1.196  {
   1.197      SDL_Event event;
   1.198  
   1.199 -    printf ("Posting internal quit request\n");
   1.200 +    printf("Posting internal quit request\n");
   1.201      event.type = SDL_USEREVENT;
   1.202 -    SDL_PushEvent (&event);
   1.203 +    SDL_PushEvent(&event);
   1.204  }
   1.205  
   1.206  int SDLCALL
   1.207 -FilterEvents (const SDL_Event * event)
   1.208 +FilterEvents(const SDL_Event * event)
   1.209  {
   1.210      static int reallyquit = 0;
   1.211  
   1.212 @@ -184,19 +184,19 @@
   1.213  
   1.214      case SDL_ACTIVEEVENT:
   1.215          /* See what happened */
   1.216 -        printf ("App %s ", event->active.gain ? "gained" : "lost");
   1.217 +        printf("App %s ", event->active.gain ? "gained" : "lost");
   1.218          if (event->active.state & SDL_APPACTIVE)
   1.219 -            printf ("active ");
   1.220 +            printf("active ");
   1.221          if (event->active.state & SDL_APPINPUTFOCUS)
   1.222 -            printf ("input ");
   1.223 +            printf("input ");
   1.224          if (event->active.state & SDL_APPMOUSEFOCUS)
   1.225 -            printf ("mouse ");
   1.226 -        printf ("focus\n");
   1.227 +            printf("mouse ");
   1.228 +        printf("focus\n");
   1.229  
   1.230          /* See if we are iconified or restored */
   1.231          if (event->active.state & SDL_APPACTIVE) {
   1.232 -            printf ("App has been %s\n",
   1.233 -                    event->active.gain ? "restored" : "iconified");
   1.234 +            printf("App has been %s\n",
   1.235 +                   event->active.gain ? "restored" : "iconified");
   1.236          }
   1.237          return (0);
   1.238  
   1.239 @@ -205,38 +205,37 @@
   1.240      case SDL_MOUSEBUTTONUP:
   1.241          if (event->button.state == SDL_PRESSED) {
   1.242              visible = !visible;
   1.243 -            SDL_ShowCursor (visible);
   1.244 +            SDL_ShowCursor(visible);
   1.245          }
   1.246 -        printf ("Mouse button %d has been %s\n",
   1.247 -                event->button.button,
   1.248 -                (event->button.state == SDL_PRESSED) ?
   1.249 -                "pressed" : "released");
   1.250 +        printf("Mouse button %d has been %s\n",
   1.251 +               event->button.button,
   1.252 +               (event->button.state == SDL_PRESSED) ? "pressed" : "released");
   1.253          return (0);
   1.254  
   1.255          /* Show relative mouse motion */
   1.256      case SDL_MOUSEMOTION:
   1.257  #if 0
   1.258 -        printf ("Mouse motion: {%d,%d} (%d,%d)\n",
   1.259 -                event->motion.x, event->motion.y,
   1.260 -                event->motion.xrel, event->motion.yrel);
   1.261 +        printf("Mouse motion: {%d,%d} (%d,%d)\n",
   1.262 +               event->motion.x, event->motion.y,
   1.263 +               event->motion.xrel, event->motion.yrel);
   1.264  #endif
   1.265          return (0);
   1.266  
   1.267      case SDL_KEYDOWN:
   1.268          if (event->key.keysym.sym == SDLK_ESCAPE) {
   1.269 -            HotKey_Quit ();
   1.270 +            HotKey_Quit();
   1.271          }
   1.272          if ((event->key.keysym.sym == SDLK_g) &&
   1.273              (event->key.keysym.mod & KMOD_CTRL)) {
   1.274 -            HotKey_ToggleGrab ();
   1.275 +            HotKey_ToggleGrab();
   1.276          }
   1.277          if ((event->key.keysym.sym == SDLK_z) &&
   1.278              (event->key.keysym.mod & KMOD_CTRL)) {
   1.279 -            HotKey_Iconify ();
   1.280 +            HotKey_Iconify();
   1.281          }
   1.282          if ((event->key.keysym.sym == SDLK_RETURN) &&
   1.283              (event->key.keysym.mod & KMOD_ALT)) {
   1.284 -            HotKey_ToggleFullScreen ();
   1.285 +            HotKey_ToggleFullScreen();
   1.286          }
   1.287          return (0);
   1.288  
   1.289 @@ -248,10 +247,10 @@
   1.290      case SDL_QUIT:
   1.291          if (!reallyquit) {
   1.292              reallyquit = 1;
   1.293 -            printf ("Quit requested\n");
   1.294 +            printf("Quit requested\n");
   1.295              return (0);
   1.296          }
   1.297 -        printf ("Quit demanded\n");
   1.298 +        printf("Quit demanded\n");
   1.299          return (1);
   1.300  
   1.301          /* This will never happen because events queued directly
   1.302 @@ -267,7 +266,7 @@
   1.303  }
   1.304  
   1.305  int
   1.306 -main (int argc, char *argv[])
   1.307 +main(int argc, char *argv[])
   1.308  {
   1.309      SDL_Event event;
   1.310      char *title;
   1.311 @@ -276,8 +275,8 @@
   1.312      int parsed;
   1.313      int w, h;
   1.314  
   1.315 -    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
   1.316 -        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.317 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   1.318 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.319          return (1);
   1.320      }
   1.321  
   1.322 @@ -288,28 +287,28 @@
   1.323      video_flags = SDL_SWSURFACE;
   1.324      parsed = 1;
   1.325      while (parsed) {
   1.326 -        if ((argc >= 2) && (strcmp (argv[1], "-fullscreen") == 0)) {
   1.327 +        if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) {
   1.328              video_flags |= SDL_FULLSCREEN;
   1.329              argc -= 1;
   1.330              argv += 1;
   1.331 -        } else if ((argc >= 2) && (strcmp (argv[1], "-resize") == 0)) {
   1.332 +        } else if ((argc >= 2) && (strcmp(argv[1], "-resize") == 0)) {
   1.333              video_flags |= SDL_RESIZABLE;
   1.334              argc -= 1;
   1.335              argv += 1;
   1.336 -        } else if ((argc >= 2) && (strcmp (argv[1], "-noframe") == 0)) {
   1.337 +        } else if ((argc >= 2) && (strcmp(argv[1], "-noframe") == 0)) {
   1.338              video_flags |= SDL_NOFRAME;
   1.339              argc -= 1;
   1.340              argv += 1;
   1.341 -        } else if ((argc >= 3) && (strcmp (argv[1], "-width") == 0)) {
   1.342 -            w = atoi (argv[2]);
   1.343 +        } else if ((argc >= 3) && (strcmp(argv[1], "-width") == 0)) {
   1.344 +            w = atoi(argv[2]);
   1.345              argc -= 2;
   1.346              argv += 2;
   1.347 -        } else if ((argc >= 3) && (strcmp (argv[1], "-height") == 0)) {
   1.348 -            h = atoi (argv[2]);
   1.349 +        } else if ((argc >= 3) && (strcmp(argv[1], "-height") == 0)) {
   1.350 +            h = atoi(argv[2]);
   1.351              argc -= 2;
   1.352              argv += 2;
   1.353 -        } else if ((argc >= 3) && (strcmp (argv[1], "-bpp") == 0)) {
   1.354 -            video_bpp = atoi (argv[2]);
   1.355 +        } else if ((argc >= 3) && (strcmp(argv[1], "-bpp") == 0)) {
   1.356 +            video_bpp = atoi(argv[2]);
   1.357              argc -= 2;
   1.358              argv += 2;
   1.359          } else {
   1.360 @@ -318,59 +317,59 @@
   1.361      }
   1.362  
   1.363      /* Set the icon -- this must be done before the first mode set */
   1.364 -    icon = LoadIconSurface ("icon.bmp", &icon_mask);
   1.365 +    icon = LoadIconSurface("icon.bmp", &icon_mask);
   1.366      if (icon != NULL) {
   1.367 -        SDL_WM_SetIcon (icon, icon_mask);
   1.368 +        SDL_WM_SetIcon(icon, icon_mask);
   1.369      }
   1.370      if (icon_mask != NULL)
   1.371 -        free (icon_mask);
   1.372 +        free(icon_mask);
   1.373  
   1.374      /* Set the title bar */
   1.375      if (argv[1] == NULL)
   1.376          title = "Testing  1.. 2.. 3...";
   1.377      else
   1.378          title = argv[1];
   1.379 -    SDL_WM_SetCaption (title, "testwm");
   1.380 +    SDL_WM_SetCaption(title, "testwm");
   1.381  
   1.382      /* See if it's really set */
   1.383 -    SDL_WM_GetCaption (&title, NULL);
   1.384 +    SDL_WM_GetCaption(&title, NULL);
   1.385      if (title)
   1.386 -        printf ("Title was set to: %s\n", title);
   1.387 +        printf("Title was set to: %s\n", title);
   1.388      else
   1.389 -        printf ("No window title was set!\n");
   1.390 +        printf("No window title was set!\n");
   1.391  
   1.392      /* Initialize the display */
   1.393 -    if (SetVideoMode (w, h) < 0) {
   1.394 -        quit (1);
   1.395 +    if (SetVideoMode(w, h) < 0) {
   1.396 +        quit(1);
   1.397      }
   1.398  
   1.399      /* Set an event filter that discards everything but QUIT */
   1.400 -    SDL_SetEventFilter (FilterEvents);
   1.401 +    SDL_SetEventFilter(FilterEvents);
   1.402  
   1.403      /* Ignore key up events, they don't even get filtered */
   1.404 -    SDL_EventState (SDL_KEYUP, SDL_IGNORE);
   1.405 +    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   1.406  
   1.407      /* Loop, waiting for QUIT */
   1.408 -    while (SDL_WaitEvent (&event)) {
   1.409 +    while (SDL_WaitEvent(&event)) {
   1.410          switch (event.type) {
   1.411          case SDL_VIDEORESIZE:
   1.412 -            printf ("Got a resize event: %dx%d\n",
   1.413 -                    event.resize.w, event.resize.h);
   1.414 -            SetVideoMode (event.resize.w, event.resize.h);
   1.415 +            printf("Got a resize event: %dx%d\n",
   1.416 +                   event.resize.w, event.resize.h);
   1.417 +            SetVideoMode(event.resize.w, event.resize.h);
   1.418              break;
   1.419          case SDL_USEREVENT:
   1.420 -            printf ("Handling internal quit request\n");
   1.421 +            printf("Handling internal quit request\n");
   1.422              /* Fall through to the quit handler */
   1.423          case SDL_QUIT:
   1.424 -            printf ("Bye bye..\n");
   1.425 -            quit (0);
   1.426 +            printf("Bye bye..\n");
   1.427 +            quit(0);
   1.428          default:
   1.429              /* This should never happen */
   1.430 -            printf ("Warning: Event %d wasn't filtered\n", event.type);
   1.431 +            printf("Warning: Event %d wasn't filtered\n", event.type);
   1.432              break;
   1.433          }
   1.434      }
   1.435 -    printf ("SDL_WaitEvent() error: %s\n", SDL_GetError ());
   1.436 -    SDL_Quit ();
   1.437 +    printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
   1.438 +    SDL_Quit();
   1.439      return (255);
   1.440  }