rnd-20061018-1-src
[rocksndiamonds.git] / src / tools.c
index 21c5315352ca4e1e5b0c20730ea2d343a2910172..85cee1ddac6fc2a02421c485d1d982ffe87206de 100644 (file)
@@ -194,14 +194,20 @@ void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height)
   BlitBitmap(drawto, window, x, y, width, height, x, y);
 }
 
+void DrawMaskedBorder_Rect(int x, int y, int width, int height)
+{
+  Bitmap *bitmap = graphic_info[IMG_GLOBAL_BORDER].bitmap;
+
+  SetClipOrigin(bitmap, bitmap->stored_clip_gc, 0, 0);
+  BlitBitmapMasked(bitmap, backbuffer, x, y, width, height, x, y);
+}
+
 void DrawMaskedBorder_FIELD()
 {
   if (game_status >= GAME_MODE_TITLE &&
       game_status <= GAME_MODE_PLAYING &&
       border.draw_masked[game_status])
-    BlitBitmapMasked(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
-                    REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
-                    REAL_SX, REAL_SY);
+    DrawMaskedBorder_Rect(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
 }
 
 void DrawMaskedBorder_DOOR_1()
@@ -209,16 +215,14 @@ void DrawMaskedBorder_DOOR_1()
   if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
       (game_status != GAME_MODE_EDITOR ||
        border.draw_masked[GFX_SPECIAL_ARG_EDITOR]))
-    BlitBitmapMasked(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
-                    DX, DY, DXSIZE, DYSIZE, DX, DY);
+    DrawMaskedBorder_Rect(DX, DY, DXSIZE, DYSIZE);
 }
 
 void DrawMaskedBorder_DOOR_2()
 {
   if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
       game_status != GAME_MODE_EDITOR)
-    BlitBitmapMasked(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
-                    VX, VY, VXSIZE, VYSIZE, VX, VY);
+    DrawMaskedBorder_Rect(VX, VY, VXSIZE, VYSIZE);
 }
 
 void DrawMaskedBorder_DOOR_3()
@@ -268,6 +272,11 @@ void BackToFront()
   if (redraw_mask == REDRAW_NONE)
     return;
 
+  if (redraw_mask & REDRAW_TILES &&
+      game_status == GAME_MODE_PLAYING &&
+      border.draw_masked[game_status])
+    redraw_mask |= REDRAW_FIELD;
+
   if (global.fps_slowdown && game_status == GAME_MODE_PLAYING)
   {
     static boolean last_frame_skipped = FALSE;
@@ -305,8 +314,15 @@ void BackToFront()
 
   SyncDisplay();
 
+#if 1
+  DrawMaskedBorder(redraw_mask);
+#endif
+
   if (redraw_mask & REDRAW_ALL)
   {
+#if 0
+    DrawMaskedBorder(REDRAW_ALL);
+#endif
     BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
 
     redraw_mask = REDRAW_NONE;
@@ -317,7 +333,9 @@ void BackToFront()
     if (game_status != GAME_MODE_PLAYING ||
        redraw_mask & REDRAW_FROM_BACKBUFFER)
     {
+#if 0
       DrawMaskedBorder(REDRAW_FIELD);
+#endif
       BlitBitmap(backbuffer, window,
                 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);
     }
@@ -375,19 +393,25 @@ void BackToFront()
   {
     if (redraw_mask & REDRAW_DOOR_1)
     {
+#if 0
       DrawMaskedBorder(REDRAW_DOOR_1);
+#endif
       BlitBitmap(backbuffer, window, DX, DY, DXSIZE, DYSIZE, DX, DY);
     }
 
     if (redraw_mask & REDRAW_DOOR_2)
     {
+#if 0
       DrawMaskedBorder(REDRAW_DOOR_2);
+#endif
       BlitBitmap(backbuffer, window, VX, VY, VXSIZE, VYSIZE, VX, VY);
     }
 
     if (redraw_mask & REDRAW_DOOR_3)
     {
+#if 0
       DrawMaskedBorder(REDRAW_DOOR_3);
+#endif
       BlitBitmap(backbuffer, window, EX, EY, EXSIZE, EYSIZE, EX, EY);
     }
 
@@ -1708,8 +1732,14 @@ static void DrawPreviewLevelLabelExt(int mode)
 
   if (strlen(label_text) > 0)
   {
+#if 1
+    int text_width = getTextWidth(label_text, font_nr);
+    int lxpos = SX + menu.main.text.level_info_2.x - text_width / 2;
+    int lypos = SY + menu.main.text.level_info_2.y;
+#else
     int lxpos = SX + (SXSIZE - getTextWidth(label_text, font_nr)) / 2;
     int lypos = MICROLABEL2_YPOS;
+#endif
 
     DrawText(lxpos, lypos, label_text, font_nr);
   }
@@ -1727,8 +1757,14 @@ static void DrawPreviewLevelLabelExt(int mode)
 
   if (strlen(label_text) > 0)
   {
+#if 1
+    int text_width = getTextWidth(label_text, font_nr);
+    int lxpos = SX + menu.main.text.level_info_2.x - text_width / 2;
+    int lypos = SY + menu.main.text.level_info_2.y;
+#else
     int lxpos = SX + (SXSIZE - getTextWidth(label_text, font_nr)) / 2;
     int lypos = MICROLABEL2_YPOS;
+#endif
 
     DrawText(lxpos, lypos, label_text, font_nr);
   }
@@ -1753,7 +1789,8 @@ void DrawPreviewLevel(boolean restart)
 
   if (restart)
   {
-    from_x = from_y = 0;
+    from_x = preview.xoffset;
+    from_y = preview.yoffset;
     scroll_direction = MV_RIGHT;
     label_state = 1;
     label_counter = 0;
@@ -1770,13 +1807,20 @@ void DrawPreviewLevel(boolean restart)
       char label_text[MAX_OUTPUT_LINESIZE + 1];
       int font_nr = FONT_TEXT_1;
       int max_len_label_text = SXSIZE / getFontWidth(font_nr);
+      int text_width;
       int lxpos, lypos;
 
       strncpy(label_text, leveldir_current->name, max_len_label_text);
       label_text[max_len_label_text] = '\0';
 
+#if 1
+      text_width = getTextWidth(label_text, font_nr);
+      lxpos = SX + menu.main.text.level_info_1.x - text_width / 2;
+      lypos = SY + menu.main.text.level_info_1.y;
+#else
       lxpos = SX + (SXSIZE - getTextWidth(label_text, font_nr)) / 2;
       lypos = SY + MICROLABEL1_YPOS;
+#endif
 
       DrawText(lxpos, lypos, label_text, font_nr);
     }
@@ -2627,8 +2671,13 @@ boolean Request(char *text, unsigned int req_state)
 
     DoAnimation();
 
+#if 1
+    if (!PendingEvent())       /* delay only if no pending events */
+      Delay(10);
+#else
     /* don't eat all CPU time */
     Delay(10);
+#endif
   }
 
   if (game_status != GAME_MODE_MAIN)