Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/zoom.c Source File

Freeciv-3.1

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 -1.0, 1.0, 2.0, -1.0
33};
34
35 static float *zoom_steps = default_zoom_steps;
36
37 static 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/**********************************************************************/
49 void zoom_set(float new_zoom)
50{
51 zoom_enabled = TRUE;
52 mouse_zoom = new_zoom;
53
54 if (zoom_individual_tiles) {
55 map_zoom = new_zoom;
56
57 map_canvas_resized(mapview.width, mapview.height);
58 } else {
59 map_canvas_size_refresh();
60 }
61}
62
63/**********************************************************************/
66 void zoom_1_0(void)
67{
68 zoom_enabled = FALSE;
69 map_zoom = 1.0;
70 mouse_zoom = 1.0;
71
72 map_canvas_resized(mapview.width, mapview.height);
73}
74
75/**********************************************************************/
80 void zoom_set_steps(float *steps)
81{
82 if (steps == NULL) {
83 zoom_steps = default_zoom_steps;
84 } else {
85 zoom_steps = steps;
86 }
87}
88
89/**********************************************************************/
93 void zoom_phase_set(bool individual_tiles)
94{
95 zoom_individual_tiles = individual_tiles;
96
97 if (!individual_tiles) {
98 map_zoom = 1.0;
99 zoom_enabled = FALSE;
100 }
101}
102
103/**********************************************************************/
106 void 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 miniscule */
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 {
122 zoom_set(zoom_steps[i]);
123 }
124 }
125}
126
127/**********************************************************************/
130 void zoom_step_down(void)
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 miniscule */
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 {
148 zoom_set(zoom_steps[i]);
149 }
150 }
151}
152
153/**********************************************************************/
156 void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
157{
158 zdata.tgt = tgt;
159 if ((tgt < mouse_zoom && factor > 1.0)
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/**********************************************************************/
172 bool zoom_update(double time_until_next_call)
173{
174 if (zdata.active) {
175 float new_zoom = mouse_zoom * zdata.factor;
176
177 if ((zdata.factor > 1.0 && new_zoom > zdata.tgt)
178 || (zdata.factor < 1.0 && new_zoom < zdata.tgt)) {
179 new_zoom = zdata.tgt;
180 zdata.active = FALSE;
181 if (zdata.tgt_1_0) {
182 zoom_1_0();
183 } else {
184 zoom_set(new_zoom);
185 }
186 } else {
187 zoom_set(new_zoom);
188
189 return MIN(time_until_next_call, zdata.interval);
190 }
191 }
192
193 return time_until_next_call;
194}
map_canvas_size_refresh
void map_canvas_size_refresh(void)
Definition mapview.c:397
mapview
struct view mapview
Definition mapview_common.c:74
map_canvas_resized
bool map_canvas_resized(int width, int height)
Definition mapview_common.c:3593
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:38
zoom_data::factor
float factor
Definition zoom.c:41
zoom_data::tgt
float tgt
Definition zoom.c:40
zoom_data::tgt_1_0
bool tgt_1_0
Definition zoom.c:43
zoom_data::interval
float interval
Definition zoom.c:42
zoom_data::active
bool active
Definition zoom.c:39
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:66
mouse_zoom
float mouse_zoom
Definition zoom.c:28
zoom_steps
static float * zoom_steps
Definition zoom.c:35
map_zoom
float map_zoom
Definition zoom.c:25
zoom_phase_set
void zoom_phase_set(bool individual_tiles)
Definition zoom.c:93
zoom_update
bool zoom_update(double time_until_next_call)
Definition zoom.c:172
zoom_set_steps
void zoom_set_steps(float *steps)
Definition zoom.c:80
zoom_set
void zoom_set(float new_zoom)
Definition zoom.c:49
zoom_step_down
void zoom_step_down(void)
Definition zoom.c:130
zoom_step_up
void zoom_step_up(void)
Definition zoom.c:106
zdata
static struct zoom_data zdata
zoom_start
void zoom_start(float tgt, bool tgt_1_0, float factor, float interval)
Definition zoom.c:156
zoom.h