Author: cazfi
Date: Wed Dec  9 13:48:35 2015
New Revision: 30913

URL: http://svn.gna.org/viewcvs/freeciv?rev=30913&view=rev
Log:
Added zoom_start() that can be used to start multi-frame zoom in / zoom out.

See patch #6617

Modified:
    trunk/client/client_main.c
    trunk/client/zoom.c
    trunk/client/zoom.h

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=30913&r1=30912&r2=30913&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Wed Dec  9 13:48:35 2015
@@ -95,6 +95,7 @@
 #include "themes_common.h"
 #include "update_queue.h"
 #include "voteinfo.h"
+#include "zoom.h"
 
 /* client/agents */
 #include "agents.h"
@@ -1149,6 +1150,8 @@
     return time_until_next_call;
   }
 
+  time_until_next_call = zoom_update(time_until_next_call);
+
   {
     double blink_time = blink_turn_done_button();
 

Modified: trunk/client/zoom.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/zoom.c?rev=30913&r1=30912&r2=30913&view=diff
==============================================================================
--- trunk/client/zoom.c (original)
+++ trunk/client/zoom.c Wed Dec  9 13:48:35 2015
@@ -27,6 +27,15 @@
 static float zoom_steps[] = {
   -1.0, 0.10, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, -1.0
 };
+
+static struct zoom_data
+{
+  bool active;
+  float tgt;
+  float factor;
+  float interval;
+  bool tgt_1_0;
+} zdata = { FALSE, 0.0, 0.0 };
 
 /**************************************************************************
   Set map zoom level.
@@ -97,3 +106,46 @@
     }
   }
 }
+
+/**************************************************************************
+  Start zoom animation.
+**************************************************************************/
+void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
+{
+  zdata.tgt = tgt;
+  if ((tgt < map_zoom && factor > 1.0)
+      || (tgt > map_zoom && factor < 1.0)) {
+    factor = 1.0 / factor;
+  }
+  zdata.factor = factor;
+  zdata.interval = interval;
+  zdata.tgt_1_0 = tgt_1_0;
+  zdata.active = TRUE;
+}
+
+/**************************************************************************
+  Next step from the active zoom.
+**************************************************************************/
+bool zoom_update(double time_until_next_call)
+{
+  if (zdata.active) {
+    float new_zoom = map_zoom * zdata.factor;
+
+    if ((zdata.factor > 1.0 && new_zoom > zdata.tgt)
+        || (zdata.factor < 1.0 && new_zoom < zdata.tgt)) {
+      new_zoom = zdata.tgt;
+      zdata.active = FALSE;
+      if (zdata.tgt_1_0) {
+        zoom_1_0();
+      } else {
+        zoom_set(new_zoom);
+      }
+    } else {
+      zoom_set(new_zoom);
+
+      return MIN(time_until_next_call, zdata.interval);
+    }
+  }
+
+  return time_until_next_call;
+}

Modified: trunk/client/zoom.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/zoom.h?rev=30913&r1=30912&r2=30913&view=diff
==============================================================================
--- trunk/client/zoom.h (original)
+++ trunk/client/zoom.h Wed Dec  9 13:48:35 2015
@@ -26,6 +26,9 @@
 void zoom_step_up(void);
 void zoom_step_down(void);
 
+void zoom_start(float tgt, bool tgt_1_0, float factor, float interval);
+bool zoom_update(double time_until_next_call);
+
 extern bool zoom_enabled;
 extern float map_zoom;
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to