rnd-20030404-2-src
[rocksndiamonds.git] / src / libgame / system.c
index 680ff2d51ff568024693f9b53c4b4ab5536e3d42..0e0bb333e4afa28af362af8ddcf671e81fa53134 100644 (file)
@@ -311,7 +311,6 @@ inline void CloseVideoDisplay(void)
 #if defined(TARGET_SDL)
   SDL_QuitSubSystem(SDL_INIT_VIDEO);
 #else
-
   if (display)
     XCloseDisplay(display);
 #endif
@@ -349,36 +348,9 @@ inline Bitmap *CreateBitmap(int width, int height, int depth)
   int real_depth = GetRealDepth(depth);
 
 #ifdef TARGET_SDL
-  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);
-
-  new_bitmap->surface = surface_native;
+  SDLCreateBitmapContent(new_bitmap, width, height, real_depth);
 #else
-  Pixmap pixmap;
-
-  if ((pixmap = XCreatePixmap(display, window->drawable,
-                             width, height, real_depth))
-      == None)
-    Error(ERR_EXIT, "cannot create pixmap");
-
-  new_bitmap->drawable = pixmap;
-
-  if (window == NULL)
-    Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first");
-
-  new_bitmap->gc = window->gc;
-
-  new_bitmap->line_gc[0] = window->line_gc[0];
-  new_bitmap->line_gc[1] = window->line_gc[1];
+  X11CreateBitmapContent(new_bitmap, width, height, real_depth);
 #endif
 
   new_bitmap->width = width;
@@ -393,28 +365,9 @@ inline static void FreeBitmapPointers(Bitmap *bitmap)
     return;
 
 #ifdef TARGET_SDL
-  if (bitmap->surface)
-    SDL_FreeSurface(bitmap->surface);
-  if (bitmap->surface_masked)
-    SDL_FreeSurface(bitmap->surface_masked);
-  bitmap->surface = NULL;
-  bitmap->surface_masked = NULL;
+  SDLFreeBitmapPointers(bitmap);
 #else
-  /* The X11 version seems to have a memory leak here -- although
-     "XFreePixmap()" is called, the corresponding memory seems not
-     to be freed (according to "ps"). The SDL version apparently
-     does not have this problem. */
-
-  if (bitmap->drawable)
-    XFreePixmap(display, bitmap->drawable);
-  if (bitmap->clip_mask)
-    XFreePixmap(display, bitmap->clip_mask);
-  if (bitmap->stored_clip_gc)
-    XFreeGC(display, bitmap->stored_clip_gc);
-  /* the other GCs are only pointers to GCs used elsewhere */
-  bitmap->drawable = None;
-  bitmap->clip_mask = None;
-  bitmap->stored_clip_gc = None;
+  X11FreeBitmapPointers(bitmap);
 #endif
 
   if (bitmap->source_filename)
@@ -510,7 +463,7 @@ inline void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height,
 
 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
 {
-  FillRectangle(bitmap, x, y, width, height, BlackPixel(display, screen));
+  FillRectangle(bitmap, x, y, width, height, BLACK_PIXEL);
 }
 
 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
@@ -594,10 +547,9 @@ inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
                                int to_x, int to_y)
 {
 #ifdef TARGET_SDL
-  SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
+  SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
 #else
-  XSetForeground(display, bitmap->gc, WhitePixel(display, screen));
-  XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y);
+  X11DrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
 #endif
 }