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
25float map_zoom = 1.0;
27
28float mouse_zoom = 1.0;
30
31static 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
40
41static 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/**********************************************************************/
66
67/**********************************************************************/
70void zoom_1_0(void)
71{
73 map_zoom = 1.0;
74 mouse_zoom = 1.0;
75
77}
78
79/**********************************************************************/
84void zoom_set_steps(float *steps)
85{
86 if (steps == NULL) {
88 } else {
89 zoom_steps = steps;
90 }
91}
92
93/**********************************************************************/
98{
100
101 if (!individual_tiles) {
102 map_zoom = 1.0;
104 }
105}
106
107/**********************************************************************/
110void 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 {
127 }
128 }
129}
130
131/**********************************************************************/
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 {
153 }
154 }
155}
156
157/**********************************************************************/
160void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
161{
162 zdata.tgt = tgt;
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/**********************************************************************/
177{
178 if (zdata.active) {
180
181 if ((zdata.factor > 1.0 && new_zoom > zdata.tgt)
182 || (zdata.factor < 1.0 && new_zoom < zdata.tgt)) {
185 if (zdata.tgt_1_0) {
186 zoom_1_0();
187 } else {
189 }
190 } else {
192
194 }
195 }
196
198}
char * incite_cost
Definition comments.c:74
void map_canvas_size_refresh(void)
Definition mapview.c:414
struct view mapview
bool map_canvas_resized(int width, int height)
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
int height
int width
float factor
Definition zoom.c:45
float tgt
Definition zoom.c:44
bool tgt_1_0
Definition zoom.c:47
float interval
Definition zoom.c:46
bool active
Definition zoom.c:43
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
static float default_zoom_steps[]
Definition zoom.c:31
bool zoom_individual_tiles
Definition zoom.c:29
bool zoom_enabled
Definition zoom.c:26
void zoom_1_0(void)
Definition zoom.c:70
float mouse_zoom
Definition zoom.c:28
static float * zoom_steps
Definition zoom.c:39
float map_zoom
Definition zoom.c:25
void zoom_phase_set(bool individual_tiles)
Definition zoom.c:97
bool zoom_update(double time_until_next_call)
Definition zoom.c:176
void zoom_set_steps(float *steps)
Definition zoom.c:84
void zoom_set(float new_zoom)
Definition zoom.c:53
void zoom_step_down(void)
Definition zoom.c:134
void zoom_step_up(void)
Definition zoom.c:110
static struct zoom_data zdata
void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
Definition zoom.c:160