Stop sharing requirement_unit_state_ereq().
[freeciv.git] / client / zoom.c
blob1453cb8df10308b7488aed8b35a295ecba3f79eb
1 /***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* client */
19 #include "mapview_common.h"
21 #include "zoom.h"
24 float map_zoom = 1.0;
25 bool zoom_enabled = FALSE;
27 static float zoom_steps[] = {
28 -1.0, 0.13, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, -1.0
31 static struct zoom_data
33 bool active;
34 float tgt;
35 float factor;
36 float interval;
37 bool tgt_1_0;
38 } zdata = { FALSE, 0.0, 0.0 };
40 /**************************************************************************
41 Set map zoom level.
42 **************************************************************************/
43 void zoom_set(float new_zoom)
45 zoom_enabled = TRUE;
46 map_zoom = new_zoom;
48 map_canvas_resized(mapview.width, mapview.height);
51 /**************************************************************************
52 Set map zoom level to exactly one.
53 **************************************************************************/
54 void zoom_1_0(void)
56 zoom_enabled = FALSE;
57 map_zoom = 1.0;
59 map_canvas_resized(mapview.width, mapview.height);
62 /**************************************************************************
63 Zoom level one step up
64 **************************************************************************/
65 void zoom_step_up(void)
67 int i;
69 /* Even if below previous step, close enough is considered to be in
70 * previous step so that change is not miniscule */
71 for (i = 1 ;
72 zoom_steps[i] < map_zoom * 1.05 && zoom_steps[i] > 0.0 ;
73 i++ ) {
74 /* empty */
77 if (zoom_steps[i] > 0.0) {
78 if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
79 zoom_1_0();
80 } else {
81 zoom_set(zoom_steps[i]);
86 /**************************************************************************
87 Zoom level one step down
88 **************************************************************************/
89 void zoom_step_down(void)
91 int i;
93 /* Even if above previous step, close enough is considered to be in
94 * previous step so that change is not miniscule */
95 for (i = ARRAY_SIZE(zoom_steps) - 2 ;
96 zoom_steps[i] * 1.05 > map_zoom && zoom_steps[i] > 0.0 ;
97 i-- ) {
98 /* empty */
101 if (zoom_steps[i] > 0.0) {
102 if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
103 zoom_1_0();
104 } else {
105 zoom_set(zoom_steps[i]);
110 /**************************************************************************
111 Start zoom animation.
112 **************************************************************************/
113 void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
115 zdata.tgt = tgt;
116 if ((tgt < map_zoom && factor > 1.0)
117 || (tgt > map_zoom && factor < 1.0)) {
118 factor = 1.0 / factor;
120 zdata.factor = factor;
121 zdata.interval = interval;
122 zdata.tgt_1_0 = tgt_1_0;
123 zdata.active = TRUE;
126 /**************************************************************************
127 Next step from the active zoom.
128 **************************************************************************/
129 bool zoom_update(double time_until_next_call)
131 if (zdata.active) {
132 float new_zoom = map_zoom * zdata.factor;
134 if ((zdata.factor > 1.0 && new_zoom > zdata.tgt)
135 || (zdata.factor < 1.0 && new_zoom < zdata.tgt)) {
136 new_zoom = zdata.tgt;
137 zdata.active = FALSE;
138 if (zdata.tgt_1_0) {
139 zoom_1_0();
140 } else {
141 zoom_set(new_zoom);
143 } else {
144 zoom_set(new_zoom);
146 return MIN(time_until_next_call, zdata.interval);
150 return time_until_next_call;