Author: cazfi
Date: Wed Dec  9 13:48:42 2015
New Revision: 30914

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

See patch #6617

Modified:
    branches/S2_6/client/client_main.c
    branches/S2_6/client/zoom.c
    branches/S2_6/client/zoom.h

Modified: branches/S2_6/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=30914&r1=30913&r2=30914&view=diff
==============================================================================
--- branches/S2_6/client/client_main.c  (original)
+++ branches/S2_6/client/client_main.c  Wed Dec  9 13:48:42 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: branches/S2_6/client/zoom.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/zoom.c?rev=30914&r1=30913&r2=30914&view=diff
==============================================================================
--- branches/S2_6/client/zoom.c (original)
+++ branches/S2_6/client/zoom.c Wed Dec  9 13:48:42 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: branches/S2_6/client/zoom.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/zoom.h?rev=30914&r1=30913&r2=30914&view=diff
==============================================================================
--- branches/S2_6/client/zoom.h (original)
+++ branches/S2_6/client/zoom.h Wed Dec  9 13:48:42 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