Author: cazfi
Date: Mon Nov  9 19:44:34 2015
New Revision: 30498

URL: http://svn.gna.org/viewcvs/freeciv?rev=30498&view=rev
Log:
Added zoom steps API

See patch #6543

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

Modified: branches/S2_6/client/zoom.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/zoom.c?rev=30498&r1=30497&r2=30498&view=diff
==============================================================================
--- branches/S2_6/client/zoom.c (original)
+++ branches/S2_6/client/zoom.c Mon Nov  9 19:44:34 2015
@@ -24,6 +24,10 @@
 float map_zoom = 1.0;
 bool zoom_enabled = FALSE;
 
+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
+};
+
 /**************************************************************************
   Set map zoom level.
 **************************************************************************/
@@ -45,3 +49,51 @@
 
   map_canvas_resized(mapview.width, mapview.height);
 }
+
+/**************************************************************************
+  Zoom level one step up
+**************************************************************************/
+void zoom_step_up(void)
+{
+  int i;
+
+  /* Even if below previous step, close enough is considered to be in
+   * previous step so that change is not miniscule */
+  for (i = 1 ;
+       zoom_steps[i] < map_zoom * 1.05 && zoom_steps[i] > 0 ;
+       i++ ) {
+    /* empty */
+  }
+
+  if (zoom_steps[i] > 0) {
+    if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
+      zoom_1_0();
+    } else {
+      zoom_set(zoom_steps[i]);
+    }
+  }
+}
+
+/**************************************************************************
+  Zoom level one step down
+**************************************************************************/
+void zoom_step_down(void)
+{
+  int i;
+
+  /* Even if above previous step, close enough is considered to be in
+   * previous step so that change is not miniscule */
+  for (i = ARRAY_SIZE(zoom_steps) - 2 ;
+       zoom_steps[i] * 1.05 > map_zoom && zoom_steps[i] > 0 ;
+       i-- ) {
+    /* empty */
+  }
+
+  if (zoom_steps[i] > 0) {
+    if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
+      zoom_1_0();
+    } else {
+      zoom_set(zoom_steps[i]);
+    }
+  }
+}

Modified: branches/S2_6/client/zoom.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/zoom.h?rev=30498&r1=30497&r2=30498&view=diff
==============================================================================
--- branches/S2_6/client/zoom.h (original)
+++ branches/S2_6/client/zoom.h Mon Nov  9 19:44:34 2015
@@ -23,6 +23,9 @@
 #define zoom_get_level() map_zoom
 #define zoom_is_enabled() zoom_enabled
 
+void zoom_step_up(void);
+void zoom_step_down(void);
+
 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