rnd-20131202-1-src
[rocksndiamonds.git] / src / libgame / sdl.c
index 4d9c5462c2a66c679def5efb90072b811d865e1f..b9309408a4d1966ea687f6fa0db5b7d04fb64aa4 100644 (file)
@@ -85,7 +85,7 @@ static void SDLSetWindowIcon(char *basename)
   }
 
   /* set transparent color */
-  SDL_SetColorKey(surface, SDL_SRCCOLORKEY,
+  SDL_SetColorKey(surface, SET_TRANSPARENT_PIXEL,
                  SDL_MapRGB(surface->format, 0x00, 0x00, 0x00));
 
   SDL_WM_SetIcon(surface, NULL);
@@ -140,6 +140,13 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
   fullscreen_xoffset = (fullscreen_width  - video.width)  / 2;
   fullscreen_yoffset = (fullscreen_height - video.height) / 2;
 
+#if 1
+  checked_free(video.fullscreen_modes);
+
+  video.fullscreen_modes = NULL;
+  video.fullscreen_mode_current = NULL;
+#endif
+
   /* get available hardware supported fullscreen modes */
   modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
 
@@ -228,7 +235,11 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
      should never be drawn to directly, it would do no harm nevertheless. */
 
   /* create additional (symbolic) buffer for double-buffering */
+#if 1
+  ReCreateBitmap(window, video.width, video.height, video.depth);
+#else
   *window = CreateBitmap(video.width, video.height, video.depth);
+#endif
 }
 
 boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
@@ -241,6 +252,10 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   if (*backbuffer == NULL)
     *backbuffer = CreateBitmapStruct();
 
+  /* (real bitmap might be larger in fullscreen mode with video offsets) */
+  (*backbuffer)->width  = video.width;
+  (*backbuffer)->height = video.height;
+
   if (fullscreen && !video.fullscreen_enabled && video.fullscreen_available)
   {
     setFullscreenParameters(setup.fullscreen_mode);
@@ -292,10 +307,30 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
       (*backbuffer)->surface = new_surface;
 
       video.fullscreen_enabled = FALSE;
+
       success = TRUE;
     }
   }
 
+#if 1
+  SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
+
+#if defined(PLATFORM_WIN32)
+  {
+    SDL_SysWMinfo wminfo;
+    HWND hwnd;
+
+    SDL_VERSION(&wminfo.version);
+    SDL_GetWMInfo(&wminfo);
+
+    hwnd = wminfo.window;
+
+    DragAcceptFiles(hwnd, TRUE);
+  }
+#endif
+#endif
+
+
   return success;
 }
 
@@ -402,8 +437,17 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
   int src_x = x, src_y = y;
   int dst_x = x, dst_y = y;
   unsigned int time_last, time_current;
-  float alpha;
-  int alpha_final;
+
+  /* check if screen size has changed */
+  if (surface_source != NULL && (video.width  != surface_source->w ||
+                                video.height != surface_source->h))
+  {
+    SDL_FreeSurface(surface_source);
+    SDL_FreeSurface(surface_target);
+    SDL_FreeSurface(surface_black);
+
+    initialization_needed = TRUE;
+  }
 
   src_rect.x = src_x;
   src_rect.y = src_y;
@@ -498,6 +542,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
     int ypos[melt_columns];
     int max_steps = height / 8 + 32;
     int steps_done = 0;
+    float steps = 0;
     int i;
 
     SDL_BlitSurface(surface_source, &src_rect, surface_screen, &dst_rect);
@@ -520,7 +565,6 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
 
     while (!done)
     {
-      float steps;
       int steps_final;
 
       time_last = time_current;
@@ -610,6 +654,9 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
   }
   else
   {
+    float alpha;
+    int alpha_final;
+
     for (alpha = 0.0; alpha < 255.0;)
     {
       time_last = time_current;
@@ -1287,12 +1334,17 @@ int zoomSurfaceRGBA_scaleDownBy2(SDL_Surface *src, SDL_Surface *dst)
 {
   int x, y;
   tColorRGBA *sp, *csp, *dp;
-  int sgap, dgap;
+#if 0
+  int sgap;
+#endif
+  int dgap;
 
   /* pointer setup */
   sp = csp = (tColorRGBA *) src->pixels;
   dp = (tColorRGBA *) dst->pixels;
+#if 0
   sgap = src->pitch - src->w * 4;
+#endif
   dgap = dst->pitch - dst->w * 4;
 
   for (y = 0; y < dst->h; y++)
@@ -1339,7 +1391,10 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst)
 {
   int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy;
   tColorRGBA *sp, *csp, *dp;
-  int sgap, dgap;
+#if 0
+  int sgap;
+#endif
+  int dgap;
 
   /* use specialized zoom function when scaling down to exactly half size */
   if (src->w == 2 * dst->w &&
@@ -1378,7 +1433,9 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst)
   /* pointer setup */
   sp = csp = (tColorRGBA *) src->pixels;
   dp = (tColorRGBA *) dst->pixels;
+#if 0
   sgap = src->pitch - src->w * 4;
+#endif
   dgap = dst->pitch - dst->w * 4;
 
   csay = say;
@@ -1636,6 +1693,8 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
+  UPDATE_BUSY_STATE();
+
   /* create native non-transparent surface for current image */
   if ((new_bitmap->surface = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
   {
@@ -1644,8 +1703,10 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
+  UPDATE_BUSY_STATE();
+
   /* create native transparent surface for current image */
-  SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
+  SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL,
                  SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
   if ((new_bitmap->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
   {
@@ -1654,6 +1715,8 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
+  UPDATE_BUSY_STATE();
+
   /* free temporary surface */
   SDL_FreeSurface(sdl_image_tmp);
 
@@ -1780,6 +1843,36 @@ void SDLNextEvent(Event *event)
   }
 }
 
+void SDLHandleWindowManagerEvent(Event *event)
+{
+#if defined(PLATFORM_WIN32)
+  SDL_SysWMEvent *syswmevent = (SDL_SysWMEvent *)event;
+  SDL_SysWMmsg *syswmmsg = (SDL_SysWMmsg *)(syswmevent->msg);
+
+  if (syswmmsg->msg == WM_DROPFILES)
+  {
+    HDROP hdrop = (HDROP)syswmmsg->wParam;
+    int i, num_files;
+
+    printf("::: SDL_SYSWMEVENT:\n");
+
+    num_files = DragQueryFile(hdrop, 0xffffffff, NULL, 0);
+
+    for (i = 0; i < num_files; i++)
+    {
+      int buffer_len = DragQueryFile(hdrop, i, NULL, 0);
+      char buffer[buffer_len + 1];
+
+      DragQueryFile(hdrop, i, buffer, buffer_len + 1);
+
+      printf("::: - '%s'\n", buffer);
+    }
+
+    DragFinish((HDROP)syswmmsg->wParam);
+  }
+#endif
+}
+
 
 /* ========================================================================= */
 /* joystick functions                                                        */