fixed background and global border handling
authorHolger Schemel <info@artsoft.org>
Tue, 16 Jun 2015 20:17:09 +0000 (22:17 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 16 Jun 2015 20:17:09 +0000 (22:17 +0200)
src/init.c
src/tools.c
src/tools.h

index c30548161e2408565ff3ef6155217c6582c5f345..629133e8e61451eecb2b347069aff99590931d57 100644 (file)
@@ -5202,26 +5202,6 @@ void InitGfx()
   init_last = init;
 }
 
-void RedrawGlobalBorder()
-{
-  int global_border_graphic =
-    (game_status == GAME_MODE_MAIN ? IMG_GLOBAL_BORDER_MAIN :
-     game_status == GAME_MODE_SCORES ? IMG_GLOBAL_BORDER_SCORES :
-     game_status == GAME_MODE_EDITOR ? IMG_GLOBAL_BORDER_EDITOR :
-     game_status == GAME_MODE_PLAYING ? IMG_GLOBAL_BORDER_PLAYING :
-     IMG_GLOBAL_BORDER);
-
-  Bitmap *global_border_bitmap =
-    (graphic_info[global_border_graphic].bitmap ?
-     graphic_info[global_border_graphic].bitmap :
-     graphic_info[IMG_GLOBAL_BORDER].bitmap);
-
-  BlitBitmap(global_border_bitmap, backbuffer,
-            0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
-
-  redraw_mask = REDRAW_ALL;
-}
-
 void InitGfxBackground()
 {
   fieldbuffer = bitmap_db_field;
index 1cf7f74305e25fbbc1c382382cff971e76765711..f76c8dceefedd097c65ccf9ea1f107cf4f5876f1 100644 (file)
@@ -687,6 +687,37 @@ void FadeSkipNextFadeOut()
   FadeExt(0, FADE_MODE_SKIP_FADE_OUT, FADE_TYPE_SKIP);
 }
 
+Bitmap *getBitmapFromGraphicOrDefault(int graphic, int default_graphic)
+{
+  boolean redefined = getImageListEntryFromImageID(graphic)->redefined;
+
+  return (graphic == IMG_UNDEFINED ? NULL :
+         graphic_info[graphic].bitmap != NULL || redefined ?
+         graphic_info[graphic].bitmap :
+         graphic_info[default_graphic].bitmap);
+}
+
+Bitmap *getBackgroundBitmap(int graphic)
+{
+  return getBitmapFromGraphicOrDefault(graphic, IMG_BACKGROUND);
+}
+
+Bitmap *getGlobalBorderBitmap(int graphic)
+{
+  return getBitmapFromGraphicOrDefault(graphic, IMG_GLOBAL_BORDER);
+}
+
+Bitmap *getGlobalBorderBitmapFromGameStatus()
+{
+  int graphic = (game_status == GAME_MODE_MAIN    ? IMG_GLOBAL_BORDER_MAIN :
+                game_status == GAME_MODE_SCORES  ? IMG_GLOBAL_BORDER_SCORES :
+                game_status == GAME_MODE_EDITOR  ? IMG_GLOBAL_BORDER_EDITOR :
+                game_status == GAME_MODE_PLAYING ? IMG_GLOBAL_BORDER_PLAYING :
+                IMG_GLOBAL_BORDER);
+
+  return getGlobalBorderBitmap(graphic);
+}
+
 void SetWindowBackgroundImageIfDefined(int graphic)
 {
   if (graphic_info[graphic].bitmap)
@@ -707,26 +738,17 @@ void SetDoorBackgroundImageIfDefined(int graphic)
 
 void SetWindowBackgroundImage(int graphic)
 {
-  SetWindowBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
-                           graphic_info[graphic].bitmap ?
-                           graphic_info[graphic].bitmap :
-                           graphic_info[IMG_BACKGROUND].bitmap);
+  SetWindowBackgroundBitmap(getBackgroundBitmap(graphic));
 }
 
 void SetMainBackgroundImage(int graphic)
 {
-  SetMainBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
-                         graphic_info[graphic].bitmap ?
-                         graphic_info[graphic].bitmap :
-                         graphic_info[IMG_BACKGROUND].bitmap);
+  SetMainBackgroundBitmap(getBackgroundBitmap(graphic));
 }
 
 void SetDoorBackgroundImage(int graphic)
 {
-  SetDoorBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
-                         graphic_info[graphic].bitmap ?
-                         graphic_info[graphic].bitmap :
-                         graphic_info[IMG_BACKGROUND].bitmap);
+  SetDoorBackgroundBitmap(getBackgroundBitmap(graphic));
 }
 
 void SetPanelBackground()
@@ -786,23 +808,12 @@ static int vxsize_last = -1, vysize_last = -1;
 
 boolean CheckIfGlobalBorderHasChanged()
 {
-  int global_border_graphic;
-
   // if game status has not changed, global border has not changed either
   if (game_status == game_status_last)
     return FALSE;
 
-  global_border_graphic =
-    (game_status == GAME_MODE_MAIN ? IMG_GLOBAL_BORDER_MAIN :
-     game_status == GAME_MODE_SCORES ? IMG_GLOBAL_BORDER_SCORES :
-     game_status == GAME_MODE_EDITOR ? IMG_GLOBAL_BORDER_EDITOR :
-     game_status == GAME_MODE_PLAYING ? IMG_GLOBAL_BORDER_PLAYING :
-     IMG_GLOBAL_BORDER);
-
-  global_border_bitmap =
-    (graphic_info[global_border_graphic].bitmap ?
-     graphic_info[global_border_graphic].bitmap :
-     graphic_info[IMG_GLOBAL_BORDER].bitmap);
+  // determine and store new global border bitmap for current game status
+  global_border_bitmap = getGlobalBorderBitmapFromGameStatus();
 
   return (global_border_bitmap_last != global_border_bitmap);
 }
@@ -835,6 +846,23 @@ boolean CheckIfGlobalBorderRedrawIsNeeded()
   return FALSE;
 }
 
+void RedrawGlobalBorderFromBitmap(Bitmap *bitmap)
+{
+  if (bitmap)
+    BlitBitmap(bitmap, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+  else
+    ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
+}
+
+void RedrawGlobalBorder()
+{
+  Bitmap *bitmap = getGlobalBorderBitmapFromGameStatus();
+
+  RedrawGlobalBorderFromBitmap(bitmap);
+
+  redraw_mask = REDRAW_ALL;
+}
+
 static void RedrawGlobalBorderIfNeeded()
 {
   if (game_status == game_status_last)
@@ -846,12 +874,7 @@ static void RedrawGlobalBorderIfNeeded()
   if (CheckIfGlobalBorderRedrawIsNeeded())
   {
     // redraw global screen border (or clear, if defined to be empty)
-
-    if (global_border_bitmap)
-      BlitBitmap(global_border_bitmap, backbuffer,
-                0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
-    else
-      ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
+    RedrawGlobalBorderFromBitmap(global_border_bitmap);
 
     // copy previous playfield and door areas, if they are defined on both
     // previous and current screen and if they still have the same size
index 71b4f01af7c8b85ab3480070ecaf683b2ad97413..8c8f0184be78b34e4969cc6197d71e3a910c5072 100644 (file)
@@ -107,6 +107,7 @@ void DrawBackground(int, int, int, int);
 void DrawBackgroundForFont(int, int, int, int, int);
 void DrawBackgroundForGraphic(int, int, int, int, int);
 boolean CheckIfGlobalBorderHasChanged();
+void RedrawGlobalBorder();
 
 void MarkTileDirty(int, int);
 void SetBorderElement();