added 'position: last' for global animations to continue from last position
[rocksndiamonds.git] / src / anim.c
index ef0fb92a69fd99c0460a8454c357e17abaa55f2d..ff9a8d1f7b443d213cf63e69fe9786a835d4c752 100644 (file)
@@ -126,6 +126,8 @@ struct GlobalAnimMainControlInfo
 
   boolean has_base;    // animation has base/main/default animation part
 
+  int last_x, last_y;
+
   int init_delay_counter;
 
   int state;
@@ -340,6 +342,9 @@ static void InitToonControls()
 
   anim->has_base = FALSE;
 
+  anim->last_x = POS_OFFSCREEN;
+  anim->last_y = POS_OFFSCREEN;
+
   anim->init_delay_counter = 0;
 
   anim->state = ANIM_STATE_INACTIVE;
@@ -433,6 +438,9 @@ void InitGlobalAnimControls()
 
       anim->has_base = FALSE;
 
+      anim->last_x = POS_OFFSCREEN;
+      anim->last_y = POS_OFFSCREEN;
+
       anim->init_delay_counter = 0;
 
       anim->state = ANIM_STATE_INACTIVE;
@@ -698,6 +706,10 @@ void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
        int cut_y = 0;
        int sync_frame;
        int frame;
+       void (*blit_bitmap)(Bitmap *, Bitmap *, int, int, int, int, int, int) =
+         (g->draw_masked ? BlitBitmapMasked : BlitBitmap);
+       void (*blit_screen)(Bitmap *, int, int, int, int, int, int) =
+         (g->draw_masked ? BlitToScreenMasked : BlitToScreen);
 
        if (!(part->state & ANIM_STATE_RUNNING))
          continue;
@@ -741,11 +753,11 @@ void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
        src_y += cut_y;
 
        if (drawing_target == DRAW_TO_SCREEN)
-         BlitToScreenMasked(src_bitmap, src_x, src_y, width, height,
-                            dst_x, dst_y);
+         blit_screen(src_bitmap, src_x, src_y, width, height,
+                     dst_x, dst_y);
        else
-         BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
-                          dst_x, dst_y);
+         blit_bitmap(src_bitmap, fade_bitmap, src_x, src_y, width, height,
+                     dst_x, dst_y);
       }
     }
   }
@@ -932,9 +944,14 @@ static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask)
 {
   struct GraphicInfo *c = &part->control_info;
 
+  boolean clickable_any = FALSE;
   boolean clickable_self = FALSE;
   boolean clickable_triggered = FALSE;
 
+  if (mask & ANIM_EVENT_CLICK_ANY)
+    clickable_any = (c->init_event & ANIM_EVENT_CLICK_ANY ||
+                    c->anim_event & ANIM_EVENT_CLICK_ANY);
+
   if (mask & ANIM_EVENT_CLICK_SELF)
     clickable_self = (c->init_event & ANIM_EVENT_CLICK_SELF ||
                      c->anim_event & ANIM_EVENT_CLICK_SELF);
@@ -942,7 +959,7 @@ static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask)
   clickable_triggered = (matchesAnimEventMask(c->init_event, mask) ||
                         matchesAnimEventMask(c->anim_event, mask));
 
-  return (clickable_self || clickable_triggered);
+  return (clickable_any || clickable_self || clickable_triggered);
 }
 
 static boolean isClickedPart(struct GlobalAnimPartControlInfo *part,
@@ -977,6 +994,8 @@ static boolean isClickedPart(struct GlobalAnimPartControlInfo *part,
 
 int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state)
 {
+  struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr];
+  struct GlobalAnimMainControlInfo *anim = &ctrl->anim[part->anim_nr];
   struct GraphicInfo *g = &part->graphic_info;
   struct GraphicInfo *c = &part->control_info;
   boolean viewport_changed = SetGlobalAnimPart_Viewport(part);
@@ -1073,6 +1092,14 @@ int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state)
     if (c->y != ARG_UNDEFINED_VALUE)
       part->y = c->y;
 
+    if (c->position == POS_LAST &&
+       anim->last_x > -g->width  && anim->last_x < part->viewport_width &&
+       anim->last_y > -g->height && anim->last_y < part->viewport_height)
+    {
+      part->x = anim->last_x;
+      part->y = anim->last_y;
+    }
+
     if (c->step_xoffset != ARG_UNDEFINED_VALUE)
       part->step_xoffset = c->step_xoffset;
     if (c->step_yoffset != ARG_UNDEFINED_VALUE)
@@ -1200,6 +1227,9 @@ int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state)
   part->x += part->step_xoffset;
   part->y += part->step_yoffset;
 
+  anim->last_x = part->x;
+  anim->last_y = part->y;
+
   return ANIM_STATE_RUNNING;
 }
 
@@ -1448,8 +1478,13 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
          continue;
        }
 
-       if (part->clickable &&
-           isClickedPart(part, mx, my, clicked))
+       if (!part->clickable)
+         continue;
+
+       if (isClickablePart(part, ANIM_EVENT_CLICK_ANY))
+         any_part_clicked = part->clicked = TRUE;
+
+       if (isClickedPart(part, mx, my, clicked))
        {
 #if 0
          printf("::: %d.%d CLICKED\n", anim_nr, part_nr);