Freeciv-3.3
Loading...
Searching...
No Matches
mapview_common.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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#ifndef FC__MAPVIEW_COMMON_H
15#define FC__MAPVIEW_COMMON_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/* utility */
22#include "support.h" /* bool type */
23
24/* common */
25#include "fc_types.h"
26#include "featured_text.h" /* enum text_link_type type */
27#include "map.h"
28
29/* include */
30#include "colors_g.h"
31
32#include "tilespec.h"
33
34struct canvas_store; /* Opaque type, real type is gui-dep */
35
36struct view {
37 float gui_x0, gui_y0;
38 int width, height; /* Size in pixels. */
39 int tile_width, tile_height; /* Size in tiles. Rounded up. */
41 bool can_do_cached_drawing; /* TRUE if cached drawing is possible. */
43};
44
45void mapdeco_init(void);
46void mapdeco_free(void);
47void mapdeco_set_highlight(const struct tile *ptile, bool highlight);
48bool mapdeco_is_highlight_set(const struct tile *ptile);
50void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair);
51bool mapdeco_is_crosshair_set(const struct tile *ptile);
53void mapdeco_set_gotoroute(const struct unit *punit);
54void mapdeco_add_gotoline(const struct tile *ptile,
55 enum direction8 dir);
56void mapdeco_remove_gotoline(const struct tile *ptile,
57 enum direction8 dir);
58bool mapdeco_is_gotoline_set(const struct tile *ptile,
59 enum direction8 dir);
61
62struct tile *client_infratile(void);
63void client_infratile_set(struct tile *ptile);
64
65extern struct view mapview;
66
67/* HACK: Callers can set this to FALSE to disable sliding. It should be
68 * re-enabled afterwards. */
69extern bool can_slide;
70
71#define BORDER_WIDTH 2
72#define GOTO_WIDTH 2
73
74/*
75 * Iterate over all map tiles that intersect with the given GUI rectangle.
76 * The order of iteration is guaranteed to satisfy the painter's algorithm.
77 * The iteration covers not only tiles but tile edges and corners.
78 *
79 * GRI_x0, GRI_y0: gives the GUI origin of the rectangle.
80 *
81 * GRI_width, GRI_height: gives the GUI width and height of the rectangle.
82 * These values may be negative.
83 *
84 * _t, _e, _c: the tile, edge, or corner that is being iterated, declared
85 * inside the macro. Usually, only one of them will be non-NULL at a time.
86 * These values may be passed directly to fill_sprite_array().
87 *
88 * _x, _y: the canvas position of the current element, declared inside
89 * the macro. Each element is assumed to be tileset_tile_width(tileset) *
90 * tileset_tile_height(tileset) in size. If an element is larger, the
91 * caller needs to use a larger rectangle of iteration.
92 *
93 * The grid of iteration is rather complicated. For a picture of it see
94 * https://files.freeciv.org/dev/newgrid.png
95 * (originally newgrid.png in PR#12085).
96 */
97#define gui_rect_iterate(GRI_x0, GRI_y0, GRI_width, GRI_height, \
98 _t, _e, _c, _zoom) \
99{ \
100 int _x_##_0 = (GRI_x0), _y_##_0 = (GRI_y0); \
101 int _x_##_w = (GRI_width), _y_##_h = (GRI_height); \
102 \
103 if (_x_##_w < 0) { \
104 _x_##_0 += _x_##_w; \
105 _x_##_w = -_x_##_w; \
106 } \
107 if (_y_##_h < 0) { \
108 _y_##_0 += _y_##_h; \
109 _y_##_h = -_y_##_h; \
110 } \
111 if (_x_##_w > 0 && _y_##_h > 0) { \
112 struct tile_edge _t##_e; \
113 struct tile_corner _t##_c; \
114 int _t##_xi, _t##_yi, _t##_si, _t##_di; \
115 const int _t##_r1 = (tileset_is_isometric(tileset) ? 2 : 1); \
116 const int _t##_r2 = _t##_r1 * 2; /* Double the ratio */ \
117 const int _t##_w = tileset_tile_width(tileset) * _zoom; \
118 const int _t##_h = tileset_tile_height(tileset) * _zoom; \
119 /* Don't divide by _r2 yet, to avoid integer rounding errors. */ \
120 const int _t##_x0 = DIVIDE(_x_##_0 * _t##_r2, _t##_w) - _t##_r1 / 2;\
121 const int _t##_y0 = DIVIDE(_y_##_0 * _t##_r2, _t##_h) - _t##_r1 / 2;\
122 const int _t##_x1 = DIVIDE((_x_##_0 + _x_##_w) * _t##_r2 + _t##_w - 1,\
123 _t##_w) + _t##_r1; \
124 const int _t##_y1 = DIVIDE((_y_##_0 + _y_##_h) * _t##_r2 + _t##_h - 1,\
125 _t##_h) + _t##_r1; \
126 const int _t##_count = (_t##_x1 - _t##_x0) * (_t##_y1 - _t##_y0); \
127 int _t##_index = 0; \
128 \
129 log_debug("Iterating over %d-%d x %d-%d rectangle.", \
130 _t##_x1, _t##_x0, _t##_y1, _t##_y0); \
131 for (; _t##_index < _t##_count; _t##_index++) { \
132 struct tile *_t = NULL; \
133 struct tile_edge *_e = NULL; \
134 struct tile_corner *_c = NULL; \
135 \
136 _t##_xi = _t##_x0 + (_t##_index % (_t##_x1 - _t##_x0)); \
137 _t##_yi = _t##_y0 + (_t##_index / (_t##_x1 - _t##_x0)); \
138 _t##_si = _t##_xi + _t##_yi; \
139 _t##_di = _t##_yi - _t##_xi; \
140 if (2 == _t##_r1 /* tileset_is_isometric(tileset) */) { \
141 if ((_t##_xi + _t##_yi) % 2 != 0) { \
142 continue; \
143 } \
144 if (_t##_xi % 2 == 0 && _t##_yi % 2 == 0) { \
145 if ((_t##_xi + _t##_yi) % 4 == 0) { \
146 /* Tile */ \
147 _t = map_pos_to_tile(&(wld.map), _t##_si / 4 - 1, _t##_di / 4); \
148 } else { \
149 /* Corner */ \
150 _c = &_t##_c; \
151 _c->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \
152 (_t##_di - 2) / 4); \
153 _c->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \
154 (_t##_di - 2) / 4); \
155 _c->tile[2] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \
156 (_t##_di + 2) / 4); \
157 _c->tile[3] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \
158 (_t##_di + 2) / 4); \
159 if (tileset_hex_width(tileset) > 0) { \
160 _e = &_t##_e; \
161 _e->type = EDGE_UD; \
162 _e->tile[0] = _c->tile[0]; \
163 _e->tile[1] = _c->tile[2]; \
164 } else if (tileset_hex_height(tileset) > 0) { \
165 _e = &_t##_e; \
166 _e->type = EDGE_LR; \
167 _e->tile[0] = _c->tile[1]; \
168 _e->tile[1] = _c->tile[3]; \
169 } \
170 } \
171 } else { \
172 /* Edge. */ \
173 _e = &_t##_e; \
174 if (_t##_si % 4 == 0) { \
175 _e->type = EDGE_NS; \
176 _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 4) / 4, \
177 (_t##_di - 2) / 4); /*N*/ \
178 _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 4) / 4, \
179 (_t##_di + 2) / 4); /*S*/ \
180 } else { \
181 _e->type = EDGE_WE; \
182 _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \
183 _t##_di / 4); /*W*/ \
184 _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \
185 _t##_di / 4); /*E*/ \
186 } \
187 } \
188 } else { \
189 if (_t##_si % 2 == 0) { \
190 if (_t##_xi % 2 == 0) { \
191 /* Corner. */ \
192 _c = &_t##_c; \
193 _c->tile[0] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \
194 _t##_yi / 2 - 1); /*NW*/ \
195 _c->tile[1] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \
196 _t##_yi / 2 - 1); /*NE*/ \
197 _c->tile[2] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \
198 _t##_yi / 2); /*SE*/ \
199 _c->tile[3] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \
200 _t##_yi / 2); /*SW*/ \
201 } else { \
202 /* Tile. */ \
203 _t = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \
204 (_t##_yi - 1) / 2); \
205 } \
206 } else { \
207 /* Edge. */ \
208 _e = &_t##_e; \
209 if (_t##_yi % 2 == 0) { \
210 _e->type = EDGE_NS; \
211 _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \
212 _t##_yi / 2 - 1); /*N*/ \
213 _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \
214 _t##_yi / 2); /*S*/ \
215 } else { \
216 _e->type = EDGE_WE; \
217 _e->tile[0] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \
218 (_t##_yi - 1) / 2); /*W*/ \
219 _e->tile[1] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \
220 (_t##_yi - 1) / 2); /*E*/ \
221 } \
222 } \
223 }
224
225#define gui_rect_iterate_end \
226 } \
227 } \
228}
229
230#define gui_rect_iterate_coord(GRI_x0, GRI_y0, GRI_width, GRI_height, \
231 _t, _e, _c, _x, _y, _zoom) \
232 gui_rect_iterate(GRI_x0, GRI_y0, GRI_width, GRI_height, \
233 _t, _e, _c, _zoom) { \
234 int _x, _y; \
235 \
236 _x = _t##_xi * _t##_w / _t##_r2 - _t##_w / 2; \
237 _y = _t##_yi * _t##_h / _t##_r2 - _t##_h / 2;
238
239#define gui_rect_iterate_coord_end \
240 } gui_rect_iterate_end
241
242void refresh_tile_mapcanvas(struct tile *ptile,
243 bool full_refresh, bool write_to_screen);
244void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile,
245 bool full_refresh, bool write_to_screen);
246void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile,
247 bool full_refresh, bool write_to_screen);
248
250
251void map_to_gui_vector(const struct tileset *t, float zoom,
252 float *gui_dx, float *gui_dy, int map_dx, int map_dy);
253bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom,
254 const struct tile *ptile)
255 fc__attribute((nonnull (1, 2, 4)));
256struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom);
258 float zoom);
259
260void get_mapview_scroll_window(float *xmin, float *ymin,
261 float *xmax, float *ymax,
262 int *xsize, int *ysize);
263void get_mapview_scroll_step(int *xstep, int *ystep);
265void set_mapview_scroll_pos(int scroll_x, int scroll_y, float zoom);
266
267void set_mapview_origin(float gui_x0, float gui_y0, float zoom);
268struct tile *get_center_tile_mapcanvas(void);
269void center_tile_mapcanvas(const struct tile *ptile)
270 fc__attribute((nonnull (1)));
271
272bool tile_visible_mapcanvas(struct tile *ptile);
274
275void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom,
276 int canvas_x, int canvas_y);
277void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom,
278 int canvas_x, int canvas_y);
279void put_city(struct city *pcity, struct canvas *pcanvas, float zoom,
280 int canvas_x, int canvas_y);
281void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom,
282 int canvas_x, int canvas_y);
283
285 struct canvas *pcanvas,
286 int canvas_x, int canvas_y, int *upkeep_cost,
287 int happy_cost);
288void toggle_city_color(struct city *pcity);
289void toggle_unit_color(struct unit *punit);
290
291void put_nuke_mushroom_pixmaps(struct tile *ptile);
292
293void put_one_element(struct canvas *pcanvas, float zoom,
294 enum mapview_layer layer,
295 const struct tile *ptile,
296 const struct tile_edge *pedge,
297 const struct tile_corner *pcorner,
298 const struct unit *punit, const struct city *pcity,
299 int canvas_x, int canvas_y,
300 const struct city *citymode,
301 const struct unit_type *putype);
302
303void put_drawn_sprites(struct canvas *pcanvas, float zoom,
304 int canvas_x, int canvas_y,
305 int count, struct drawn_sprite *pdrawn,
306 bool fog);
307
308void update_map_canvas(int canvas_x, int canvas_y, int width, int height);
311void update_tile_label(struct tile *ptile);
312
314 int width_base, int height_base);
316 int width_base, int height_base);
317
318void draw_segment(struct tile *ptile, enum direction8 dir)
319 fc__attribute((nonnull (1)));
320
321void decrease_unit_hp_smooth(struct unit *punit0, int hp0,
322 struct unit *punit1, int hp1);
323void move_unit_map_canvas(struct unit *punit,
324 struct tile *ptile, int dx, int dy);
325
326struct city *find_city_or_settler_near_tile(const struct tile *ptile,
327 struct unit **punit);
328struct city *find_city_near_tile(const struct tile *ptile);
329
331 char *buf, size_t buf_len);
333 char *name_buffer,
334 size_t name_buffer_len,
335 char *growth_buffer,
336 size_t growth_buffer_len,
343
344bool map_canvas_resized(int width, int height);
347
348void get_spaceship_dimensions(int *width, int *height);
349void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y,
350 const struct player *pplayer);
351
352void link_marks_init(void);
353void link_marks_free(void);
354
355void link_marks_draw_all(void);
356void link_marks_clear_all(void);
358
359void link_mark_add_new(enum text_link_type type, int id);
360void link_mark_restore(enum text_link_type type, int id);
361
365
366enum topo_comp_lvl tileset_map_topo_compatible(int topology_id,
367 struct tileset *tset,
368 int *tset_topo);
369const char *describe_topology(int topo);
370
371void animations_init(void);
372void animations_free(void);
374void update_animation(void);
375
376#ifdef __cplusplus
377}
378#endif /* __cplusplus */
379
380#endif /* FC__MAPVIEW_COMMON_H */
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
struct canvas * pcanvas
Definition canvas_g.h:42
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
text_link_type
GType type
Definition repodlgs.c:1313
void mapdeco_set_highlight(const struct tile *ptile, bool highlight)
void link_mark_restore(enum text_link_type type, int id)
void put_nuke_mushroom_pixmaps(struct tile *ptile)
void init_mapcanvas_and_overview(void)
struct city * find_city_or_settler_near_tile(const struct tile *ptile, struct unit **punit)
void put_drawn_sprites(struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y, int count, struct drawn_sprite *pdrawn, bool fog)
void update_map_canvas_visible(void)
bool tile_visible_mapcanvas(struct tile *ptile)
void set_mapview_origin(float gui_x0, float gui_y0, float zoom)
void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void map_to_gui_vector(const struct tileset *t, float zoom, float *gui_dx, float *gui_dy, int map_dx, int map_dy)
void update_tile_label(struct tile *ptile)
void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
enum topo_comp_lvl tileset_map_topo_compatible(int topology_id, struct tileset *tset, int *tset_topo)
struct view mapview
void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh, bool write_to_screen)
void put_city(struct city *pcity, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
struct tile * get_center_tile_mapcanvas(void)
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void draw_segment(struct tile *ptile, enum direction8 dir) fc__attribute((nonnull(1)))
struct city * find_city_near_tile(const struct tile *ptile)
void mapdeco_free(void)
void free_mapcanvas_and_overview(void)
void get_mapview_scroll_pos(int *scroll_x, int *scroll_y)
bool mapdeco_is_highlight_set(const struct tile *ptile)
void center_tile_mapcanvas(const struct tile *ptile) fc__attribute((nonnull(1)))
void get_mapview_scroll_window(float *xmin, float *ymin, float *xmax, float *ymax, int *xsize, int *ysize)
void move_unit_map_canvas(struct unit *punit, struct tile *ptile, int dx, int dy)
void mapdeco_set_gotoroute(const struct unit *punit)
void unqueue_mapview_updates(bool write_to_screen)
void get_mapview_scroll_step(int *xstep, int *ystep)
void get_city_mapview_trade_routes(struct city *pcity, char *trade_routes_buffer, size_t trade_routes_buffer_len, enum color_std *trade_routes_color)
void get_city_mapview_production(struct city *pcity, char *buf, size_t buf_len)
void show_city_descriptions(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
void set_mapview_scroll_pos(int scroll_x, int scroll_y, float zoom)
void mapdeco_init(void)
void client_infratile_set(struct tile *ptile)
void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void mapdeco_clear_gotoroutes(void)
void put_unit_city_overlays(struct unit *punit, struct canvas *pcanvas, int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost)
void put_one_element(struct canvas *pcanvas, float zoom, enum mapview_layer layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, int canvas_x, int canvas_y, const struct city *citymode, const struct unit_type *putype)
bool mapdeco_is_gotoline_set(const struct tile *ptile, enum direction8 dir)
void animations_init(void)
void update_animation(void)
void toggle_city_color(struct city *pcity)
struct tile * canvas_pos_to_nearest_tile(float canvas_x, float canvas_y, float zoom)
void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir)
void update_map_canvas(int canvas_x, int canvas_y, int width, int height)
void link_marks_decrease_turn_counters(void)
topo_comp_lvl
@ TOPO_COMPATIBLE
@ TOPO_INCOMP_HARD
@ TOPO_INCOMP_SOFT
void mapdeco_clear_crosshairs(void)
void link_marks_draw_all(void)
void update_city_description(struct city *pcity)
void link_marks_init(void)
struct tile * client_infratile(void)
void set_frame_by_frame_animation(void)
void mapdeco_clear_highlights(void)
void link_marks_clear_all(void)
const char * describe_topology(int topo)
void toggle_unit_color(struct unit *punit)
void animations_free(void)
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom, const struct tile *ptile) fc__attribute((nonnull(1
bool map_canvas_resized(int width, int height)
void link_mark_add_new(enum text_link_type type, int id)
bool can_slide
void refresh_tile_mapcanvas(struct tile *ptile, bool full_refresh, bool write_to_screen)
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh, bool write_to_screen)
void get_spaceship_dimensions(int *width, int *height)
void decrease_unit_hp_smooth(struct unit *punit0, int hp0, struct unit *punit1, int hp1)
void get_city_mapview_name_and_growth(struct city *pcity, char *name_buffer, size_t name_buffer_len, char *growth_buffer, size_t growth_buffer_len, enum color_std *growth_color, enum color_std *production_color)
bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const struct player *pplayer)
bool struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
void mapdeco_remove_gotoline(const struct tile *ptile, enum direction8 dir)
bool mapdeco_is_crosshair_set(const struct tile *ptile)
void link_marks_free(void)
void show_tile_labels(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
Definition city.h:317
Definition tile.h:50
Definition unit.h:140
int height
int store_width
float gui_x0
int tile_height
bool can_do_cached_drawing
int store_height
struct canvas * store
struct canvas * tmp_store
float gui_y0
int width
int tile_width
#define fc__attribute(x)
Definition support.h:99