Freeciv-3.3: /fast/freeciv/nightly/main/client/zoom.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
zoom.c
Go to the documentation of this file.
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.
7
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***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* client */
19#include "mapview_common.h"
20#include "mapview_g.h"
21
22#include "zoom.h"
23
24
25 float map_zoom = 1.0;
26 bool zoom_enabled = FALSE;
27
28 float mouse_zoom = 1.0;
29 bool zoom_individual_tiles = TRUE;
30
31 static float default_zoom_steps[] = {
32#ifdef EXP_ZOOM_LEVELS
33 -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
34#else
35 -1.0, 1.0, 2.0, -1.0
36#endif /* EXP_ZOOM_LEVELS */
37};
38
39 static float *zoom_steps = default_zoom_steps;
40
41 static struct zoom_data
42{
43 bool active;
44 float tgt;
45 float factor;
46 float interval;
47 bool tgt_1_0;
48} zdata = { FALSE, 0.0, 0.0 };
49
50/**********************************************************************/
53 void zoom_set(float new_zoom)
54{
55 zoom_enabled = TRUE;
56 mouse_zoom = new_zoom;
57
58 if (zoom_individual_tiles) {
59 map_zoom = new_zoom;
60
61 map_canvas_resized(mapview.width, mapview.height);
62 } else {
63 map_canvas_size_refresh();
64 }
65}
66
67/**********************************************************************/
70 void zoom_1_0(void)
71{
72 zoom_enabled = FALSE;
73 map_zoom = 1.0;
74 mouse_zoom = 1.0;
75
76 map_canvas_resized(mapview.width, mapview.height);
77}
78
79/**********************************************************************/
84 void zoom_set_steps(float *steps)
85{
86 if (steps == NULL) {
87 zoom_steps = default_zoom_steps;
88 } else {
89 zoom_steps = steps;
90 }
91}
92
93/**********************************************************************/
97 void zoom_phase_set(bool individual_tiles)
98{
99 zoom_individual_tiles = individual_tiles;
100
101 if (!individual_tiles) {
102 map_zoom = 1.0;
103 zoom_enabled = FALSE;
104 }
105}
106
107/**********************************************************************/
110 void zoom_step_up(void)
111{
112 int i;
113
114 /* Even if below previous step, close enough is considered to be in
115 * previous step so that change is not miniscule */
116 for (i = 1 ;
117 zoom_steps[i] < mouse_zoom * 1.05 && zoom_steps[i] > 0.0 ;
118 i++ ) {
119 /* Empty */
120 }
121
122 if (zoom_steps[i] > 0.0) {
123 if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
124 zoom_1_0();
125 } else {
126 zoom_set(zoom_steps[i]);
127 }
128 }
129}
130
131/**********************************************************************/
134 void zoom_step_down(void)
135{
136 int i;
137
138 /* Even if above previous step, close enough is considered to be in
139 * previous step so that change is not miniscule */
140 for (i = 1;
141 zoom_steps[i] < mouse_zoom * 1.05 && zoom_steps[i] > 0.0 ;
142 i++) {
143 }
144
145 /* Get back, and below */
146 i = MAX(i - 2, 1);
147
148 if (zoom_steps[i] > 0.0) {
149 if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
150 zoom_1_0();
151 } else {
152 zoom_set(zoom_steps[i]);
153 }
154 }
155}
156
157/**********************************************************************/
160 void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
161{
162 zdata.tgt = tgt;
163 if ((tgt < mouse_zoom && factor > 1.0)
164 || (tgt > mouse_zoom && factor < 1.0)) {
165 factor = 1.0 / factor;
166 }
167 zdata.factor = factor;
168 zdata.interval = interval;
169 zdata.tgt_1_0 = tgt_1_0;
170 zdata.active = TRUE;
171}
172
173/**********************************************************************/
176 bool zoom_update(double time_until_next_call)
177{
178 if (zdata.active) {
179 float new_zoom = mouse_zoom * zdata.factor;
180
181 if ((zdata.factor > 1.0 && new_zoom > zdata.tgt)
182 || (zdata.factor < 1.0 && new_zoom < zdata.tgt)) {
183 new_zoom = zdata.tgt;
184 zdata.active = FALSE;
185 if (zdata.tgt_1_0) {
186 zoom_1_0();
187 } else {
188 zoom_set(new_zoom);
189 }
190 } else {
191 zoom_set(new_zoom);
192
193 return MIN(time_until_next_call, zdata.interval);
194 }
195 }
196
197 return time_until_next_call;
198}
incite_cost
char * incite_cost
Definition comments.c:74
map_canvas_size_refresh
void map_canvas_size_refresh(void)
Definition mapview.c:414
mapview
struct view mapview
Definition mapview_common.c:75
map_canvas_resized
bool map_canvas_resized(int width, int height)
Definition mapview_common.c:3564
mapview_common.h
mapview_g.h
MIN
#define MIN(x, y)
Definition shared.h:55
MAX
#define MAX(x, y)
Definition shared.h:54
view::height
int height
Definition mapview_common.h:38
view::width
int width
Definition mapview_common.h:38
zoom_data
Definition zoom.c:42
zoom_data::factor
float factor
Definition zoom.c:45
zoom_data::tgt
float tgt
Definition zoom.c:44
zoom_data::tgt_1_0
bool tgt_1_0
Definition zoom.c:47
zoom_data::interval
float interval
Definition zoom.c:46
zoom_data::active
bool active
Definition zoom.c:43
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
default_zoom_steps
static float default_zoom_steps[]
Definition zoom.c:31
zoom_individual_tiles
bool zoom_individual_tiles
Definition zoom.c:29
zoom_enabled
bool zoom_enabled
Definition zoom.c:26
zoom_1_0
void zoom_1_0(void)
Definition zoom.c:70
mouse_zoom
float mouse_zoom
Definition zoom.c:28
zoom_steps
static float * zoom_steps
Definition zoom.c:39
map_zoom
float map_zoom
Definition zoom.c:25
zoom_phase_set
void zoom_phase_set(bool individual_tiles)
Definition zoom.c:97
zoom_update
bool zoom_update(double time_until_next_call)
Definition zoom.c:176
zoom_set_steps
void zoom_set_steps(float *steps)
Definition zoom.c:84
zoom_set
void zoom_set(float new_zoom)
Definition zoom.c:53
zoom_step_down
void zoom_step_down(void)
Definition zoom.c:134
zoom_step_up
void zoom_step_up(void)
Definition zoom.c:110
zdata
static struct zoom_data zdata
zoom_start
void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
Definition zoom.c:160
zoom.h