Freeciv-3.2
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 -1.0, 1.0, 2.0, -1.0
33};
34
36
37static struct zoom_data
38{
39 bool active;
40 float tgt;
41 float factor;
42 float interval;
43 bool tgt_1_0;
44} zdata = { FALSE, 0.0, 0.0 };
45
46/**********************************************************************/
62
63/**********************************************************************/
66void zoom_1_0(void)
67{
69 map_zoom = 1.0;
70 mouse_zoom = 1.0;
71
73}
74
75/**********************************************************************/
80void zoom_set_steps(float *steps)
81{
82 if (steps == NULL) {
84 } else {
85 zoom_steps = steps;
86 }
87}
88
89/**********************************************************************/
102
103/**********************************************************************/
106void zoom_step_up(void)
107{
108 int i;
109
110 /* Even if below previous step, close enough is considered to be in
111 * previous step so that change is not minuscule */
112 for (i = 1 ;
113 zoom_steps[i] < mouse_zoom * 1.05 && zoom_steps[i] > 0.0 ;
114 i++ ) {
115 /* Empty */
116 }
117
118 if (zoom_steps[i] > 0.0) {
119 if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
120 zoom_1_0();
121 } else {
123 }
124 }
125}
126
127/**********************************************************************/
131{
132 int i;
133
134 /* Even if above previous step, close enough is considered to be in
135 * previous step so that change is not minuscule */
136 for (i = 1;
137 zoom_steps[i] < mouse_zoom * 1.05 && zoom_steps[i] > 0.0 ;
138 i++) {
139 }
140
141 /* Get back, and below */
142 i = MAX(i - 2, 1);
143
144 if (zoom_steps[i] > 0.0) {
145 if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) {
146 zoom_1_0();
147 } else {
149 }
150 }
151}
152
153/**********************************************************************/
156void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
157{
158 zdata.tgt = tgt;
160 || (tgt > mouse_zoom && factor < 1.0)) {
161 factor = 1.0 / factor;
162 }
163 zdata.factor = factor;
164 zdata.interval = interval;
165 zdata.tgt_1_0 = tgt_1_0;
166 zdata.active = TRUE;
167}
168
169/**********************************************************************/
173{
174 if (zdata.active) {
176
177 if ((zdata.factor > 1.0 && new_zoom > zdata.tgt)
178 || (zdata.factor < 1.0 && new_zoom < zdata.tgt)) {
181 if (zdata.tgt_1_0) {
182 zoom_1_0();
183 } else {
185 }
186 } else {
188
190 }
191 }
192
194}
char * incite_cost
Definition comments.c:75
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:41
float tgt
Definition zoom.c:40
bool tgt_1_0
Definition zoom.c:43
float interval
Definition zoom.c:42
bool active
Definition zoom.c:39
#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:66
float mouse_zoom
Definition zoom.c:28
static float * zoom_steps
Definition zoom.c:35
float map_zoom
Definition zoom.c:25
void zoom_phase_set(bool individual_tiles)
Definition zoom.c:93
bool zoom_update(double time_until_next_call)
Definition zoom.c:172
void zoom_set_steps(float *steps)
Definition zoom.c:80
void zoom_set(float new_zoom)
Definition zoom.c:49
void zoom_step_down(void)
Definition zoom.c:130
void zoom_step_up(void)
Definition zoom.c:106
static struct zoom_data zdata
void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
Definition zoom.c:156