added support for stacked global animations
authorHolger Schemel <info@artsoft.org>
Wed, 8 Feb 2023 21:49:12 +0000 (22:49 +0100)
committerHolger Schemel <info@artsoft.org>
Wed, 8 Feb 2023 21:49:17 +0000 (22:49 +0100)
This extension of global animations adds "stacked animations" that are
created by "stacking" the same global animation multiple times, either
horizontally, vertically, or both, with additional options to use some
empty space between two adjacent stacked animations, as follows:

global.anim_X.stacked_xfactor: <x-factor>
global.anim_X.stacked_yfactor: <y-factor>
global.anim_X.stacked_xoffset: <x-offset>
global.anim_X.stacked_yoffset: <y-offset>

This would stack global animation X <x-factor> times horizontally and
<y-factor> times vertically, while adding empty space between stacked
animations of <x-offset> pixels horizontally and <y-offset> vertically.

src/anim.c
src/conf_gfx.c
src/init.c
src/main.h

index 1fb0672e2e50138d0b46674b6999e25cb43d7196..9ac9d168e3cf7dc6c3d2a9a4597cf9ebbb80ecbf 100644 (file)
@@ -636,7 +636,9 @@ void InitGlobalAnimations(void)
   InitGlobalAnimControls();
 }
 
-static void BlitGlobalAnimation(struct GraphicInfo *g, Bitmap *src_bitmap,
+static void BlitGlobalAnimation(struct GraphicInfo *g,
+                               struct GraphicInfo *c,
+                               Bitmap *src_bitmap,
                                int src_x, int src_y, int width, int height,
                                int dst_x, int dst_y, int drawing_target)
 {
@@ -647,13 +649,23 @@ static void BlitGlobalAnimation(struct GraphicInfo *g, Bitmap *src_bitmap,
   Bitmap *fade_bitmap =
     (drawing_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
      drawing_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
+  int x, y;
 
-  if (drawing_target == DRAW_TO_SCREEN)
-    blit_screen(src_bitmap, src_x, src_y, width, height,
-               dst_x, dst_y);
-  else
-    blit_bitmap(src_bitmap, fade_bitmap, src_x, src_y, width, height,
-               dst_x, dst_y);
+  for (y = 0; y < c->stacked_yfactor; y++)
+  {
+    for (x = 0; x < c->stacked_xfactor; x++)
+    {
+      int dst_x_final = dst_x + x * (g->width  + c->stacked_xoffset);
+      int dst_y_final = dst_y + y * (g->height + c->stacked_yoffset);
+
+      if (drawing_target == DRAW_TO_SCREEN)
+       blit_screen(src_bitmap, src_x, src_y, width, height,
+                   dst_x_final, dst_y_final);
+      else
+       blit_bitmap(src_bitmap, fade_bitmap, src_x, src_y, width, height,
+                   dst_x_final, dst_y_final);
+    }
+  }
 }
 
 static void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
@@ -800,6 +812,7 @@ static void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
       {
        struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
        struct GraphicInfo *g = &part->graphic_info;
+       struct GraphicInfo *c = &part->control_info;
        Bitmap *src_bitmap;
        int src_x, src_y;
        int width  = g->width;
@@ -864,7 +877,7 @@ static void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
        src_x += cut_x;
        src_y += cut_y;
 
-       BlitGlobalAnimation(g, src_bitmap, src_x, src_y, width, height,
+       BlitGlobalAnimation(g, c, src_bitmap, src_x, src_y, width, height,
                            dst_x, dst_y, drawing_target);
       }
     }
index b168262dc2721c601a3908219ffc1066c3b2dbea..fe2dd219f7d7b48d64c87352d15c3e158a95eefc 100644 (file)
@@ -86,6 +86,10 @@ struct ConfigTypeInfo image_config_suffix[] =
   { ".active_yoffset",                 "0",            TYPE_INTEGER    },
   { ".pressed_xoffset",                        "0",            TYPE_INTEGER    },
   { ".pressed_yoffset",                        "0",            TYPE_INTEGER    },
+  { ".stacked_xfactor",                        "1",            TYPE_INTEGER    },
+  { ".stacked_yfactor",                        "1",            TYPE_INTEGER    },
+  { ".stacked_xoffset",                        "0",            TYPE_INTEGER    },
+  { ".stacked_yoffset",                        "0",            TYPE_INTEGER    },
 
   { NULL,                              NULL,           0               }
 };
index 00b471ee916bcc69f50147456414134ab2359619..6cfba4e633c944145fee8330797e0ef72c32a839 100644 (file)
@@ -1691,6 +1691,12 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   g->active_yoffset = parameter[GFX_ARG_ACTIVE_YOFFSET];
   g->pressed_xoffset = parameter[GFX_ARG_PRESSED_XOFFSET];
   g->pressed_yoffset = parameter[GFX_ARG_PRESSED_YOFFSET];
+
+  // this is only used for drawing stacked global animations
+  g->stacked_xfactor = parameter[GFX_ARG_STACKED_XFACTOR];
+  g->stacked_yfactor = parameter[GFX_ARG_STACKED_YFACTOR];
+  g->stacked_xoffset = parameter[GFX_ARG_STACKED_XOFFSET];
+  g->stacked_yoffset = parameter[GFX_ARG_STACKED_YOFFSET];
 }
 
 static void set_graphic_parameters(int graphic)
index 238a0774785a98193e2b52d6cc808e4df636bb2a..618db1fb84097a4a82094ff982b99f5a09b3ae48 100644 (file)
@@ -2456,6 +2456,10 @@ enum
   GFX_ARG_ACTIVE_YOFFSET,
   GFX_ARG_PRESSED_XOFFSET,
   GFX_ARG_PRESSED_YOFFSET,
+  GFX_ARG_STACKED_XFACTOR,
+  GFX_ARG_STACKED_YFACTOR,
+  GFX_ARG_STACKED_XOFFSET,
+  GFX_ARG_STACKED_YOFFSET,
 
   NUM_GFX_ARGS
 };
@@ -3690,6 +3694,11 @@ struct GraphicInfo
   int pressed_xoffset;
   int pressed_yoffset;
 
+  int stacked_xfactor;
+  int stacked_yfactor;
+  int stacked_xoffset;
+  int stacked_yoffset;
+
   boolean use_image_size;      // use image size as default width and height
 };