comparison src/SDL_compat.c @ 1669:9857d21967bb SDL-1.3

The test programs compile again. The dummy video driver is partially functional now.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 05:08:33 +0000
parents 4da1ee79c9af
children eef792d31de8
comparison
equal deleted inserted replaced
1668:4da1ee79c9af 1669:9857d21967bb
127 modes[nmodes] = NULL; 127 modes[nmodes] = NULL;
128 } 128 }
129 return modes; 129 return modes;
130 } 130 }
131 131
132 static int (*orig_eventfilter) (const SDL_Event * event);
133
134 static int
135 SDL_CompatEventFilter(const SDL_Event * event)
136 {
137 SDL_Event fake;
138
139 switch (event->type) {
140 case SDL_WINDOWEVENT:
141 switch (event->window.event) {
142 case SDL_WINDOWEVENT_RESIZED:
143 fake.type = SDL_VIDEORESIZE;
144 fake.resize.w = event->window.data1;
145 fake.resize.h = event->window.data2;
146 SDL_PushEvent(&fake);
147 break;
148 case SDL_WINDOWEVENT_MINIMIZED:
149 fake.type = SDL_ACTIVEEVENT;
150 fake.active.gain = 0;
151 fake.active.state = SDL_APPACTIVE;
152 SDL_PushEvent(&fake);
153 break;
154 case SDL_WINDOWEVENT_RESTORED:
155 fake.type = SDL_ACTIVEEVENT;
156 fake.active.gain = 1;
157 fake.active.state = SDL_APPACTIVE;
158 SDL_PushEvent(&fake);
159 break;
160 case SDL_WINDOWEVENT_ENTER:
161 fake.type = SDL_ACTIVEEVENT;
162 fake.active.gain = 1;
163 fake.active.state = SDL_APPMOUSEFOCUS;
164 SDL_PushEvent(&fake);
165 break;
166 case SDL_WINDOWEVENT_LEAVE:
167 fake.type = SDL_ACTIVEEVENT;
168 fake.active.gain = 0;
169 fake.active.state = SDL_APPMOUSEFOCUS;
170 SDL_PushEvent(&fake);
171 break;
172 case SDL_WINDOWEVENT_FOCUS_GAINED:
173 fake.type = SDL_ACTIVEEVENT;
174 fake.active.gain = 1;
175 fake.active.state = SDL_APPINPUTFOCUS;
176 SDL_PushEvent(&fake);
177 break;
178 case SDL_WINDOWEVENT_FOCUS_LOST:
179 fake.type = SDL_ACTIVEEVENT;
180 fake.active.gain = 1;
181 fake.active.state = SDL_APPINPUTFOCUS;
182 SDL_PushEvent(&fake);
183 break;
184 }
185 }
186 return orig_eventfilter(event);
187 }
188
132 SDL_Surface * 189 SDL_Surface *
133 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) 190 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
134 { 191 {
192 int (*filter) (const SDL_Event * event);
193 const SDL_DisplayMode *desktop_mode;
135 SDL_DisplayMode mode; 194 SDL_DisplayMode mode;
136 int i; 195 int i;
137 Uint32 window_flags; 196 Uint32 window_flags;
138 Uint32 desktop_format; 197 Uint32 desktop_format;
139 Uint32 desired_format; 198 Uint32 desired_format;
145 } 204 }
146 205
147 /* Destroy existing window */ 206 /* Destroy existing window */
148 SDL_DestroyWindow(window); 207 SDL_DestroyWindow(window);
149 208
209 /* Set up the event filter */
210 filter = SDL_GetEventFilter();
211 if (filter != SDL_CompatEventFilter) {
212 orig_eventfilter = filter;
213 }
214 SDL_SetEventFilter(SDL_CompatEventFilter);
215
150 /* Create a new window */ 216 /* Create a new window */
151 window_flags = SDL_WINDOW_SHOWN; 217 window_flags = SDL_WINDOW_SHOWN;
152 if (flags & SDL_FULLSCREEN) { 218 if (flags & SDL_FULLSCREEN) {
153 window_flags |= SDL_WINDOW_FULLSCREEN; 219 window_flags |= SDL_WINDOW_FULLSCREEN;
154 } 220 }
165 if (!window) { 231 if (!window) {
166 return NULL; 232 return NULL;
167 } 233 }
168 234
169 /* Set up the desired display mode */ 235 /* Set up the desired display mode */
170 desktop_format = SDL_GetDesktopDisplayMode()->format; 236 desktop_mode = SDL_GetDesktopDisplayMode();
171 if ((bpp == SDL_BITSPERPIXEL(desktop_format)) || 237 desktop_format = desktop_mode->format;
172 (desktop_format && (flags & SDL_ANYFORMAT))) { 238 if (desktop_format && ((flags & SDL_ANYFORMAT)
239 || (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
173 desired_format = desktop_format; 240 desired_format = desktop_format;
174 } else { 241 } else {
175 switch (bpp) { 242 switch (bpp) {
243 case 0:
244 if (desktop_format) {
245 desired_format = desktop_format;
246 } else {
247 desired_format = SDL_PixelFormat_RGB888;
248 }
249 break;
176 case 8: 250 case 8:
177 desired_format = SDL_PixelFormat_Index8; 251 desired_format = SDL_PixelFormat_Index8;
178 break; 252 break;
179 case 15: 253 case 15:
180 desired_format = SDL_PixelFormat_RGB555; 254 desired_format = SDL_PixelFormat_RGB555;
202 if (flags & SDL_FULLSCREEN) { 276 if (flags & SDL_FULLSCREEN) {
203 if (!SDL_GetClosestDisplayMode(&mode, &mode)) { 277 if (!SDL_GetClosestDisplayMode(&mode, &mode)) {
204 return NULL; 278 return NULL;
205 } 279 }
206 } else { 280 } else {
207 mode = *SDL_GetDesktopDisplayMode(); 281 if (desktop_format) {
282 mode.format = desktop_format;
283 }
284 if (desktop_mode->w && desktop_mode->h) {
285 mode.w = desktop_mode->w;
286 mode.h = desktop_mode->h;
287 }
288 mode.refresh_rate = desktop_mode->refresh_rate;
208 } 289 }
209 if (SDL_SetDisplayMode(&mode) < 0) { 290 if (SDL_SetDisplayMode(&mode) < 0) {
210 return NULL; 291 return NULL;
211 } 292 }
212 293