rnd-20001204-1-src
[rocksndiamonds.git] / src / libgame / sdl.c
index e732b11107913b0468d85476ec387d00b648b998..533d0366b5fd248953c6eced78a0a1ee14deed9b 100644 (file)
@@ -1,20 +1,21 @@
 /***********************************************************
-*  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
+* Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-*  ©1995 Artsoft Development                               *
-*        Holger Schemel                                    *
-*        33659 Bielefeld-Senne                             *
-*        Telefon: (0521) 493245                            *
-*        eMail: aeglos@valinor.owl.de                      *
-*               aeglos@uni-paderborn.de                    *
-*               q99492@pbhrzx.uni-paderborn.de             *
+* (c) 1994-2000 Artsoft Entertainment                      *
+*               Holger Schemel                             *
+*               Detmolder Strasse 189                      *
+*               33604 Bielefeld                            *
+*               Germany                                    *
+*               e-mail: info@artsoft.org                   *
 *----------------------------------------------------------*
-*  sdl.c                                                   *
+* sdl.c                                                    *
 ***********************************************************/
 
-#include "libgame.h"
+#include "system.h"
+#include "misc.h"
 
-#ifdef TARGET_SDL
+
+#if defined(TARGET_SDL)
 
 inline void SDLInitVideoDisplay(void)
 {
@@ -65,10 +66,11 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen)
   {
     /* switch display to fullscreen mode, if available */
     DrawWindow window_old = *backbuffer;
-    DrawWindow window_new;
+    DrawWindow window_new = CreateBitmapStruct();
 
-    if ((window_new = SDL_SetVideoMode(video.width, video.height, video.depth,
-                                      surface_flags)) == NULL)
+    if ((window_new->surface = SDL_SetVideoMode(video.width, video.height,
+                                               video.depth, surface_flags))
+       == NULL)
     {
       /* switching display to fullscreen mode failed */
       Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
@@ -80,7 +82,7 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen)
     else
     {
       if (window_old)
-       SDL_FreeSurface(window_old);
+       FreeBitmap(window_old);
       *backbuffer = window_new;
 
       video.fullscreen_enabled = TRUE;
@@ -92,10 +94,11 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen)
   {
     /* switch display to window mode */
     DrawWindow window_old = *backbuffer;
-    DrawWindow window_new;
+    DrawWindow window_new = CreateBitmapStruct();
 
-    if ((window_new = SDL_SetVideoMode(video.width, video.height, video.depth,
-                                      surface_flags)) == NULL)
+    if ((window_new->surface = SDL_SetVideoMode(video.width, video.height,
+                                               video.depth, surface_flags))
+       == NULL)
     {
       /* switching display to window mode failed -- should not happen */
       Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
@@ -105,7 +108,7 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen)
     else
     {
       if (window_old)
-       SDL_FreeSurface(window_old);
+       FreeBitmap(window_old);
       *backbuffer = window_new;
 
       video.fullscreen_enabled = FALSE;
@@ -116,12 +119,12 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen)
   return success;
 }
 
-inline void SDLCopyArea(SDL_Surface *src_surface, SDL_Surface *dst_surface,
+inline void SDLCopyArea(Bitmap src_bitmap, Bitmap dst_bitmap,
                        int src_x, int src_y,
                        int width, int height,
-                       int dst_x, int dst_y)
+                       int dst_x, int dst_y, int copy_mode)
 {
-  SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface);
+  Bitmap real_dst_bitmap = (dst_bitmap == window ? backbuffer : dst_bitmap);
   SDL_Rect src_rect, dst_rect;
 
   src_rect.x = src_x;
@@ -134,17 +137,19 @@ inline void SDLCopyArea(SDL_Surface *src_surface, SDL_Surface *dst_surface,
   dst_rect.w = width;
   dst_rect.h = height;
 
-  if (src_surface != backbuffer || dst_surface != window)
-    SDL_BlitSurface(src_surface, &src_rect, surface, &dst_rect);
+  if (src_bitmap != backbuffer || dst_bitmap != window)
+    SDL_BlitSurface((copy_mode == SDLCOPYAREA_MASKED ?
+                    src_bitmap->surface_masked : src_bitmap->surface),
+                   &src_rect, real_dst_bitmap->surface, &dst_rect);
 
-  if (dst_surface == window)
-    SDL_UpdateRect(backbuffer, dst_x, dst_y, width, height);
+  if (dst_bitmap == window)
+    SDL_UpdateRect(backbuffer->surface, dst_x, dst_y, width, height);
 }
 
-inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y,
+inline void SDLFillRectangle(Bitmap dst_bitmap, int x, int y,
                             int width, int height, unsigned int color)
 {
-  SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface);
+  Bitmap real_dst_bitmap = (dst_bitmap == window ? backbuffer : dst_bitmap);
   SDL_Rect rect;
   unsigned int color_r = (color >> 16) && 0xff;
   unsigned int color_g = (color >>  8) && 0xff;
@@ -155,11 +160,12 @@ inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y,
   rect.w = width;
   rect.h = height;
 
-  SDL_FillRect(surface, &rect,
-              SDL_MapRGB(surface->format, color_r, color_g, color_b));
+  SDL_FillRect(real_dst_bitmap->surface, &rect,
+              SDL_MapRGB(real_dst_bitmap->surface->format,
+                         color_r, color_g, color_b));
 
-  if (dst_surface == window)
-    SDL_UpdateRect(backbuffer, x, y, width, height);
+  if (dst_bitmap == window)
+    SDL_UpdateRect(backbuffer->surface, x, y, width, height);
 }
 
 inline void SDLDrawSimpleLine(SDL_Surface *surface, int from_x, int from_y,