X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fsystem.c;h=d0c948a64dd360e59e43c94351715e845144e8d7;hb=7d958613de0b14e460ebca1a651b73cfadf9213c;hp=6b85ccb38c219d7fe790031bdbf817a355c179d6;hpb=41cfe645942062496cd063eb46e17d677a76c645;p=rocksndiamonds.git diff --git a/src/system.c b/src/system.c index 6b85ccb3..d0c948a6 100644 --- a/src/system.c +++ b/src/system.c @@ -13,6 +13,61 @@ ***********************************************************/ #include "main.h" +#include "misc.h" + +inline void InitEventFilter(EventFilter filter_function) +{ +#ifdef USE_SDL_LIBRARY + /* set event filter to filter out certain events */ + SDL_SetEventFilter(filter_function); +#endif +} + +inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window) +{ +#ifdef USE_SDL_LIBRARY + SDLInitBufferedDisplay(backbuffer, window); +#else + X11InitBufferedDisplay(backbuffer, window); +#endif +} + +inline int GetDisplayDepth(void) +{ +#ifdef USE_SDL_LIBRARY + return SDL_GetVideoSurface()->format->BitsPerPixel; +#else + return XDefaultDepth(display, screen); +#endif +} + +inline Bitmap CreateBitmap(int width, int height, int depth) +{ + int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth); + +#ifdef USE_SDL_LIBRARY + SDL_Surface *surface_tmp, *surface_native; + + if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, + real_depth, 0, 0, 0, 0)) + == NULL) + Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); + + if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); + + SDL_FreeSurface(surface_tmp); + + return surface_native; +#else + Pixmap pixmap; + + if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth))) + Error(ERR_EXIT, "cannot create pixmap"); + + return pixmap; +#endif +} inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height) { @@ -84,7 +139,7 @@ inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y, } /* execute all pending screen drawing operations */ -inline void FlushDisplay() +inline void FlushDisplay(void) { #ifndef USE_SDL_LIBRARY XFlush(display); @@ -92,14 +147,14 @@ inline void FlushDisplay() } /* execute and wait for all pending screen drawing operations */ -inline void SyncDisplay() +inline void SyncDisplay(void) { #ifndef USE_SDL_LIBRARY XSync(display, FALSE); #endif } -inline void KeyboardAutoRepeatOn() +inline void KeyboardAutoRepeatOn(void) { #ifdef USE_SDL_LIBRARY SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2, @@ -110,7 +165,7 @@ inline void KeyboardAutoRepeatOn() #endif } -inline void KeyboardAutoRepeatOff() +inline void KeyboardAutoRepeatOff(void) { #ifdef USE_SDL_LIBRARY SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); @@ -137,7 +192,7 @@ inline boolean PointerInWindow(DrawWindow window) #endif } -inline boolean PendingEvent() +inline boolean PendingEvent(void) { #ifdef USE_SDL_LIBRARY return (SDL_PollEvent(NULL) ? TRUE : FALSE); @@ -158,11 +213,24 @@ inline void NextEvent(Event *event) inline Key GetEventKey(KeyEvent *event, boolean with_modifiers) { #ifdef USE_SDL_LIBRARY +#if 0 + printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n", + (int)event->keysym.unicode, + (int)event->keysym.sym, + (int)SDL_GetModState()); +#endif + if (with_modifiers && event->keysym.unicode != 0) return event->keysym.unicode; else return event->keysym.sym; #else +#if 0 + printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n", + (int)XLookupKeysym(event, event->state), + (int)XLookupKeysym(event, 0)); +#endif + if (with_modifiers) return XLookupKeysym(event, event->state); else @@ -170,7 +238,37 @@ inline Key GetEventKey(KeyEvent *event, boolean with_modifiers) #endif } -inline void dummy() +inline boolean SetVideoMode(void) +{ +#ifdef USE_SDL_LIBRARY + return SDLSetVideoMode(&backbuffer, &window); +#else + boolean success = TRUE; + + if (setup.fullscreen && fullscreen_available) + { + Error(ERR_WARN, "fullscreen not available in X11 version"); + + /* display error message only once */ + fullscreen_available = FALSE; + + success = FALSE; + } + + return success; +#endif +} + +inline void ChangeVideoModeIfNeeded(void) +{ +#ifdef USE_SDL_LIBRARY + if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) || + (!setup.fullscreen && fullscreen_enabled)) + SetVideoMode(); +#endif +} + +inline void dummy(void) { #ifdef USE_SDL_LIBRARY #else