rnd-20001205-1-src
[rocksndiamonds.git] / src / cartoons.c
index 9eef8e1e075a148b4aae99c6889af6ba0a09c61b..164fcf220c4d9048eed24609d8dc637fd01db9b5 100644 (file)
 
 #include "cartoons.h"
 #include "main.h"
-#include "misc.h"
 #include "tools.h"
 
+
 static void HandleAnimation(int);
-static BOOL AnimateToon(int, BOOL);
-static void DrawAnim(Pixmap, GC, int, int, int, int, int, int, int, int);
+static boolean AnimateToon(int, boolean);
+static void DrawAnim(Bitmap *, GC, int, int, int, int, int, int, int, int);
 
 struct AnimInfo
 {
@@ -27,7 +27,7 @@ struct AnimInfo
   int frames;
   int frames_per_second;
   int stepsize;
-  BOOL pingpong;
+  boolean pingpong;
   int direction;
   int position;
 };
@@ -107,14 +107,14 @@ void DoAnimation()
 
 void HandleAnimation(int mode)
 {
-  static long animstart_delay = -1;
-  static long animstart_delay_value = 0;
-  static BOOL anim_restart = TRUE;
-  static BOOL reset_delay = TRUE;
+  static unsigned long animstart_delay = -1;
+  static unsigned long animstart_delay_value = 0;
+  static boolean anim_restart = TRUE;
+  static boolean reset_delay = TRUE;
   static int toon_nr = 0;
   int draw_mode;
 
-  if (!toons_on)
+  if (!setup.toons)
     return;
 
   switch(mode)
@@ -124,7 +124,7 @@ void HandleAnimation(int mode)
       reset_delay = TRUE;
 
       /* Fill empty backbuffer for animation functions */
-      if (direct_draw_on && game_status == PLAYING)
+      if (setup.direct_draw && game_status == PLAYING)
       {
        int xx,yy;
 
@@ -138,16 +138,14 @@ void HandleAnimation(int mode)
        SetDrawtoField(DRAW_DIRECT);
       }
 
-      if (soft_scrolling_on && game_status == PLAYING)
+      if (setup.soft_scrolling && game_status == PLAYING)
       {
        int fx = FX, fy = FY;
 
         fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0);
         fy += (ScreenMovDir & (MV_UP|MV_DOWN)    ? ScreenGfxPos : 0);
 
-       XCopyArea(display,fieldbuffer,backbuffer,gc,
-                 fx,fy, SXSIZE,SYSIZE,
-                 SX,SY);
+       BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY);
       }
 
       return;
@@ -158,12 +156,12 @@ void HandleAnimation(int mode)
       redraw_mask |= (REDRAW_FIELD | REDRAW_FROM_BACKBUFFER);
 
       /* Redraw background even when in direct drawing mode */
-      draw_mode = direct_draw_on;
-      direct_draw_on = FALSE;
+      draw_mode = setup.direct_draw;
+      setup.direct_draw = FALSE;
 
       BackToFront();
 
-      direct_draw_on = draw_mode;
+      setup.direct_draw = draw_mode;
 
       return;
       break;
@@ -189,14 +187,14 @@ void HandleAnimation(int mode)
   anim_restart = reset_delay = AnimateToon(toon_nr,anim_restart);
 }
 
-BOOL AnimateToon(int toon_nr, BOOL restart)
+boolean AnimateToon(int toon_nr, boolean restart)
 {
-  static pos_x = 0, pos_y = 0;
-  static delta_x = 0, delta_y = 0;
+  static int pos_x = 0, pos_y = 0;
+  static int delta_x = 0, delta_y = 0;
   static int frame = 0, frame_step = 1;
-  static BOOL horiz_move, vert_move;
-  static long anim_delay = 0;
-  static int anim_delay_value = 0;
+  static boolean horiz_move, vert_move;
+  static unsigned long anim_delay = 0;
+  static unsigned long anim_delay_value = 0;
   static int width,height;
   static int pad_x,pad_y;
   static int cut_x,cut_y;
@@ -310,8 +308,8 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
     },
     {
       GAMETOON_XSIZE, GAMETOON_YSIZE,
-      ((GFX_MAULWURF_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
-      ((GFX_MAULWURF_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
+      ((GFX_MOLE_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
+      ((GFX_MOLE_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
       GAMETOON_FRAMES_4,
       GAMETOON_FPS,
       GAMETOON_STEPSIZE,
@@ -321,8 +319,8 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
     },
     {
       GAMETOON_XSIZE, GAMETOON_YSIZE,
-      ((GFX_MAULWURF_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
-      ((GFX_MAULWURF_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
+      ((GFX_MOLE_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
+      ((GFX_MOLE_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
       GAMETOON_FRAMES_4,
       GAMETOON_FPS,
       GAMETOON_STEPSIZE,
@@ -398,8 +396,9 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
     },
   };
   struct AnimInfo *anim = &toon[toon_nr];
-  Pixmap anim_pixmap = (toon_nr < 6 ? pix[PIX_TOONS] : pix[PIX_HEROES]);
-  GC anim_clip_gc = (toon_nr < 6 ? clip_gc[PIX_TOONS] : clip_gc[PIX_HEROES]);
+  int anim_bitmap_nr = (toon_nr < 6 ? PIX_TOONS : PIX_HEROES);
+  Bitmap *anim_bitmap = pix[anim_bitmap_nr];
+  GC anim_clip_gc = pix[anim_bitmap_nr]->stored_clip_gc;
 
   if (restart)
   {
@@ -462,10 +461,12 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
 
   if (!DelayReached(&anim_delay, anim_delay_value))
   {
-    if (game_status==HELPSCREEN && !restart)
-      DrawAnim(anim_pixmap,anim_clip_gc,
-              src_x+cut_x,src_y+cut_y, width,height,
-              REAL_SX+dest_x,REAL_SY+dest_y, pad_x,pad_y);
+    if ((game_status == HELPSCREEN ||
+        (game_status == MAINMENU && redraw_mask & REDRAW_MICROLEVEL))
+       && !restart)
+      DrawAnim(anim_bitmap, anim_clip_gc,
+              src_x + cut_x, src_y + cut_y, width, height,
+              REAL_SX + dest_x, REAL_SY + dest_y, pad_x, pad_y);
 
     return(FALSE);
   }
@@ -507,7 +508,7 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
   else if (pos_y>FULL_SYSIZE-anim->height)
     height -= (pos_y - (FULL_SYSIZE-anim->height));
 
-  DrawAnim(anim_pixmap,anim_clip_gc,
+  DrawAnim(anim_bitmap,anim_clip_gc,
           src_x+cut_x,src_y+cut_y, width,height,
           REAL_SX+dest_x,REAL_SY+dest_y, pad_x,pad_y);
 
@@ -529,7 +530,7 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
   return(FALSE);
 }
 
-void DrawAnim(Pixmap toon_pixmap, GC toon_clip_gc,
+void DrawAnim(Bitmap *toon_bitmap, GC toon_clip_gc,
              int src_x, int src_y, int width, int height,
              int dest_x, int dest_y, int pad_x, int pad_y)
 {
@@ -537,27 +538,26 @@ void DrawAnim(Pixmap toon_pixmap, GC toon_clip_gc,
 
 #if 1
   /* special method to avoid flickering interference with BackToFront() */
-  XCopyArea(display,backbuffer,pix[PIX_DB_DOOR],gc,dest_x-pad_x,dest_y-pad_y,
-           width+2*pad_x,height+2*pad_y, buf_x,buf_y);
-  XSetClipOrigin(display,toon_clip_gc,dest_x-src_x,dest_y-src_y);
-  XCopyArea(display,toon_pixmap,backbuffer,toon_clip_gc,
-           src_x,src_y, width,height, dest_x,dest_y);
-  XCopyArea(display,backbuffer,window,gc, dest_x-pad_x,dest_y-pad_y,
-           width+2*pad_x,height+2*pad_y, dest_x-pad_x,dest_y-pad_y);
+  BlitBitmap(backbuffer, pix[PIX_DB_DOOR], dest_x-pad_x, dest_y-pad_y,
+            width+2*pad_x, height+2*pad_y, buf_x, buf_y);
+  SetClipOrigin(toon_bitmap, toon_clip_gc, dest_x-src_x, dest_y-src_y);
+  BlitBitmapMasked(toon_bitmap, backbuffer,
+                  src_x, src_y, width, height, dest_x, dest_y);
+  BlitBitmap(backbuffer, window, dest_x-pad_x, dest_y-pad_y,
+            width+2*pad_x, height+2*pad_y, dest_x-pad_x, dest_y-pad_y);
   BackToFront();
-  XCopyArea(display,pix[PIX_DB_DOOR],backbuffer,gc, buf_x,buf_y,
-           width+2*pad_x,height+2*pad_y, dest_x-pad_x,dest_y-pad_y);
+  BlitBitmap(pix[PIX_DB_DOOR], backbuffer, buf_x, buf_y,
+           width+2*pad_x, height+2*pad_y, dest_x-pad_x, dest_y-pad_y);
 #else
   /* normal method, causing flickering interference with BackToFront() */
-  XCopyArea(display,backbuffer,pix[PIX_DB_DOOR],gc,dest_x-pad_x,dest_y-pad_y,
-           width+2*pad_x,height+2*pad_y, buf_x,buf_y);
-  XSetClipOrigin(display,toon_clip_gc,
-                buf_x-src_x+pad_x,buf_y-src_y+pad_y);
-  XCopyArea(display,toon_pixmap,pix[PIX_DB_DOOR],toon_clip_gc,
-           src_x,src_y, width,height, buf_x+pad_x,buf_y+pad_y);
-  XCopyArea(display,pix[PIX_DB_DOOR],window,gc, buf_x,buf_y,
-           width+2*pad_x,height+2*pad_y, dest_x-pad_x,dest_y-pad_y);
+  BlitBitmap(backbuffer, pix[PIX_DB_DOOR], dest_x-pad_x, dest_y-pad_y,
+            width+2*pad_x, height+2*pad_y, buf_x, buf_y);
+  SetClipOrigin(toon_bitmap,toon_clip_gc, buf_x-src_x+pad_x,buf_y-src_y+pad_y);
+  BlitBitmapMasked(toon_bitmap, pix[PIX_DB_DOOR],
+                  src_x, src_y, width, height, buf_x+pad_x, buf_y+pad_y);
+  BlitBitmap(pix[PIX_DB_DOOR], window, buf_x, buf_y,
+            width+2*pad_x, height+2*pad_y, dest_x-pad_x, dest_y-pad_y);
 #endif
 
-  XFlush(display);
+  FlushDisplay();
 }