rnd-19990122-2
[rocksndiamonds.git] / src / tools.c
index 56b64fdaba94c1cd02b7389c9286e676f847ca89..900e5ef7078e610454db0973d6b92b0e898d237d 100644 (file)
@@ -184,15 +184,20 @@ void BackToFront()
     redraw_mask &= ~REDRAW_DOORS;
   }
 
-  if (redraw_mask & REDRAW_MICROLEV)
+  if (redraw_mask & REDRAW_MICROLEVEL)
   {
     XCopyArea(display,backbuffer,window,gc,
-             MICROLEV_XPOS,MICROLEV_YPOS, MICROLEV_XSIZE,MICROLEV_YSIZE,
-             MICROLEV_XPOS,MICROLEV_YPOS);
+             MICROLEV_XPOS, MICROLEV_YPOS, MICROLEV_XSIZE, MICROLEV_YSIZE,
+             MICROLEV_XPOS, MICROLEV_YPOS);
+    redraw_mask &= ~REDRAW_MICROLEVEL;
+  }
+
+  if (redraw_mask & REDRAW_MICROLEVEL_LABEL)
+  {
     XCopyArea(display,backbuffer,window,gc,
-             SX,MICROLABEL_YPOS, SXSIZE,FONT4_YSIZE,
-             SX,MICROLABEL_YPOS);
-    redraw_mask &= ~REDRAW_MICROLEV;
+             SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE,
+             SX, MICROLABEL_YPOS);
+    redraw_mask &= ~REDRAW_MICROLEVEL_LABEL;
   }
 
   if (redraw_mask & REDRAW_TILES)
@@ -349,6 +354,7 @@ void DrawTextExt(Drawable d, GC gc, int x, int y,
 {
   int font_width, font_height, font_start;
   int font_pixmap;
+  boolean print_inverse = FALSE;
 
   if (font_size != FS_SMALL && font_size != FS_BIG)
     font_size = FS_SMALL;
@@ -364,10 +370,16 @@ void DrawTextExt(Drawable d, GC gc, int x, int y,
   font_start = (font_type * (font_size == FS_BIG ? FONT1_YSIZE : FONT2_YSIZE) *
                FONT_LINES_PER_FONT);
 
-  while(*text)
+  while (*text)
   {
     char c = *text++;
 
+    if (c == '~' && font_size == FS_SMALL && font_type <= FC_YELLOW)
+    {
+      print_inverse = TRUE;
+      continue;
+    }
+
     if (c >= 'a' && c <= 'z')
       c = 'A' + (c - 'a');
     else if (c == 'ä' || c == 'Ä')
@@ -378,10 +390,27 @@ void DrawTextExt(Drawable d, GC gc, int x, int y,
       c = 93;
 
     if (c >= 32 && c <= 95)
-      XCopyArea(display, pix[font_pixmap], d, gc,
-               ((c - 32) % FONT_CHARS_PER_LINE) * font_width,
-               ((c - 32) / FONT_CHARS_PER_LINE) * font_height + font_start,
-               font_width, font_height, x, y);
+    {
+      int src_x = ((c - 32) % FONT_CHARS_PER_LINE) * font_width;
+      int src_y = ((c - 32) / FONT_CHARS_PER_LINE) * font_height + font_start;
+      int dest_x = x, dest_y = y;
+
+      if (print_inverse)
+      {
+       XCopyArea(display, pix[font_pixmap], d, gc,
+                 FONT_CHARS_PER_LINE * font_width,
+                 3 * font_height + font_start,
+                 font_width, font_height, x, y);
+
+       XSetClipOrigin(display, clip_gc[font_pixmap],
+                      dest_x - src_x, dest_y - src_y);
+       XCopyArea(display, pix[font_pixmap], drawto, clip_gc[font_pixmap],
+                 0, 0, font_width, font_height, dest_x, dest_y);
+      }
+      else
+       XCopyArea(display, pix[font_pixmap], d, gc,
+                 src_x, src_y, font_width, font_height, dest_x, dest_y);
+    }
 
     x += font_width;
   }
@@ -543,7 +572,10 @@ void DrawPlayer(struct PlayerInfo *player)
        phase = 7 - phase;
     }
 
-    DrawGraphicThruMask(sx, sy, graphic + phase);
+    if (game_emulation == EMU_SUPAPLEX)
+      DrawGraphic(sx, sy, GFX_SP_DISK_RED);
+    else
+      DrawGraphicThruMask(sx, sy, graphic + phase);
   }
 
   if ((last_jx != jx || last_jy != jy) &&
@@ -1202,7 +1234,12 @@ void DrawScreenField(int x, int y)
 
   if (!IN_LEV_FIELD(ux, uy))
   {
-    DrawScreenElement(x, y, EL_BETON);
+    if (ux < -1 || ux > lev_fieldx || uy < -1 || uy > lev_fieldy)
+      element = EL_LEERRAUM;
+    else
+      element = BorderElement;
+
+    DrawScreenElement(x, y, element);
     return;
   }
 
@@ -1362,49 +1399,120 @@ void DrawMiniLevel(int scroll_x, int scroll_y)
 {
   int x,y;
 
-  ClearWindow();
-
-  for(x=0; x<2*SCR_FIELDX; x++)
-    for(y=0; y<2*SCR_FIELDY; y++)
+  for(x=0; x<ED_FIELDX; x++)
+    for(y=0; y<ED_FIELDY; y++)
       DrawMiniElementOrWall(x, y, scroll_x, scroll_y);
 
   redraw_mask |= REDRAW_FIELD;
 }
 
-void DrawMicroLevel(int xpos, int ypos)
+static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
 {
-  int x,y;
+  int x, y;
+
+  /* determine border element for this level */
+  SetBorderElement();
 
   XFillRectangle(display, drawto, gc,
-                xpos - MICRO_TILEX, ypos - MICRO_TILEY,
-                MICRO_TILEX * (STD_LEV_FIELDX + 2),
-                MICRO_TILEY * (STD_LEV_FIELDY + 2));
+                xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
+
   if (lev_fieldx < STD_LEV_FIELDX)
-    xpos += (STD_LEV_FIELDX - lev_fieldx)/2 * MICRO_TILEX;
+    xpos += (STD_LEV_FIELDX - lev_fieldx) / 2 * MICRO_TILEX;
   if (lev_fieldy < STD_LEV_FIELDY)
-    ypos += (STD_LEV_FIELDY - lev_fieldy)/2 * MICRO_TILEY;
+    ypos += (STD_LEV_FIELDY - lev_fieldy) / 2 * MICRO_TILEY;
+
+  xpos += MICRO_TILEX;
+  ypos += MICRO_TILEY;
 
   for(x=-1; x<=STD_LEV_FIELDX; x++)
+  {
     for(y=-1; y<=STD_LEV_FIELDY; y++)
-      if (x >= 0 && x < lev_fieldx && y >= 0 && y < lev_fieldy)
+    {
+      int lx = from_x + x, ly = from_y + y;
+
+      if (lx >= 0 && lx < lev_fieldx && ly >= 0 && ly < lev_fieldy)
        DrawMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY,
-                        Ur[x][y]);
-      else if (x >= -1 && x < lev_fieldx+1 && y >= -1 && y < lev_fieldy+1)
+                        Ur[lx][ly]);
+      else if (lx >= -1 && lx < lev_fieldx+1 && ly >= -1 && ly < lev_fieldy+1)
        DrawMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY,
-                        EL_BETON);
+                        BorderElement);
+    }
+  }
 
-  XFillRectangle(display, drawto,gc, SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE);
+  redraw_mask |= REDRAW_MICROLEVEL;
+}
 
-  if (level.name)
+void DrawMicroLevel(int xpos, int ypos, boolean restart)
+{
+  static unsigned long scroll_delay = 0;
+  static int from_x, from_y, scroll_direction;
+
+  if (restart)
   {
-    int len = strlen(level.name);
-    int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
-    int lypos = MICROLABEL_YPOS;
+    from_x = from_y = 0;
+    scroll_direction = MV_RIGHT;
+
+    DrawMicroLevelExt(xpos, ypos, from_x, from_y);
+
+    XFillRectangle(display, drawto,gc,
+                  SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE);
+
+    if (level.name && restart)
+    {
+      int len = strlen(level.name);
+      int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
+      int lypos = MICROLABEL_YPOS;
+
+      DrawText(lxpos, lypos, level.name, FS_SMALL, FC_SPECIAL2);
+    }
 
-    DrawText(lxpos, lypos, level.name, FS_SMALL, FC_SPECIAL2);
+    /* initialize delay counter */
+    DelayReached(&scroll_delay, 0);
+
+    redraw_mask |= REDRAW_MICROLEVEL_LABEL;
   }
+  else
+  {
+    if ((lev_fieldx <= STD_LEV_FIELDX && lev_fieldy <= STD_LEV_FIELDY) ||
+       !DelayReached(&scroll_delay, MICROLEVEL_SCROLL_DELAY))
+      return;
+
+    switch (scroll_direction)
+    {
+      case MV_LEFT:
+       if (from_x > 0)
+         from_x--;
+       else
+         scroll_direction = MV_UP;
+       break;
+
+      case MV_RIGHT:
+       if (from_x < lev_fieldx - STD_LEV_FIELDX)
+         from_x++;
+       else
+         scroll_direction = MV_DOWN;
+       break;
+
+      case MV_UP:
+       if (from_y > 0)
+         from_y--;
+       else
+         scroll_direction = MV_RIGHT;
+       break;
 
-  redraw_mask |= REDRAW_MICROLEV;
+      case MV_DOWN:
+       if (from_y < lev_fieldy - STD_LEV_FIELDY)
+         from_y++;
+       else
+         scroll_direction = MV_LEFT;
+       break;
+
+      default:
+       break;
+    }
+
+    DrawMicroLevelExt(xpos, ypos, from_x, from_y);
+  }
 }
 
 int REQ_in_range(int x, int y)
@@ -1954,6 +2062,7 @@ int el2gfx(int element)
     case EL_SPEED_PILL:                return GFX_SPEED_PILL;
     case EL_SP_TERMINAL_ACTIVE:        return GFX_SP_TERMINAL;
     case EL_SP_BUG_ACTIVE:     return GFX_SP_BUG_ACTIVE;
+    case EL_INVISIBLE_STEEL:   return GFX_INVISIBLE_STEEL;
 
     default:
     {