fixed bug where player actions were incorrectly mapped in single player mode (also...
[rocksndiamonds.git] / src / libgame / sdl.c
index 628ee38dc4b0da4a7ecd09158259945198bf4ca7..3ab03783ba16a33a1da73c7c76362b368118368b 100644 (file)
@@ -27,6 +27,7 @@
 static SDL_Window *sdl_window = NULL;
 static SDL_Renderer *sdl_renderer = NULL;
 static SDL_Texture *sdl_texture = NULL;
+static boolean fullscreen_enabled = FALSE;
 
 #define USE_RENDERER   TRUE
 #endif
@@ -503,7 +504,6 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
   SDL_Surface *new_surface = NULL;
 
 #if defined(TARGET_SDL2)
-  static boolean fullscreen_enabled = FALSE;
   int surface_flags_window = SURFACE_FLAGS | SDL_WINDOW_RESIZABLE;
 #if USE_DESKTOP_FULLSCREEN
   int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN_DESKTOP;
@@ -527,9 +527,8 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
 
 #if defined(TARGET_SDL2)
 
-  // store if initial screen mode on game start is fullscreen mode
-  if (sdl_window == NULL)
-    video.fullscreen_initial = fullscreen;
+  // store if initial screen mode is fullscreen mode when changing screen size
+  video.fullscreen_initial = fullscreen;
 
 #if USE_RENDERER
   float window_scaling_factor = (float)setup.window_scaling_percent / 100;
@@ -833,9 +832,9 @@ void SDLSetWindowFullscreen(boolean fullscreen)
 #endif
 
   if (SDL_SetWindowFullscreen(sdl_window, flags) == 0)
-    video.fullscreen_enabled = fullscreen;
+    video.fullscreen_enabled = fullscreen_enabled = fullscreen;
 
-  // if game started in fullscreen mode, window will also get fullscreen size
+  // if screen size was changed in fullscreen mode, correct desktop window size
   if (!fullscreen && video.fullscreen_initial)
   {
     SDLSetWindowScaling(setup.window_scaling_percent);
@@ -1202,7 +1201,65 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
       }
     }
   }
-  else
+  else if (fade_mode == FADE_MODE_CURTAIN)
+  {
+    float xx;
+    int xx_final;
+    int xx_size = width / 2;
+
+    SDL_BlitSurface(surface_target, &src_rect, surface_screen, &dst_rect);
+#if defined(TARGET_SDL2)
+    SDL_SetSurfaceBlendMode(surface_source, SDL_BLENDMODE_NONE);
+#else
+    SDL_SetAlpha(surface_source, 0, 0);                /* disable alpha blending */
+#endif
+
+    for (xx = 0; xx < xx_size;)
+    {
+      time_last = time_current;
+      time_current = SDL_GetTicks();
+      xx += xx_size * ((float)(time_current - time_last) / fade_delay);
+      xx_final = MIN(MAX(0, xx), xx_size);
+
+      src_rect.x = src_x;
+      src_rect.y = src_y;
+      src_rect.w = width;
+      src_rect.h = height;
+
+      dst_rect.x = dst_x;
+      dst_rect.y = dst_y;
+
+      /* draw new (target) image to screen buffer */
+      SDL_BlitSurface(surface_target, &src_rect, surface_screen, &dst_rect);
+
+      if (xx_final < xx_size)
+      {
+       src_rect.w = xx_size - xx_final;
+       src_rect.h = height;
+
+       /* draw old (source) image to screen buffer (left side) */
+
+       src_rect.x = src_x + xx_final;
+       dst_rect.x = dst_x;
+
+       SDL_BlitSurface(surface_source, &src_rect, surface_screen, &dst_rect);
+
+       /* draw old (source) image to screen buffer (right side) */
+
+       src_rect.x = src_x + xx_size;
+       dst_rect.x = dst_x + xx_size + xx_final;
+
+       SDL_BlitSurface(surface_source, &src_rect, surface_screen, &dst_rect);
+      }
+
+      if (draw_border_function != NULL)
+       draw_border_function();
+
+      /* only update the region of the screen that is affected from fading */
+      UpdateScreen(&dst_rect2);
+    }
+  }
+  else         /* fading in, fading out or cross-fading */
   {
     float alpha;
     int alpha_final;