added global animation event 'unclick:any' to handle mouse release events
authorHolger Schemel <info@artsoft.org>
Sun, 17 Mar 2019 19:20:51 +0000 (20:20 +0100)
committerHolger Schemel <info@artsoft.org>
Sun, 17 Mar 2019 19:20:51 +0000 (20:20 +0100)
src/anim.c
src/files.c
src/libgame/system.h

index 824f86b5a159e441fc90c03112b0e45cc36cae0c..9d1f0b5c734dc75200cc077ff88d826051ceb443 100644 (file)
@@ -1013,6 +1013,8 @@ static boolean checkGlobalAnimEvent(int anim_event, int mask)
     return (anim_event & ANIM_EVENT_ANY);
   else if (mask & ANIM_EVENT_SELF)
     return (anim_event & ANIM_EVENT_SELF);
     return (anim_event & ANIM_EVENT_ANY);
   else if (mask & ANIM_EVENT_SELF)
     return (anim_event & ANIM_EVENT_SELF);
+  else if (mask & ANIM_EVENT_UNCLICK_ANY)
+    return (anim_event & ANIM_EVENT_UNCLICK_ANY);
   else
     return (anim_event == mask ||
            anim_event == mask_anim_only);
   else
     return (anim_event == mask ||
            anim_event == mask_anim_only);
@@ -1662,7 +1664,11 @@ static void InitGlobalAnim_Clickable(void)
   }
 }
 
   }
 }
 
-static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
+#define ANIM_CLICKED_RESET     0
+#define ANIM_CLICKED_PRESSED   1
+#define ANIM_CLICKED_RELEASED  2
+
+static boolean InitGlobalAnim_Clicked(int mx, int my, int clicked_event)
 {
   boolean anything_clicked = FALSE;
   boolean any_part_clicked = FALSE;
 {
   boolean anything_clicked = FALSE;
   boolean any_part_clicked = FALSE;
@@ -1686,7 +1692,7 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
       {
        struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
 
       {
        struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
 
-       if (!clicked)
+       if (clicked_event == ANIM_CLICKED_RESET)
        {
          part->clicked = FALSE;
 
        {
          part->clicked = FALSE;
 
@@ -1700,7 +1706,8 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
          continue;
 
        // always handle "any" click events (clicking anywhere on screen) ...
          continue;
 
        // always handle "any" click events (clicking anywhere on screen) ...
-       if (isClickablePart(part, ANIM_EVENT_ANY))
+       if (clicked_event == ANIM_CLICKED_PRESSED &&
+           isClickablePart(part, ANIM_EVENT_ANY))
        {
 #if DEBUG_ANIM_EVENTS
          printf("::: => %d.%d TRIGGERED BY ANY\n",
        {
 #if DEBUG_ANIM_EVENTS
          printf("::: => %d.%d TRIGGERED BY ANY\n",
@@ -1711,11 +1718,25 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
          anything_clicked = clickConsumed(part);
        }
 
          anything_clicked = clickConsumed(part);
        }
 
+       // always handle "unclick:any" events (releasing anywhere on screen) ...
+       if (clicked_event == ANIM_CLICKED_RELEASED &&
+           isClickablePart(part, ANIM_EVENT_UNCLICK_ANY))
+       {
+#if DEBUG_ANIM_EVENTS
+         printf("::: => %d.%d TRIGGERED BY UNCLICK:ANY\n",
+                part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
+         part->clicked = TRUE;
+         anything_clicked = clickConsumed(part);
+       }
+
        // ... but only handle the first (topmost) clickable animation
        if (any_part_clicked)
          continue;
 
        // ... but only handle the first (topmost) clickable animation
        if (any_part_clicked)
          continue;
 
-       if (isClickedPart(part, mx, my, clicked))
+       if (clicked_event == ANIM_CLICKED_PRESSED &&
+           isClickedPart(part, mx, my, TRUE))
        {
 #if 0
          printf("::: %d.%d CLICKED [%d]\n", anim_nr, part_nr,
        {
 #if 0
          printf("::: %d.%d CLICKED [%d]\n", anim_nr, part_nr,
@@ -1758,7 +1779,7 @@ static void ResetGlobalAnim_Clickable(void)
 
 static void ResetGlobalAnim_Clicked(void)
 {
 
 static void ResetGlobalAnim_Clicked(void)
 {
-  InitGlobalAnim_Clicked(-1, -1, FALSE);
+  InitGlobalAnim_Clicked(-1, -1, ANIM_CLICKED_RESET);
 }
 
 boolean HandleGlobalAnimClicks(int mx, int my, int button)
 }
 
 boolean HandleGlobalAnimClicks(int mx, int my, int button)
@@ -1776,12 +1797,15 @@ boolean HandleGlobalAnimClicks(int mx, int my, int button)
 
   if (press_event)
   {
 
   if (press_event)
   {
-    click_consumed = InitGlobalAnim_Clicked(mx, my, TRUE);
+    click_consumed = InitGlobalAnim_Clicked(mx, my, ANIM_CLICKED_PRESSED);
     click_consumed_current = click_consumed;
   }
 
   if (release_event)
     click_consumed_current = click_consumed;
   }
 
   if (release_event)
+  {
+    InitGlobalAnim_Clicked(mx, my, ANIM_CLICKED_RELEASED);
     click_consumed = FALSE;
     click_consumed = FALSE;
+  }
 
   return click_consumed_current;
 }
 
   return click_consumed_current;
 }
index 5ec5f7f063e83c9454f7e2d85b3be2b8fb5b2414..cfba947d0c50ac26aa6870d5d87cbb1f48f45d3d 100644 (file)
@@ -10168,6 +10168,9 @@ static int get_anim_parameter_values(char *s)
       string_has_parameter(s, "self"))
     event_value |= ANIM_EVENT_SELF;
 
       string_has_parameter(s, "self"))
     event_value |= ANIM_EVENT_SELF;
 
+  if (string_has_parameter(s, "unclick:any"))
+    event_value |= ANIM_EVENT_UNCLICK_ANY;
+
   // if animation event found, add it to global animation event list
   if (event_value != ANIM_EVENT_NONE)
     list_pos = AddGlobalAnimEventValue(list_pos, event_value);
   // if animation event found, add it to global animation event list
   if (event_value != ANIM_EVENT_NONE)
     list_pos = AddGlobalAnimEventValue(list_pos, event_value);
index 8bcafb8269c1517ecaf30a8734f9db2668059351..51357bcea1fb338324e4ef8a46ec5955c00fdef1 100644 (file)
 #define ANIM_EVENT_START       (1 << 20)
 #define ANIM_EVENT_END         (1 << 21)
 #define ANIM_EVENT_POST                (1 << 22)
 #define ANIM_EVENT_START       (1 << 20)
 #define ANIM_EVENT_END         (1 << 21)
 #define ANIM_EVENT_POST                (1 << 22)
+#define ANIM_EVENT_UNCLICK_ANY (1 << 23)
 
 // anim number: bits 0-7
 // part number: bits 8-15
 
 // anim number: bits 0-7
 // part number: bits 8-15