rnd-20030218-3-src
[rocksndiamonds.git] / src / tools.c
index 5722e2528137a59a47f4b0bca72baf29a2795879..8ed2e29b604f1c462b048c66ef845fe6093a4918 100644 (file)
@@ -254,7 +254,7 @@ void BackToFront()
               MICROLEV_XPOS, MICROLEV_YPOS, MICROLEV_XSIZE, MICROLEV_YSIZE,
               MICROLEV_XPOS, MICROLEV_YPOS);
     BlitBitmap(backbuffer, window,
-              SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE,
+              SX, MICROLABEL_YPOS, SXSIZE, getFontHeight(FONT_SPECIAL_GAME),
               SX, MICROLABEL_YPOS);
     redraw_mask &= ~REDRAW_MICROLEVEL;
   }
@@ -279,7 +279,7 @@ void BackToFront()
       info1[0] = '\0';
 
     sprintf(text, "%.1f fps%s", global.frames_per_second, info1);
-    DrawTextExt(window, SX, SY, text, FS_SMALL, FC_YELLOW, FONT_OPAQUE);
+    DrawTextExt(window, SX, SY, text, FONT_DEFAULT_SMALL, FONT_OPAQUE);
   }
 
   FlushDisplay();
@@ -367,7 +367,7 @@ void SetMainBackgroundImage(int graphic)
   SetMainBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
                          graphic_info[graphic].bitmap ?
                          graphic_info[graphic].bitmap :
-                         graphic_info[IMG_BACKGROUND_DEFAULT].bitmap);
+                         graphic_info[IMG_BACKGROUND].bitmap);
 }
 
 void SetDoorBackgroundImage(int graphic)
@@ -375,7 +375,7 @@ void SetDoorBackgroundImage(int graphic)
   SetDoorBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL :
                          graphic_info[graphic].bitmap ?
                          graphic_info[graphic].bitmap :
-                         graphic_info[IMG_BACKGROUND_DEFAULT].bitmap);
+                         graphic_info[IMG_BACKGROUND].bitmap);
 }
 
 void DrawBackground(int dest_x, int dest_y, int width, int height)
@@ -426,7 +426,7 @@ void SetBorderElement()
   {
     for(x=0; x<lev_fieldx; x++)
     {
-      if (!IS_MASSIVE(Feld[x][y]))
+      if (!IS_INDESTRUCTIBLE(Feld[x][y]))
        BorderElement = EL_STEELWALL;
 
       if (y != 0 && y != lev_fieldy - 1 && x != lev_fieldx - 1)
@@ -959,16 +959,22 @@ void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
   int src_x = mini_startx + graphic_info[graphic].src_x / 2;
   int src_y = mini_starty + graphic_info[graphic].src_y / 2;
 
+#if 0
+  /* !!! not needed anymore, because of automatically created mini graphics */
   if (src_x + MINI_TILEX > src_bitmap->width ||
       src_y + MINI_TILEY > src_bitmap->height)
   {
     /* graphic of desired size seems not to be contained in this image;
        dirty workaround: get it from the middle of the normal sized image */
 
+    printf("::: using dirty workaround for %d (%d, %d)\n",
+          graphic, src_bitmap->width, src_bitmap->height);
+
     getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
     src_x += (TILEX / 2 - MINI_TILEX / 2);
     src_y += (TILEY / 2 - MINI_TILEY / 2);
   }
+#endif
 
   *bitmap = src_bitmap;
   *x = src_x;
@@ -1155,6 +1161,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
       frame = graphic_info[graphic].anim_frames - 1;
     }
   }
+#if 0
   else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING)
   {
     graphic = (element == EL_BD_AMOEBA ? IMG_BD_AMOEBA_PART1 :
@@ -1165,6 +1172,16 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
 
     graphic += (x + 2 * y + 4) % 4;
   }
+#endif
+
+#if 0
+  if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING)
+  {
+    if (Feld[lx][ly] == EL_AMOEBA_DRIPPING)
+      printf("---> %d -> %d / %d [%d]\n",
+            element, graphic, frame, GfxRandom[lx][ly]);
+  }
+#endif
 
   if (dx || dy)
     DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode);
@@ -1337,6 +1354,29 @@ void DrawCrumbledSand(int x, int y)
   }
 }
 
+static int getBorderElement(int x, int y)
+{
+  int border[7][2] =
+  {
+    { EL_STEELWALL_TOPLEFT,            EL_INVISIBLE_STEELWALL_TOPLEFT     },
+    { EL_STEELWALL_TOPRIGHT,           EL_INVISIBLE_STEELWALL_TOPRIGHT    },
+    { EL_STEELWALL_BOTTOMLEFT,         EL_INVISIBLE_STEELWALL_BOTTOMLEFT  },
+    { EL_STEELWALL_BOTTOMRIGHT,                EL_INVISIBLE_STEELWALL_BOTTOMRIGHT },
+    { EL_STEELWALL_VERTICAL,           EL_INVISIBLE_STEELWALL_VERTICAL    },
+    { EL_STEELWALL_HORIZONTAL,         EL_INVISIBLE_STEELWALL_HORIZONTAL  },
+    { EL_STEELWALL,                    EL_INVISIBLE_STEELWALL             }
+  };
+  int steel_type = (BorderElement == EL_STEELWALL ? 0 : 1);
+  int steel_position = (x == -1 && y == -1                     ? 0 :
+                       x == lev_fieldx && y == -1              ? 1 :
+                       x == -1 && y == lev_fieldy              ? 2 :
+                       x == lev_fieldx && y == lev_fieldy      ? 3 :
+                       x == -1 || x == lev_fieldx              ? 4 :
+                       y == -1 || y == lev_fieldy              ? 5 : 6);
+
+  return border[steel_position][steel_type];
+}
+
 void DrawScreenElement(int x, int y, int element)
 {
   DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
@@ -1359,7 +1399,7 @@ void DrawScreenField(int x, int y)
     if (lx < -1 || lx > lev_fieldx || ly < -1 || ly > lev_fieldy)
       element = EL_EMPTY;
     else
-      element = BorderElement;
+      element = getBorderElement(lx, ly);
 
     DrawScreenElement(x, y, element);
     return;
@@ -1478,29 +1518,7 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
   else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
     DrawMiniElement(sx, sy, Feld[x][y]);
   else
-  {
-    int steel_type, steel_position;
-    int border[6][2] =
-    {
-      { IMG_STEELWALL_TOPLEFT,         IMG_INVISIBLE_STEELWALL_TOPLEFT     },
-      { IMG_STEELWALL_TOPRIGHT,                IMG_INVISIBLE_STEELWALL_TOPRIGHT    },
-      { IMG_STEELWALL_BOTTOMLEFT,      IMG_INVISIBLE_STEELWALL_BOTTOMLEFT  },
-      { IMG_STEELWALL_BOTTOMRIGHT,     IMG_INVISIBLE_STEELWALL_BOTTOMRIGHT },
-      { IMG_STEELWALL_VERTICAL,                IMG_INVISIBLE_STEELWALL_VERTICAL    },
-      { IMG_STEELWALL_HORIZONTAL,      IMG_INVISIBLE_STEELWALL_HORIZONTAL  }
-    };
-
-    steel_type = (BorderElement == EL_STEELWALL ? 0 : 1);
-    steel_position = (x == -1 && y == -1                       ? 0 :
-                     x == lev_fieldx && y == -1                ? 1 :
-                     x == -1 && y == lev_fieldy                ? 2 :
-                     x == lev_fieldx && y == lev_fieldy        ? 3 :
-                     x == -1 || x == lev_fieldx                ? 4 :
-                     y == -1 || y == lev_fieldy                ? 5 : -1);
-
-    if (steel_position != -1)
-      DrawMiniGraphic(sx, sy, border[steel_position][steel_type]);
-  }
+    DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y)));
 }
 
 void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
@@ -1531,7 +1549,7 @@ void DrawMicroElement(int xpos, int ypos, int element)
 {
   Bitmap *src_bitmap;
   int src_x, src_y;
-  int graphic = el2img(element);
+  int graphic = el2preimg(element);
 
   getMicroGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
   BlitBitmap(src_bitmap, drawto, src_x, src_y, MICRO_TILEX, MICRO_TILEY,
@@ -1589,7 +1607,7 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
       else if (lx >= -1 && lx < lev_fieldx+1 && ly >= -1 && ly < lev_fieldy+1
               && BorderElement != EL_EMPTY)
        DrawMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY,
-                        BorderElement);
+                        getBorderElement(lx, ly));
     }
   }
 
@@ -1603,13 +1621,12 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
 #define MICROLABEL_IMPORTED_FROM       4
 #define MICROLABEL_LEVEL_IMPORT_INFO   5
 
-#define MAX_MICROLABEL_SIZE            (SXSIZE / FONT4_XSIZE)
-
 static void DrawMicroLevelLabelExt(int mode)
 {
-  char label_text[MAX_MICROLABEL_SIZE + 1];
+  char label_text[MAX_OUTPUT_LINESIZE + 1];
+  int max_len_label_text = SXSIZE / getFontWidth(FONT_SPECIAL_GAME);
 
-  DrawBackground(SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE);
+  DrawBackground(SX, MICROLABEL_YPOS, SXSIZE,getFontHeight(FONT_SPECIAL_GAME));
 
   strncpy(label_text, (mode == MICROLABEL_LEVEL_NAME ? level.name :
                       mode == MICROLABEL_CREATED_BY ? "created by" :
@@ -1617,15 +1634,16 @@ static void DrawMicroLevelLabelExt(int mode)
                       mode == MICROLABEL_IMPORTED_FROM ? "imported from" :
                       mode == MICROLABEL_LEVEL_IMPORT_INFO ?
                       leveldir_current->imported_from : ""),
-         MAX_MICROLABEL_SIZE);
-  label_text[MAX_MICROLABEL_SIZE] = '\0';
+         max_len_label_text);
+  label_text[max_len_label_text] = '\0';
 
   if (strlen(label_text) > 0)
   {
-    int lxpos = SX + (SXSIZE - strlen(label_text) * FONT4_XSIZE) / 2;
+    int text_width = strlen(label_text) * getFontWidth(FONT_SPECIAL_GAME);
+    int lxpos = SX + (SXSIZE - text_width) / 2;
     int lypos = MICROLABEL_YPOS;
 
-    DrawText(lxpos, lypos, label_text, FS_SMALL, FC_SPECIAL2);
+    DrawText(lxpos, lypos, label_text, FONT_SPECIAL_GAME);
   }
 
   redraw_mask |= REDRAW_MICROLEVEL;
@@ -1793,7 +1811,7 @@ boolean Request(char *text, unsigned int req_state)
     text_line[tl] = 0;
 
     DrawText(DX + 50 - (tl * 14)/2, DY + 8 + ty * 16,
-            text_line, FS_SMALL, FC_YELLOW);
+            text_line, FONT_DEFAULT_SMALL);
 
     text += tl + (tc == ' ' ? 1 : 0);
   }
@@ -2455,3 +2473,8 @@ int el2edimg(int element)
 {
   return element_info[element].editor_graphic;
 }
+
+int el2preimg(int element)
+{
+  return element_info[element].preview_graphic;
+}