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 d226d5cddcc82626191dde2c34abb6edcca32f48..8256ce7f60f5ec62fda3ebf49adb086a5450cc3b 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;