Freeciv21
Develop your civilization from humble roots to a global empire
view_map_common.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2023 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // common
14 #include "featured_text.h"
15 #include "map.h"
16 // include
17 #include "colors_g.h"
18 
19 #include "map_updates_handler.h"
20 #include "tileset/tilespec.h"
21 
22 struct view {
23  float gui_x0, gui_y0;
24  int width, height; // Size in pixels.
26  bool can_do_cached_drawing; // TRUE if cached drawing is possible.
27  QPixmap *store, *tmp_store;
28 };
29 
30 void mapdeco_init();
31 void mapdeco_free();
32 bool mapdeco_is_highlight_set(const struct tile *ptile);
33 void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair);
34 bool mapdeco_is_crosshair_set(const struct tile *ptile);
36 void mapdeco_set_gotoroute(const struct unit *punit);
37 void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir,
38  bool safe);
39 bool mapdeco_is_gotoline_set(const struct tile *ptile, enum direction8 dir,
40  bool *safe);
42 
43 extern struct view mapview;
44 
45 #define GOTO_WIDTH 2
46 
47 void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh);
48 void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile,
49  bool full_refresh);
50 void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile,
51  bool full_refresh);
52 
53 std::map<freeciv::map_updates_handler::update_type, QRectF> update_rects();
55 void map_to_gui_vector(const struct tileset *t, float *gui_dx, float *gui_dy,
56  int map_dx, int map_dy);
57 void map_to_gui_pos(const struct tileset *t, float *gui_x, float *gui_y,
58  int map_x, int map_y);
59 bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, const tile *ptile);
60 struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y);
61 struct tile *canvas_pos_to_nearest_tile(float canvas_x, float canvas_y);
62 
63 void gui_distance_vector(const struct tileset *t, float *gui_dx,
64  float *gui_dy, float gui_x0, float gui_y0,
65  float gui_x1, float gui_y1);
66 
67 void get_mapview_scroll_window(float *xmin, float *ymin, float *xmax,
68  float *ymax, int *xsize, int *ysize);
69 void get_mapview_scroll_pos(int *scroll_x, int *scroll_y);
70 
71 void set_mapview_origin(float gui_x0, float gui_y0);
73 
74 bool tile_visible_mapcanvas(struct tile *ptile);
76 
77 void put_unit(const struct unit *punit, QPixmap *pcanvas,
78  const QPoint &canvas_loc);
79 void put_terrain(struct tile *ptile, QPixmap *pcanvas,
80  const QPoint &canvas_loc);
81 
82 void put_unit_city_overlays(const unit *punit, QPixmap *pcanvas,
83  int canvas_x, int canvas_y,
84  const int *upkeep_cost, int happy_cost);
85 void toggle_city_color(struct city *pcity);
86 void toggle_unit_color(struct unit *punit);
87 
88 void put_nuke_mushroom_pixmaps(struct tile *ptile);
89 
90 void put_drawn_sprites(QPixmap *pcanvas, const QPoint &canvas_loc,
91  const std::vector<drawn_sprite> &sprites, bool fog,
92  bool city_unit = false);
93 
94 void update_map_canvas(int canvas_x, int canvas_y, int width, int height);
96 void update_city_description(struct city *pcity);
97 void update_tile_label(struct tile *ptile);
98 
99 void show_city_descriptions(int canvas_base_x, int canvas_base_y,
100  int width_base, int height_base);
101 void show_tile_labels(int canvas_base_x, int canvas_base_y, int width_base,
102  int height_base);
103 
104 void draw_segment(const tile *ptile, enum direction8 dir, bool safe);
105 
106 void decrease_unit_hp_smooth(struct unit *punit0, int hp0,
107  struct unit *punit1, int hp1);
108 void animate_unit_explosion(const tile *location);
109 void move_unit_map_canvas(struct unit *punit, struct tile *ptile, int dx,
110  int dy);
111 
112 struct city *find_city_or_settler_near_tile(const struct tile *ptile,
113  struct unit **punit);
114 
115 void get_city_mapview_production(const city *pcity, char *buf,
116  size_t buf_len);
117 void get_city_mapview_name_and_growth(const city *pcity, char *name_buffer,
118  size_t name_buffer_len,
119  char *growth_buffer,
120  size_t growth_buffer_len,
121  enum color_std *growth_color,
122  enum color_std *production_color);
123 void get_city_mapview_trade_routes(const city *pcity,
124  char *trade_routes_buffer,
125  size_t trade_routes_buffer_len,
126  enum color_std *trade_routes_color);
127 
128 void map_canvas_resized(int width, int height);
131 
132 void link_marks_init();
133 void link_marks_free();
134 
135 void link_marks_draw_all();
136 void link_marks_clear_all();
138 
139 void link_mark_add_new(enum text_link_type type, int id);
140 void link_mark_restore(enum text_link_type type, int id);
141 
145  TOPO_INCOMP_HARD = 2
146 };
147 
148 enum topo_comp_lvl tileset_map_topo_compatible(int topology_id,
149  struct tileset *tset);
text_link_type
Definition: city.h:291
Definition: tile.h:42
Definition: unit.h:134
int height
QPixmap * store
int store_width
QPixmap * tmp_store
float gui_x0
bool can_do_cached_drawing
int store_height
float gui_y0
int width
void link_mark_restore(enum text_link_type type, int id)
Add a visible link for 1 turn.
void get_city_mapview_trade_routes(const city *pcity, char *trade_routes_buffer, size_t trade_routes_buffer_len, enum color_std *trade_routes_color)
Find the mapview city trade routes text for the given city, and place it into the buffer.
void put_nuke_mushroom_pixmaps(struct tile *ptile)
Animate the nuke explosion at map(x, y).
bool tile_visible_mapcanvas(struct tile *ptile)
Return TRUE iff the given map position has a tile visible on the map canvas.
void link_marks_draw_all()
Draw all link marks.
void mapdeco_init()
Called when we receive map dimensions.
void set_mapview_origin(float gui_x0, float gui_y0)
Change the mapview origin, clip it, and update everything.
void update_tile_label(struct tile *ptile)
void map_to_gui_vector(const struct tileset *t, float *gui_dx, float *gui_dy, int map_dx, int map_dy)
Translate from a cartesian system to the GUI system.
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y)
Finds the tile corresponding to pixel coordinates.
void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
Marks the given tile as having a "crosshair" map decoration.
void draw_segment(const tile *ptile, enum direction8 dir, bool safe)
Draw a goto line at the given location and direction.
void init_mapcanvas_and_overview()
Sets up data for the mapview and overview.
struct view mapview
void get_city_mapview_production(const city *pcity, char *buf, size_t buf_len)
Find the mapview city production text for the given city, and place it into the buffer.
void get_mapview_scroll_pos(int *scroll_x, int *scroll_y)
Find the current scroll position (origin) of the mapview.
void mapdeco_clear_crosshairs()
Clears all previous set tile crosshair decorations.
bool mapdeco_is_highlight_set(const struct tile *ptile)
Return TRUE if the given tile is highlighted.
void get_mapview_scroll_window(float *xmin, float *ymin, float *xmax, float *ymax, int *xsize, int *ysize)
Return the scroll dimensions of the clipping window for the mapview window.
void move_unit_map_canvas(struct unit *punit, struct tile *ptile, int dx, int dy)
Animates punit's "smooth" move from (x0, y0) to (x0+dx, y0+dy).
bool mapdeco_is_gotoline_set(const struct tile *ptile, enum direction8 dir, bool *safe)
Returns TRUE if a goto line should be drawn from the given tile in the given direction.
struct tile * get_center_tile_mapcanvas()
Finds the current center tile of the mapcanvas.
struct city * find_city_or_settler_near_tile(const struct tile *ptile, struct unit **punit)
Find the "best" city/settlers to associate with the selected tile.
void get_city_mapview_name_and_growth(const 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)
Fill the two buffers which information about the city which is shown below it.
void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh)
Refreshes a single tile on the map canvas.
void mapdeco_set_gotoroute(const struct unit *punit)
Set the map decorations for the given unit's goto route.
void show_city_descriptions(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
Show descriptions for all cities visible on the map canvas.
void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir, bool safe)
Add a goto line from the given tile 'ptile' in the direction 'dir'.
void map_canvas_resized(int width, int height)
Called if the map in the GUI is resized.
void free_mapcanvas_and_overview()
Frees resources allocated for mapview and overview.
void put_drawn_sprites(QPixmap *pcanvas, const QPoint &canvas_loc, const std::vector< drawn_sprite > &sprites, bool fog, bool city_unit=false)
Draw an array of drawn sprites onto the canvas.
void mapdeco_free()
Free all memory used for map decorations.
void put_terrain(struct tile *ptile, QPixmap *pcanvas, const QPoint &canvas_loc)
Draw the given tile terrain onto the canvas store at the given location.
void link_marks_free()
Free the link marks.
void toggle_city_color(struct city *pcity)
Toggle the city color.
void update_map_canvas(int canvas_x, int canvas_y, int width, int height)
Update (refresh) the map canvas starting at the given tile (in map coordinates) and with the given di...
void link_marks_clear_all()
Clear all visible links.
topo_comp_lvl
@ TOPO_COMPATIBLE
@ TOPO_INCOMP_HARD
@ TOPO_INCOMP_SOFT
void animate_unit_explosion(const tile *location)
Draws an explosion animation on the given sprite.
void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh)
Refreshes a single city on the map canvas.
void update_city_description(struct city *pcity)
Update the city description for the given city.
void put_unit_city_overlays(const unit *punit, QPixmap *pcanvas, int canvas_x, int canvas_y, const int *upkeep_cost, int happy_cost)
Draw food, gold, and shield upkeep values on the unit.
void map_to_gui_pos(const struct tileset *t, float *gui_x, float *gui_y, int map_x, int map_y)
Translate from map to gui coordinate systems.
void gui_distance_vector(const struct tileset *t, float *gui_dx, float *gui_dy, float gui_x0, float gui_y0, float gui_x1, float gui_y1)
Find the vector with minimum "real" distance between two GUI positions.
void toggle_unit_color(struct unit *punit)
Toggle the unit color.
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh)
Refreshes a single unit on the map canvas.
void link_mark_add_new(enum text_link_type type, int id)
Add a visible link for 2 turns.
void link_marks_decrease_turn_counters()
Clear all visible links.
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, const tile *ptile)
Finds the canvas coordinates for a map position.
void link_marks_init()
Initialize the link marks.
void decrease_unit_hp_smooth(struct unit *punit0, int hp0, struct unit *punit1, int hp1)
This function is called to decrease a unit's HP smoothly in battle when combat_animation is turned on...
void mapdeco_clear_gotoroutes()
Clear all goto line map decorations and queues mapview updates for the affected tiles.
bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
Return TRUE iff the given map position has a tile visible within the interior of the map canvas.
enum topo_comp_lvl tileset_map_topo_compatible(int topology_id, struct tileset *tset)
Are the topology and tileset compatible?
bool mapdeco_is_crosshair_set(const struct tile *ptile)
Returns TRUE if there is a "crosshair" decoration set at the given tile.
void show_tile_labels(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
Show labels for all tiles visible on the map canvas.
void update_map_canvas_visible()
Schedules an update of (only) the visible part of the map at the next unqueue_mapview_update().
struct tile * canvas_pos_to_nearest_tile(float canvas_x, float canvas_y)
Finds the tile corresponding to pixel coordinates.
std::map< freeciv::map_updates_handler::update_type, QRectF > update_rects()
Calculates the area covered by each update type.
void put_unit(const struct unit *punit, QPixmap *pcanvas, const QPoint &canvas_loc)
Draw the given unit onto the canvas store at the given location.
void unqueue_mapview_updates()
See comment in update_map_canvas_visible().