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)
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 ***********************************************************************/
15 #include <fc_config.h>
19 #include "mapview_common.h"
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
38 } zdata
= { FALSE
, 0.0, 0.0 };
40 /**************************************************************************
42 **************************************************************************/
43 void zoom_set(float new_zoom
)
48 map_canvas_resized(mapview
.width
, mapview
.height
);
51 /**************************************************************************
52 Set map zoom level to exactly one.
53 **************************************************************************/
59 map_canvas_resized(mapview
.width
, mapview
.height
);
62 /**************************************************************************
63 Zoom level one step up
64 **************************************************************************/
65 void zoom_step_up(void)
69 /* Even if below previous step, close enough is considered to be in
70 * previous step so that change is not miniscule */
72 zoom_steps
[i
] < map_zoom
* 1.05 && zoom_steps
[i
] > 0.0 ;
77 if (zoom_steps
[i
] > 0.0) {
78 if (zoom_steps
[i
] > 0.99 && zoom_steps
[i
] < 1.01) {
81 zoom_set(zoom_steps
[i
]);
86 /**************************************************************************
87 Zoom level one step down
88 **************************************************************************/
89 void zoom_step_down(void)
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 ;
101 if (zoom_steps
[i
] > 0.0) {
102 if (zoom_steps
[i
] > 0.99 && zoom_steps
[i
] < 1.01) {
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
)
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
;
126 /**************************************************************************
127 Next step from the active zoom.
128 **************************************************************************/
129 bool zoom_update(double time_until_next_call
)
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
;
146 return MIN(time_until_next_call
, zdata
.interval
);
150 return time_until_next_call
;