Mercurial > sdl-ios-xcode
comparison test/testwm2.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | |
children | 7ee5297340f7 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
1 /* Simple program: Move N sprites around on the screen as fast as possible */ | |
2 | |
3 #include "SDL.h" | |
4 | |
5 #define NUM_WINDOWS 2 | |
6 #define WINDOW_W 640 | |
7 #define WINDOW_H 480 | |
8 | |
9 static int num_windows; | |
10 static SDL_WindowID *windows; | |
11 | |
12 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | |
13 static void | |
14 quit(int rc) | |
15 { | |
16 if (windows) { | |
17 SDL_free(windows); | |
18 } | |
19 SDL_Quit(); | |
20 exit(rc); | |
21 } | |
22 | |
23 int | |
24 main(int argc, char *argv[]) | |
25 { | |
26 int window_w, window_h; | |
27 int i, done; | |
28 SDL_Event event; | |
29 | |
30 /* Initialize SDL */ | |
31 if (SDL_Init(SDL_INIT_VIDEO) < 0) { | |
32 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); | |
33 return (1); | |
34 } | |
35 | |
36 num_windows = NUM_WINDOWS; | |
37 window_w = WINDOW_W; | |
38 window_h = WINDOW_H; | |
39 while (argc > 1) { | |
40 if (strcmp(argv[argc - 1], "-width") == 0) { | |
41 window_w = atoi(argv[argc]); | |
42 --argc; | |
43 } else if (strcmp(argv[argc - 1], "-height") == 0) { | |
44 window_h = atoi(argv[argc]); | |
45 --argc; | |
46 } else { | |
47 fprintf(stderr, "Usage: %s [-width] [-height]\n", argv[0]); | |
48 quit(1); | |
49 } | |
50 } | |
51 | |
52 /* Create the windows */ | |
53 windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows)); | |
54 if (!windows) { | |
55 fprintf(stderr, "Out of memory!\n"); | |
56 quit(2); | |
57 } | |
58 for (i = 0; i < num_windows; ++i) { | |
59 char title[32]; | |
60 int x, y; | |
61 | |
62 SDL_snprintf(title, sizeof(title), "testwm %d", i + 1); | |
63 if (i == 0) { | |
64 x = SDL_WINDOWPOS_CENTERED; | |
65 y = SDL_WINDOWPOS_CENTERED; | |
66 } else { | |
67 x = SDL_WINDOWPOS_UNDEFINED; | |
68 y = SDL_WINDOWPOS_UNDEFINED; | |
69 } | |
70 windows[i] = | |
71 SDL_CreateWindow(title, x, y, window_w, window_h, | |
72 SDL_WINDOW_SHOWN); | |
73 if (!windows[i]) { | |
74 fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); | |
75 quit(2); | |
76 } | |
77 } | |
78 | |
79 /* Loop, blitting sprites and waiting for a keystroke */ | |
80 done = 0; | |
81 while (!done) { | |
82 /* Check for events */ | |
83 while (SDL_PollEvent(&event)) { | |
84 switch (event.type) { | |
85 case SDL_KEYDOWN: | |
86 /* Any keypress quits the app... */ | |
87 case SDL_QUIT: | |
88 done = 1; | |
89 break; | |
90 default: | |
91 break; | |
92 } | |
93 } | |
94 } | |
95 | |
96 quit(0); | |
97 } | |
98 | |
99 /* vi: set ts=4 sw=4 expandtab: */ |