annotate test/testwm.c @ 1013:a649064a3215

Date: Tue, 14 Dec 2004 12:08:30 +0100 From: Marcin Konicki Subject: Re: [SDL] SDL 1.2.8 Prerelease I'm sending small fix for BeOS, which prevents filling up SDL's message queue too fast. Without it, SDL receives "key down" messages from BeOS code, for each key repeat (BeOS handles key repeats itself, and application can check if received "key down" message from BeOS is first time key down, or if it's repeat, and which repeat it is). Since there is no way for "sdl driver" to turn off "default" SDL's key-repeat mechanism, they were working both at the same time (and queue could be filled up very fast). So this patch removes handling "key down" message from BeOS if it's key_repeat "type".
author Sam Lantinga <slouken@libsdl.org>
date Tue, 14 Dec 2004 18:23:27 +0000
parents 3eddf51b649b
children be9c9c8f6d53
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 /* Test out the window manager interaction functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
3
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 /* Is the cursor visible? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 static int visible = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
13 static Uint8 video_bpp;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
14 static Uint32 video_flags;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
15
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
16 int SetVideoMode(int w, int h)
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
17 {
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
18 SDL_Surface *screen;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
19 int i;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
20 Uint8 *buffer;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
21 SDL_Color palette[256];
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
22
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
23 screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
24 if ( screen == NULL ) {
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
25 fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
26 w, h, video_bpp, SDL_GetError());
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
27 return(-1);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
28 }
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
29 printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
30 "fullscreen" : "windowed");
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
31
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
32 /* Set the surface pixels and refresh! */
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
33 for ( i=0; i<256; ++i ) {
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
34 palette[i].r = 255-i;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
35 palette[i].g = 255-i;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
36 palette[i].b = 255-i;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
37 }
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
38 SDL_SetColors(screen, palette, 0, 256);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
39 if ( SDL_LockSurface(screen) < 0 ) {
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
40 fprintf(stderr, "Couldn't lock display surface: %s\n",
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
41 SDL_GetError());
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
42 return(-1);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
43 }
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
44 buffer = (Uint8 *)screen->pixels;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
45 for ( i=0; i<screen->h; ++i ) {
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
46 memset(buffer,(i*255)/screen->h,
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
47 screen->w*screen->format->BytesPerPixel);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
48 buffer += screen->pitch;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
49 }
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
50 SDL_UnlockSurface(screen);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
51 SDL_UpdateRect(screen, 0, 0, 0, 0);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
52
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
53 return(0);
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
54 }
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
55
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 SDL_Surface *icon;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 Uint8 *pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 Uint8 *mask;
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
61 int mlen, i, j;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 *maskp = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 /* Load the icon surface */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 icon = SDL_LoadBMP(file);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 if ( icon == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
72 /* Check width and height
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 if ( (icon->w%8) != 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 fprintf(stderr, "Icon width must be a multiple of 8!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 SDL_FreeSurface(icon);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 }
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
78 */
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
79
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
80
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 if ( icon->format->palette == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 fprintf(stderr, "Icon must have a palette!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 SDL_FreeSurface(icon);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 /* Set the colorkey */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *)icon->pixels));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 /* Create the mask */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 pixels = (Uint8 *)icon->pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 printf("Transparent pixel: (%d,%d,%d)\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 icon->format->palette->colors[*pixels].r,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 icon->format->palette->colors[*pixels].g,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 icon->format->palette->colors[*pixels].b);
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
96 mlen = (icon->w*icon->h + 7) / 8;
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
97 mask = (Uint8 *)malloc(mlen);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 if ( mask == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 fprintf(stderr, "Out of memory!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 SDL_FreeSurface(icon);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 }
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
103 memset(mask, 0, mlen);
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
104 for ( i=0; i < icon->h; i++)
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
105 for (j=0; j < icon->w; j++) {
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
106 int pindex = i * icon->pitch + j;
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
107 int mindex = i * icon->w + j;
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
108 if ( pixels[pindex] != *pixels )
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
109 mask[mindex>>3] |= 1 << (7 - (mindex & 7));
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
110 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 *maskp = mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 return(icon);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 void HotKey_ToggleFullScreen(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 SDL_Surface *screen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 screen = SDL_GetVideoSurface();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 if ( SDL_WM_ToggleFullScreen(screen) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 printf("Toggled fullscreen mode - now %s\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 printf("Unable to toggle fullscreen mode\n");
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
125 video_flags ^= SDL_FULLSCREEN;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
126 SetVideoMode(screen->w, screen->h);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 void HotKey_ToggleGrab(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 SDL_GrabMode mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 printf("Ctrl-G: toggling input grab!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 if ( mode == SDL_GRAB_ON ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 printf("Grab was on\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 printf("Grab was off\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 }
609
a30b17e09cc0 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 591
diff changeset
141 mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 if ( mode == SDL_GRAB_ON ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 printf("Grab is now on\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 printf("Grab is now off\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 void HotKey_Iconify(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 printf("Ctrl-Z: iconifying window!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 SDL_WM_IconifyWindow();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 void HotKey_Quit(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 SDL_Event event;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 printf("Posting internal quit request\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 event.type = SDL_USEREVENT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 SDL_PushEvent(&event);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 int FilterEvents(const SDL_Event *event)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 static int reallyquit = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 switch (event->type) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 case SDL_ACTIVEEVENT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 /* See what happened */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 printf("App %s ",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 event->active.gain ? "gained" : "lost");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 if ( event->active.state & SDL_APPACTIVE )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 printf("active ");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 if ( event->active.state & SDL_APPMOUSEFOCUS )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 printf("mouse ");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 if ( event->active.state & SDL_APPINPUTFOCUS )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 printf("input ");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 printf("focus\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 /* See if we are iconified or restored */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 if ( event->active.state & SDL_APPACTIVE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 printf("App has been %s\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 event->active.gain ?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 "restored" : "iconified");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 /* We want to toggle visibility on buttonpress */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 case SDL_MOUSEBUTTONDOWN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 case SDL_MOUSEBUTTONUP:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 if ( event->button.state == SDL_PRESSED ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 visible = !visible;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 SDL_ShowCursor(visible);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 printf("Mouse button %d has been %s\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 event->button.button,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 (event->button.state == SDL_PRESSED) ?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 "pressed" : "released");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 /* Show relative mouse motion */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 case SDL_MOUSEMOTION:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 #if 0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 printf("Mouse relative motion: {%d,%d}\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 event->motion.xrel, event->motion.yrel);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 case SDL_KEYDOWN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 if ( event->key.keysym.sym == SDLK_ESCAPE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 HotKey_Quit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 if ( (event->key.keysym.sym == SDLK_g) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 (event->key.keysym.mod & KMOD_CTRL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 HotKey_ToggleGrab();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 if ( (event->key.keysym.sym == SDLK_z) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 (event->key.keysym.mod & KMOD_CTRL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 HotKey_Iconify();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 if ( (event->key.keysym.sym == SDLK_RETURN) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 (event->key.keysym.mod & KMOD_ALT) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 HotKey_ToggleFullScreen();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 /* Pass the video resize event through .. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 case SDL_VIDEORESIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 /* This is important! Queue it if we want to quit. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 case SDL_QUIT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 if ( ! reallyquit ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 reallyquit = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 printf("Quit requested\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 printf("Quit demanded\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 /* This will never happen because events queued directly
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 to the event queue are not filtered.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 case SDL_USEREVENT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 /* Drop all other events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 int main(int argc, char *argv[])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 SDL_Event event;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258 char *title;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 SDL_Surface *icon;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260 Uint8 *icon_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 int parsed;
87
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
262 int w, h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 fprintf(stderr,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 "Couldn't initialize SDL: %s\n", SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 exit(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 atexit(SDL_Quit);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 /* Check command line arguments */
87
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
272 w = 640;
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
273 h = 480;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 video_bpp = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 video_flags = SDL_SWSURFACE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 parsed = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 while ( parsed ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 if ( (argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 video_flags |= SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 argc -= 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 argv += 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 } else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 if ( (argc >= 2) && (strcmp(argv[1], "-resize") == 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 video_flags |= SDL_RESIZABLE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 argc -= 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 argv += 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 } else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288 if ( (argc >= 2) && (strcmp(argv[1], "-noframe") == 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 video_flags |= SDL_NOFRAME;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 argc -= 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 argv += 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 } else
87
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
293 if ( (argc >= 3) && (strcmp(argv[1], "-width") == 0) ) {
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
294 w = atoi(argv[2]);
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
295 argc -= 2;
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
296 argv += 2;
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
297 } else
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
298 if ( (argc >= 3) && (strcmp(argv[1], "-height") == 0) ) {
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
299 h = atoi(argv[2]);
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
300 argc -= 2;
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
301 argv += 2;
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
302 } else
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 if ( (argc >= 3) && (strcmp(argv[1], "-bpp") == 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 video_bpp = atoi(argv[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 argc -= 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 argv += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 parsed = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 /* Set the icon -- this must be done before the first mode set */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 icon = LoadIconSurface("icon.bmp", &icon_mask);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 if ( icon != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 SDL_WM_SetIcon(icon, icon_mask);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 if ( icon_mask != NULL )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 free(icon_mask);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 /* Set the title bar */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 if ( argv[1] == NULL )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 title = "Testing 1.. 2.. 3...";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 title = argv[1];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 SDL_WM_SetCaption(title, "testwm");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 /* See if it's really set */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 SDL_WM_GetCaption(&title, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 if ( title )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 printf("Title was set to: %s\n", title);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 printf("No window title was set!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 /* Initialize the display */
87
3ef4bc90c388 Added -width and -height command line options
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
335 if ( SetVideoMode(w, h) < 0 ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 /* Set an event filter that discards everything but QUIT */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 SDL_SetEventFilter(FilterEvents);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 /* Ignore key up events, they don't even get filtered */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 SDL_EventState(SDL_KEYUP, SDL_IGNORE);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 /* Loop, waiting for QUIT */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 while ( SDL_WaitEvent(&event) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 switch (event.type) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 case SDL_VIDEORESIZE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 printf("Got a resize event: %dx%d\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 event.resize.w, event.resize.h);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 SetVideoMode(event.resize.w, event.resize.h);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 case SDL_USEREVENT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 printf("Handling internal quit request\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 /* Fall through to the quit handler */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 case SDL_QUIT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 printf("Bye bye..\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 /* This should never happen */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 printf("Warning: Event %d wasn't filtered\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 event.type);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 return(255);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 }