added forcing pointer-style global animations to stay inside window area
authorHolger Schemel <info@artsoft.org>
Mon, 22 Apr 2019 11:08:40 +0000 (13:08 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 22 Apr 2019 11:08:40 +0000 (13:08 +0200)
src/anim.c

index d226d5c..8256ce7 100644 (file)
@@ -863,8 +863,11 @@ static boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part
   }
   else if (part->control_info.class == get_hash_from_key("pointer"))
   {
-    viewport_x = gfx.mouse_x + part->control_info.x;
-    viewport_y = gfx.mouse_y + part->control_info.y;
+    int mx = MIN(MAX(0, gfx.mouse_x), WIN_XSIZE - 1);
+    int my = MIN(MAX(0, gfx.mouse_y), WIN_YSIZE - 1);
+
+    viewport_x = mx + part->control_info.x;
+    viewport_y = my + part->control_info.y;
     viewport_width  = part->graphic_info.width;
     viewport_height = part->graphic_info.height;