test/testwm2.c
branchSDL-1.3
changeset 1712 931d111e737a
child 1713 3e66ed1690e4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testwm2.c	Mon Jun 26 13:56:56 2006 +0000
     1.3 @@ -0,0 +1,99 @@
     1.4 +/* Simple program:  Move N sprites around on the screen as fast as possible */
     1.5 +
     1.6 +#include "SDL.h"
     1.7 +
     1.8 +#define NUM_WINDOWS 2
     1.9 +#define WINDOW_W    640
    1.10 +#define WINDOW_H    480
    1.11 +
    1.12 +static int num_windows;
    1.13 +static SDL_WindowID *windows;
    1.14 +
    1.15 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.16 +static void
    1.17 +quit(int rc)
    1.18 +{
    1.19 +    if (windows) {
    1.20 +        SDL_free(windows);
    1.21 +    }
    1.22 +    SDL_Quit();
    1.23 +    exit(rc);
    1.24 +}
    1.25 +
    1.26 +int
    1.27 +main(int argc, char *argv[])
    1.28 +{
    1.29 +    int window_w, window_h;
    1.30 +    int i, done;
    1.31 +    SDL_Event event;
    1.32 +
    1.33 +    /* Initialize SDL */
    1.34 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.35 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.36 +        return (1);
    1.37 +    }
    1.38 +
    1.39 +    num_windows = NUM_WINDOWS;
    1.40 +    window_w = WINDOW_W;
    1.41 +    window_h = WINDOW_H;
    1.42 +    while (argc > 1) {
    1.43 +        --argc;
    1.44 +        if (strcmp(argv[argc - 1], "-width") == 0) {
    1.45 +            window_w = atoi(argv[argc]);
    1.46 +            --argc;
    1.47 +        } else if (strcmp(argv[argc - 1], "-height") == 0) {
    1.48 +            window_h = atoi(argv[argc]);
    1.49 +            --argc;
    1.50 +        } else {
    1.51 +            fprintf(stderr,
    1.52 +                    "Usage: %s [-width] [-height]\n", argv[0]);
    1.53 +            quit(1);
    1.54 +        }
    1.55 +    }
    1.56 +
    1.57 +    /* Set the desktop mode, we don't care what it is */
    1.58 +    if (SDL_SetDisplayMode(NULL) < 0) {
    1.59 +        fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
    1.60 +        quit(2);
    1.61 +    }
    1.62 +
    1.63 +    /* Create the windows */
    1.64 +    windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
    1.65 +    if (!windows) {
    1.66 +        fprintf(stderr, "Out of memory!\n");
    1.67 +        quit(2);
    1.68 +    }
    1.69 +    for (i = 0; i < num_windows; ++i) {
    1.70 +        char title[32];
    1.71 +
    1.72 +        SDL_snprintf(title, sizeof(title), "testwm %d", i + 1);
    1.73 +        windows[i] =
    1.74 +            SDL_CreateWindow(title, -1, -1, window_w, window_h,
    1.75 +                             SDL_WINDOW_SHOWN);
    1.76 +        if (!windows[i]) {
    1.77 +            fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
    1.78 +            quit(2);
    1.79 +        }
    1.80 +    }
    1.81 +
    1.82 +    /* Loop, blitting sprites and waiting for a keystroke */
    1.83 +    done = 0;
    1.84 +    while (!done) {
    1.85 +        /* Check for events */
    1.86 +        while (SDL_PollEvent(&event)) {
    1.87 +            switch (event.type) {
    1.88 +            case SDL_KEYDOWN:
    1.89 +                /* Any keypress quits the app... */
    1.90 +            case SDL_QUIT:
    1.91 +                done = 1;
    1.92 +                break;
    1.93 +            default:
    1.94 +                break;
    1.95 +            }
    1.96 +        }
    1.97 +    }
    1.98 +
    1.99 +    quit(0);
   1.100 +}
   1.101 +
   1.102 +/* vi: set ts=4 sw=4 expandtab: */