comparison src/SDL_compat.c @ 1731:875c3cf1a12c SDL-1.3

SDL_PushEvent() calls the event filter code, and has a return value to tell whether or not the event was actually pushed. SDL_GetEventFilter() now returns an SDL_bool instead of the filter function.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 08 Jul 2006 20:07:08 +0000
parents 6c63fc2bd986
children 0b1070f2f94d
comparison
equal deleted inserted replaced
1730:e70477157db9 1731:875c3cf1a12c
150 if (modes) { 150 if (modes) {
151 modes[nmodes] = NULL; 151 modes[nmodes] = NULL;
152 } 152 }
153 return modes; 153 return modes;
154 } 154 }
155
156 static SDL_EventFilter orig_eventfilter;
157 static void *orig_eventfilterparam;
158 155
159 static int 156 static int
160 SDL_CompatEventFilter(void *userdata, SDL_Event * event) 157 SDL_CompatEventFilter(void *userdata, SDL_Event * event)
161 { 158 {
162 SDL_Event fake; 159 SDL_Event fake;
267 SDL_PushEvent(&fake); 264 SDL_PushEvent(&fake);
268 break; 265 break;
269 } 266 }
270 267
271 } 268 }
272 if (orig_eventfilter) { 269 return 1;
273 return orig_eventfilter(orig_eventfilterparam, event);
274 } else {
275 return 1;
276 }
277 } 270 }
278 271
279 static int 272 static int
280 SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette) 273 SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette)
281 { 274 {
289 return SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors); 282 return SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors);
290 } 283 }
291 return 0; 284 return 0;
292 } 285 }
293 286
287 static void
288 GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
289 {
290 const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
291 const char *center = SDL_getenv("SDL_VIDEO_CENTERED");
292 if (window) {
293 if (SDL_sscanf(window, "%d,%d", x, y) == 2) {
294 return;
295 }
296 if (SDL_strcmp(window, "center") == 0) {
297 center = window;
298 }
299 }
300 if (center) {
301 const SDL_DisplayMode *current = SDL_GetDesktopDisplayMode();
302 *x = (current->w - w) / 2;
303 *y = (current->h - h) / 2;
304 }
305 }
306
294 SDL_Surface * 307 SDL_Surface *
295 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) 308 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
296 { 309 {
297 SDL_EventFilter filter; 310 SDL_EventFilter filter;
298 void *filterparam; 311 void *filterparam;
299 const SDL_DisplayMode *desktop_mode; 312 const SDL_DisplayMode *desktop_mode;
300 SDL_DisplayMode mode; 313 SDL_DisplayMode mode;
314 int window_x = SDL_WINDOWPOS_UNDEFINED;
315 int window_y = SDL_WINDOWPOS_UNDEFINED;
301 Uint32 window_flags; 316 Uint32 window_flags;
302 Uint32 desktop_format; 317 Uint32 desktop_format;
303 Uint32 desired_format; 318 Uint32 desired_format;
304 Uint32 surface_flags; 319 Uint32 surface_flags;
305 320
319 SDL_DelPaletteWatch(SDL_VideoSurface->format->palette, 334 SDL_DelPaletteWatch(SDL_VideoSurface->format->palette,
320 SDL_VideoPaletteChanged, NULL); 335 SDL_VideoPaletteChanged, NULL);
321 SDL_FreeSurface(SDL_VideoSurface); 336 SDL_FreeSurface(SDL_VideoSurface);
322 SDL_VideoSurface = NULL; 337 SDL_VideoSurface = NULL;
323 } 338 }
339 if (SDL_VideoWindow) {
340 SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
341 }
324 SDL_DestroyWindow(SDL_VideoWindow); 342 SDL_DestroyWindow(SDL_VideoWindow);
325 343
326 /* Set up the event filter */ 344 /* Set up the event filter */
327 filter = SDL_GetEventFilter(&filterparam); 345 if (!SDL_GetEventFilter(NULL, NULL)) {
328 if (filter != SDL_CompatEventFilter) { 346 SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
329 orig_eventfilter = filter; 347 }
330 orig_eventfilterparam = filterparam;
331 }
332 SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
333 348
334 /* Create a new window */ 349 /* Create a new window */
335 window_flags = SDL_WINDOW_SHOWN; 350 window_flags = SDL_WINDOW_SHOWN;
336 if (flags & SDL_FULLSCREEN) { 351 if (flags & SDL_FULLSCREEN) {
337 window_flags |= SDL_WINDOW_FULLSCREEN; 352 window_flags |= SDL_WINDOW_FULLSCREEN;
343 window_flags |= SDL_WINDOW_RESIZABLE; 358 window_flags |= SDL_WINDOW_RESIZABLE;
344 } 359 }
345 if (flags & SDL_NOFRAME) { 360 if (flags & SDL_NOFRAME) {
346 window_flags |= SDL_WINDOW_BORDERLESS; 361 window_flags |= SDL_WINDOW_BORDERLESS;
347 } 362 }
363 if (SDL_getenv("SDL_WINDOW_POS")) {
364 }
365 GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
348 SDL_VideoWindow = 366 SDL_VideoWindow =
349 SDL_CreateWindow(wm_title, SDL_WINDOWPOS_UNDEFINED, 367 SDL_CreateWindow(wm_title, window_x, window_y, width, height,
350 SDL_WINDOWPOS_UNDEFINED, width, height,
351 window_flags); 368 window_flags);
352 if (!SDL_VideoWindow) { 369 if (!SDL_VideoWindow) {
353 return NULL; 370 return NULL;
354 } 371 }
355 372