![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#include <array>#include <QCoreApplication>#include <QElapsedTimer>#include <QEventLoop>#include <QGlobalStatic>#include <QHash>#include <QLoggingCategory>#include <QPainter>#include <QPixmap>#include <QSet>#include <QTimer>#include "fcintl.h"#include "log.h"#include "rand.h"#include "support.h"#include "featured_text.h"#include "game.h"#include "map.h"#include "traderoutes.h"#include "unitlist.h"#include "citydlg_g.h"#include "mapctrl_g.h"#include "mapview_g.h"#include "canvas.h"#include "citydlg_common.h"#include "client_main.h"#include "climap.h"#include "control.h"#include "editor.h"#include "map_updates_handler.h"#include "overview_common.h"#include "qtg_cxxside.h"#include "tileset/tilespec.h"#include "views/view_map_common.h"#include "views/view_map_geometry.h"#include "speclist.h"
Include dependency graph for view_map_common.cpp:Go to the source code of this file.
Classes | |
| struct | gotoline_counter |
| struct | trade_route_line |
| struct | link_mark |
| Map link mark module: it makes link marks when a link is sent by chating, or restore a mark with clicking a link on the chatline. More... | |
Macros | |
| #define | COLOR_MAPVIEW_TILELABEL COLOR_MAPVIEW_CITYTEXT |
| #define | SPECLIST_TAG link_mark |
| #define | SPECLIST_TYPE struct link_mark |
| #define | link_marks_iterate(pmark) TYPED_LIST_ITERATE(struct link_mark, link_marks, pmark) |
| #define | link_marks_iterate_end LIST_ITERATE_END |
Typedefs | |
| typedef QHash< const struct tile *, struct gotoline_counter * > | gotohash |
Functions | |
| static void | base_canvas_to_map_pos (int *map_x, int *map_y, float canvas_x, float canvas_y) |
| Finds the map coordinates corresponding to pixel coordinates. More... | |
| Q_GLOBAL_STATIC (QElapsedTimer, anim_timer) | |
| void | anim_delay (int milliseconds) |
| void | refresh_tile_mapcanvas (const tile *ptile, bool full_refresh) |
| Refreshes a single tile on the map canvas. More... | |
| void | refresh_unit_mapcanvas (struct unit *punit, struct tile *ptile, bool full_refresh) |
| Refreshes a single unit on the map canvas. More... | |
| void | refresh_city_mapcanvas (struct city *pcity, struct tile *ptile, bool full_refresh) |
| Refreshes a single city on the map canvas. More... | |
| 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. More... | |
| 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. More... | |
| static void | gui_to_map_pos (const struct tileset *t, int *map_x, int *map_y, float gui_x, float gui_y) |
| Translate from gui to map coordinate systems. More... | |
| bool | tile_to_canvas_pos (float *canvas_x, float *canvas_y, const tile *ptile) |
| Finds the canvas coordinates for a map position. More... | |
| struct tile * | canvas_pos_to_tile (float canvas_x, float canvas_y) |
| Finds the tile corresponding to pixel coordinates. More... | |
| struct tile * | canvas_pos_to_nearest_tile (float canvas_x, float canvas_y) |
| Finds the tile corresponding to pixel coordinates. More... | |
| static void | normalize_gui_pos (const struct tileset *t, float *gui_x, float *gui_y) |
| Normalize (wrap) the GUI position. More... | |
| 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. More... | |
| static void | base_set_mapview_origin (float gui_x0, float gui_y0) |
| Move the GUI origin to the given normalized, clipped origin. More... | |
| static bool | calc_mapview_origin (float *gui_x0, float *gui_y0) |
| Adjust mapview origin values. More... | |
| void | set_mapview_origin (float gui_x0, float gui_y0) |
| Change the mapview origin, clip it, and update everything. More... | |
| 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. More... | |
| void | get_mapview_scroll_pos (int *scroll_x, int *scroll_y) |
| Find the current scroll position (origin) of the mapview. More... | |
| struct tile * | get_center_tile_mapcanvas () |
| Finds the current center tile of the mapcanvas. More... | |
| bool | tile_visible_mapcanvas (struct tile *ptile) |
| Return TRUE iff the given map position has a tile visible on the map canvas. More... | |
| 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. More... | |
| void | put_drawn_sprites (QPixmap *pcanvas, const QPoint &canvas_loc, const std::vector< drawn_sprite > &sprites, bool fog, bool city_unit) |
| Draw an array of drawn sprites onto the canvas. More... | |
| void | put_one_element (QPixmap *pcanvas, const std::unique_ptr< freeciv::layer > &layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const QPoint &canvas_loc) |
| Draw one layer of a tile, edge, corner, unit, and/or city onto the canvas at the given position. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| void | toggle_city_color (struct city *pcity) |
| Toggle the city color. More... | |
| void | toggle_unit_color (struct unit *punit) |
| Toggle the unit color. More... | |
| void | put_nuke_mushroom_pixmaps (struct tile *ptile) |
| Animate the nuke explosion at map(x, y). More... | |
| static void | put_one_tile (QPixmap *pcanvas, const std::unique_ptr< freeciv::layer > &layer, const tile *ptile, const QPoint &canvas_loc) |
| Draw some or all of a tile onto the canvas. More... | |
| static int | trade_route_to_canvas_lines (const struct tile *ptile1, const struct tile *ptile2, struct trade_route_line *lines) |
| Depending on where ptile1 and ptile2 are on the map canvas, a trade route line may need to be drawn as two disjointed line segments. More... | |
| static void | draw_trade_route_line (const struct tile *ptile1, const struct tile *ptile2, enum color_std color) |
| Draw a colored trade route line from one tile to another. More... | |
| static void | draw_trade_routes_for_city (const struct city *pcity_src) |
| Draw all trade routes for the given city. More... | |
| static void | draw_trade_routes () |
| Draw trade routes between cities as lines on the main map canvas. More... | |
| 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 dimensions (also in map coordinates). More... | |
| void | update_map_canvas_visible () |
| Schedules an update of (only) the visible part of the map at the next unqueue_mapview_update(). More... | |
| void | update_city_description (struct city *pcity) |
| Update the city description for the given city. More... | |
| void | update_tile_label (const tile *ptile) |
| Update the label for the given tile. More... | |
| static QSize | show_tile_label (QPixmap *pcanvas, int canvas_x, int canvas_y, const tile *ptile) |
| Draw a label for the given tile. More... | |
| 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. More... | |
| 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. More... | |
| void | draw_segment (const tile *src_tile, enum direction8 dir, bool safe) |
| Draw a goto line at the given location and direction. More... | |
| 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. More... | |
| void | animate_unit_explosion (const tile *location) |
| Draws an explosion animation on the given sprite. More... | |
| void | move_unit_map_canvas (struct unit *punit, struct tile *src_tile, int dx, int dy) |
| Animates punit's "smooth" move from (x0, y0) to (x0+dx, y0+dy). More... | |
| 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. More... | |
| static void | append_city_buycost_string (const struct city *pcity, char *buffer, int buffer_len) |
| Append the buy cost of the current production of the given city to the already nullptr-terminated buffer. More... | |
| void | get_city_mapview_production (const city *pcity, char *buffer, size_t buffer_len) |
| Find the mapview city production text for the given city, and place it into the buffer. More... | |
| void | get_city_mapview_trade_routes (const city *pcity, char *trade_routes_buffer, size_t trade_routes_buffer_len, enum color_std *pcolor) |
| Find the mapview city trade routes text for the given city, and place it into the buffer. More... | |
| std::map< freeciv::map_updates_handler::update_type, QRectF > | update_rects () |
| Calculates the area covered by each update type. More... | |
| void | unqueue_mapview_updates () |
| See comment in update_map_canvas_visible(). More... | |
| 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. More... | |
| static bool | can_do_cached_drawing () |
| Returns TRUE if cached drawing is possible. More... | |
| void | mapdeco_init () |
| Called when we receive map dimensions. More... | |
| void | mapdeco_free () |
| Free all memory used for map decorations. More... | |
| bool | mapdeco_is_highlight_set (const struct tile *ptile) |
| Return TRUE if the given tile is highlighted. More... | |
| void | mapdeco_set_crosshair (const struct tile *ptile, bool crosshair) |
| Marks the given tile as having a "crosshair" map decoration. More... | |
| bool | mapdeco_is_crosshair_set (const struct tile *ptile) |
| Returns TRUE if there is a "crosshair" decoration set at the given tile. More... | |
| void | mapdeco_clear_crosshairs () |
| Clears all previous set tile crosshair decorations. More... | |
| 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'. More... | |
| void | mapdeco_set_gotoroute (const struct unit *punit) |
| Set the map decorations for the given unit's goto route. More... | |
| 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. More... | |
| void | mapdeco_clear_gotoroutes () |
| Clear all goto line map decorations and queues mapview updates for the affected tiles. More... | |
| void | map_canvas_resized (int width, int height) |
| Called if the map in the GUI is resized. More... | |
| void | init_mapcanvas_and_overview () |
| Sets up data for the mapview and overview. More... | |
| void | free_mapcanvas_and_overview () |
| Frees resources allocated for mapview and overview. More... | |
| static struct link_mark * | link_mark_find (enum text_link_type type, int id) |
| Find a link mark in the list. More... | |
| static struct link_mark * | link_mark_new (enum text_link_type type, int id, int turns) |
| Create a new link mark. More... | |
| static void | link_mark_destroy (struct link_mark *pmark) |
| Remove a link mark. More... | |
| static struct tile * | link_mark_tile (const struct link_mark *pmark) |
| Returns the location of the pointed mark. More... | |
| static QColor | link_mark_color (const struct link_mark *pmark) |
| Returns the color of the pointed mark. More... | |
| static void | link_mark_draw (const struct link_mark *pmark) |
| Print a link mark. More... | |
| void | link_marks_init () |
| Initialize the link marks. More... | |
| void | link_marks_free () |
| Free the link marks. More... | |
| void | link_marks_draw_all () |
| Draw all link marks. More... | |
| void | link_marks_clear_all () |
| Clear all visible links. More... | |
| void | link_marks_decrease_turn_counters () |
| Clear all visible links. More... | |
| void | link_mark_add_new (enum text_link_type type, int id) |
| Add a visible link for 2 turns. More... | |
| void | link_mark_restore (enum text_link_type type, int id) |
| Add a visible link for 1 turn. More... | |
| enum topo_comp_lvl | tileset_map_topo_compatible (int topology_id, struct tileset *tset) |
| Are the topology and tileset compatible? More... | |
Variables | |
| struct view | mapview |
| static const int | MAX_TRADE_ROUTE_DRAW_LINES = 2 |
| static int | color_index = 0 |
| static int | max_desc_width = 0 |
| static int | max_desc_height = 0 |
| static QSize | max_label_size = QSize() |
| static struct link_mark_list * | link_marks = nullptr |
| #define COLOR_MAPVIEW_TILELABEL COLOR_MAPVIEW_CITYTEXT |
| #define link_marks_iterate | ( | pmark | ) | TYPED_LIST_ITERATE(struct link_mark, link_marks, pmark) |
Definition at line 2339 of file view_map_common.cpp.
| #define link_marks_iterate_end LIST_ITERATE_END |
Definition at line 2341 of file view_map_common.cpp.
| #define SPECLIST_TAG link_mark |
Definition at line 2336 of file view_map_common.cpp.
| #define SPECLIST_TYPE struct link_mark |
Definition at line 2337 of file view_map_common.cpp.
| typedef QHash<const struct tile *, struct gotoline_counter *> gotohash |
Definition at line 75 of file view_map_common.cpp.
| void anim_delay | ( | int | milliseconds | ) |
Definition at line 91 of file view_map_common.cpp.
Referenced by animate_unit_explosion(), and decrease_unit_hp_smooth().
| void animate_unit_explosion | ( | const tile * | location | ) |
Draws an explosion animation on the given sprite.
Definition at line 1518 of file view_map_common.cpp.
Referenced by decrease_unit_hp_smooth(), and handle_unit_bombard_info().
|
static |
Append the buy cost of the current production of the given city to the already nullptr-terminated buffer.
Does nothing if draw_city_buycost is set to FALSE, or if it does not make sense to buy the current production (e.g. coinage).
Definition at line 1774 of file view_map_common.cpp.
Referenced by get_city_mapview_production().
|
static |
Finds the map coordinates corresponding to pixel coordinates.
The resulting position is unwrapped and may be unreal.
Definition at line 332 of file view_map_common.cpp.
Referenced by canvas_pos_to_nearest_tile(), canvas_pos_to_tile(), and tile_to_canvas_pos().
|
static |
Move the GUI origin to the given normalized, clipped origin.
This may be called many times when sliding the mapview.
Definition at line 451 of file view_map_common.cpp.
Referenced by set_mapview_origin().
|
static |
Adjust mapview origin values.
Returns TRUE iff values are different from current mapview.
Definition at line 547 of file view_map_common.cpp.
Referenced by map_canvas_resized(), and set_mapview_origin().
|
static |
Returns TRUE if cached drawing is possible.
If the mapview is too large we have to turn it off.
Definition at line 1963 of file view_map_common.cpp.
Referenced by map_canvas_resized(), and mapdeco_init().
| struct tile* canvas_pos_to_nearest_tile | ( | float | canvas_x, |
| float | canvas_y | ||
| ) |
Finds the tile corresponding to pixel coordinates.
Returns that tile, or the one nearest is the position is off the map. Will never return nullptr.
Definition at line 360 of file view_map_common.cpp.
Referenced by get_center_tile_mapcanvas(), and recenter_button_pressed().
| struct tile* canvas_pos_to_tile | ( | float | canvas_x, |
| float | canvas_y | ||
| ) |
Finds the tile corresponding to pixel coordinates.
Returns that tile, or nullptr if the position is off the map.
Definition at line 343 of file view_map_common.cpp.
Referenced by action_button_pressed(), adjust_workers_button_pressed(), editor_end_selection_rectangle(), editor_mouse_button_press(), editor_mouse_move(), key_city_overlay(), maybe_activate_keyboardless_goto(), map_view::mouseMoveEvent(), release_goto_button(), map_view::shortcut_pressed(), update_line(), and wakeup_button_pressed().
This function is called to decrease a unit's HP smoothly in battle when combat_animation is turned on.
Definition at line 1477 of file view_map_common.cpp.
Referenced by handle_unit_combat_info().
| void draw_segment | ( | const tile * | src_tile, |
| enum direction8 | dir, | ||
| bool | safe | ||
| ) |
Draw a goto line at the given location and direction.
The line goes from the source tile to the adjacent tile in the given direction.
Definition at line 1438 of file view_map_common.cpp.
Referenced by update_map_canvas().
|
static |
Draw a colored trade route line from one tile to another.
Definition at line 1038 of file view_map_common.cpp.
Referenced by draw_trade_routes_for_city().
|
static |
Draw trade routes between cities as lines on the main map canvas.
Definition at line 1092 of file view_map_common.cpp.
Referenced by update_map_canvas().
|
static |
Draw all trade routes for the given city.
Definition at line 1075 of file view_map_common.cpp.
Referenced by draw_trade_routes().
Find the "best" city/settlers to associate with the selected tile.
a. If a visible city is working the tile, return that city. b. If another player's city is working the tile, return nullptr. c. If any selected cities are within range, return the closest one. d. If any cities are within range, return the closest one. e. If any active (with color) settler could work it if they founded a city, choose the closest one (only if punit != nullptr). f. If any settler could work it if they founded a city, choose the closest one (only if punit != nullptr). g. If nobody can work it, return nullptr.
Definition at line 1670 of file view_map_common.cpp.
Referenced by adjust_workers_button_pressed(), freeciv::layer_overlays::fill_sprite_array(), and key_city_overlay().
| void free_mapcanvas_and_overview | ( | ) |
Frees resources allocated for mapview and overview.
Definition at line 2320 of file view_map_common.cpp.
Referenced by fc_client::fc_main().
| struct tile* get_center_tile_mapcanvas | ( | ) |
Finds the current center tile of the mapcanvas.
Definition at line 699 of file view_map_common.cpp.
Referenced by find_a_focus_unit_tile_to_center_on(), find_best_focus_candidate(), units_view::find_nearest(), goto_dialog::init(), map_canvas_resized(), and tilespec_reread().
| 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.
It does not take draw_city_names/draw_city_growth into account.
Definition at line 1919 of file view_map_common.cpp.
Referenced by simple_citybar_painter::paint(), traditional_citybar_painter::paint(), and polished_citybar_painter::paint().
| void get_city_mapview_production | ( | const city * | pcity, |
| char * | buffer, | ||
| size_t | buffer_len | ||
| ) |
Find the mapview city production text for the given city, and place it into the buffer.
Definition at line 1792 of file view_map_common.cpp.
Referenced by simple_citybar_painter::paint(), and traditional_citybar_painter::paint().
| void get_city_mapview_trade_routes | ( | const city * | pcity, |
| char * | trade_routes_buffer, | ||
| size_t | trade_routes_buffer_len, | ||
| enum color_std * | pcolor | ||
| ) |
Find the mapview city trade routes text for the given city, and place it into the buffer.
Sets 'pcolor' to the preferred color the text should be drawn in if it is non-nullptr.
Definition at line 1818 of file view_map_common.cpp.
Referenced by simple_citybar_painter::paint(), traditional_citybar_painter::paint(), and polished_citybar_painter::paint().
| void get_mapview_scroll_pos | ( | int * | scroll_x, |
| int * | scroll_y | ||
| ) |
Find the current scroll position (origin) of the mapview.
Definition at line 690 of file view_map_common.cpp.
Referenced by tile_visible_and_not_on_border_mapcanvas().
| 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.
Imagine the entire map in scroll coordinates. It is a rectangle. Now imagine the mapview "window" sliding around through this rectangle. How far can it slide? In most cases it has to be able to slide past the ends of the map rectangle so that it's capable of reaching the whole area.
This function gives constraints on how far the window is allowed to slide. xmin and ymin are the minimum values for the window origin. xsize and ysize give the scroll dimensions of the mapview window. xmax and ymax give the maximum values that the bottom/left ends of the window may reach. The constraints, therefore, are that:
get_mapview_scroll_pos(&scroll_x, &scroll_y); xmin <= scroll_x < xmax - xsize ymin <= scroll_y < ymax - ysize
This function should be used anywhere and everywhere that scrolling is constrained.
Note that scroll coordinates, not map coordinates, are used. Currently these correspond to native coordinates.
Definition at line 608 of file view_map_common.cpp.
Referenced by calc_mapview_origin(), and tile_visible_and_not_on_border_mapcanvas().
| 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.
This corresponds to map_to_distance_vector but works for GUI coordinates.
Definition at line 408 of file view_map_common.cpp.
Referenced by base_set_mapview_origin(), and map_view::center_on_tile().
|
static |
Translate from gui to map coordinate systems.
See map_to_gui_pos().
Note that you lose some information in this conversion. If you convert from a gui position to a map position and back, you will probably not get the same value you started with.
Definition at line 189 of file view_map_common.cpp.
Referenced by base_canvas_to_map_pos(), gui_distance_vector(), and normalize_gui_pos().
| void init_mapcanvas_and_overview | ( | ) |
Sets up data for the mapview and overview.
Definition at line 2310 of file view_map_common.cpp.
Referenced by fc_client::fc_client().
| void link_mark_add_new | ( | enum text_link_type | type, |
| int | id | ||
| ) |
Add a visible link for 2 turns.
Definition at line 2522 of file view_map_common.cpp.
Referenced by handle_event().
|
static |
Returns the color of the pointed mark.
Definition at line 2406 of file view_map_common.cpp.
Referenced by link_mark_draw().
|
static |
Remove a link mark.
Definition at line 2379 of file view_map_common.cpp.
Referenced by link_marks_init().
|
static |
Print a link mark.
Definition at line 2424 of file view_map_common.cpp.
Referenced by link_marks_draw_all().
|
static |
Find a link mark in the list.
Definition at line 2348 of file view_map_common.cpp.
Referenced by link_mark_add_new(), and link_mark_restore().
|
static |
Create a new link mark.
Definition at line 2364 of file view_map_common.cpp.
Referenced by link_mark_add_new(), and link_mark_restore().
| void link_mark_restore | ( | enum text_link_type | type, |
| int | id | ||
| ) |
Add a visible link for 1 turn.
Definition at line 2544 of file view_map_common.cpp.
Referenced by chat_widget::anchor_clicked().
Returns the location of the pointed mark.
Definition at line 2384 of file view_map_common.cpp.
Referenced by link_mark_add_new(), link_mark_draw(), and link_mark_restore().
| void link_marks_clear_all | ( | ) |
Clear all visible links.
Definition at line 2497 of file view_map_common.cpp.
Referenced by chat_widget::rm_links().
| void link_marks_decrease_turn_counters | ( | ) |
Clear all visible links.
Definition at line 2506 of file view_map_common.cpp.
Referenced by handle_new_year().
| void link_marks_draw_all | ( | ) |
Draw all link marks.
Definition at line 2488 of file view_map_common.cpp.
Referenced by update_map_canvas().
| void link_marks_free | ( | ) |
Free the link marks.
Definition at line 2475 of file view_map_common.cpp.
Referenced by client_game_free(), client_game_reset(), and link_marks_init().
| void link_marks_init | ( | ) |
Initialize the link marks.
Definition at line 2463 of file view_map_common.cpp.
Referenced by client_game_init(), and client_game_reset().
| void map_canvas_resized | ( | int | width, |
| int | height | ||
| ) |
Called if the map in the GUI is resized.
Definition at line 2242 of file view_map_common.cpp.
Referenced by init_mapcanvas_and_overview(), mr_menu::save_image(), freeciv::renderer::set_scale(), and freeciv::renderer::set_viewport_size().
| 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.
GUI coordinates are comparable to canvas coordinates but extend in all directions. gui(0,0) == map(0,0).
Definition at line 174 of file view_map_common.cpp.
Referenced by map_view::center_on_tile(), get_mapview_scroll_window(), gui_distance_vector(), map_canvas_resized(), normalize_gui_pos(), tile_to_canvas_pos(), and trade_route_to_canvas_lines().
| 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.
This function works on vectors, meaning it can be passed a (dx,dy) pair and will return the change in GUI coordinates corresponding to this vector. It is thus more general than map_to_gui_pos.
Note that a gui_to_map_vector function is not possible, since the resulting map vector may differ based on the origin of the gui vector.
Definition at line 145 of file view_map_common.cpp.
Referenced by draw_calculated_trade_routes(), draw_segment(), generate_citydlg_dimensions(), map_to_gui_pos(), and move_unit_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'.
If there was no previously drawn line there, a mapview update is queued for the source and destination tiles.
Definition at line 2121 of file view_map_common.cpp.
Referenced by is_valid_goto_draw_line(), and mapdeco_set_gotoroute().
| void mapdeco_clear_crosshairs | ( | ) |
Clears all previous set tile crosshair decorations.
Marks the affected tiles as needing a mapview update.
Definition at line 2108 of file view_map_common.cpp.
Referenced by popdown_tile_info().
| void mapdeco_clear_gotoroutes | ( | ) |
Clear all goto line map decorations and queues mapview updates for the affected tiles.
Definition at line 2220 of file view_map_common.cpp.
Referenced by exit_goto_state(), is_valid_goto_draw_line(), and popdown_tile_info().
| void mapdeco_free | ( | ) |
Free all memory used for map decorations.
Definition at line 2050 of file view_map_common.cpp.
Referenced by mapdeco_clear_gotoroutes(), and mapdeco_init().
| void mapdeco_init | ( | ) |
Called when we receive map dimensions.
It initialized the mapview decorations.
Definition at line 2038 of file view_map_common.cpp.
Referenced by handle_map_info().
| bool mapdeco_is_crosshair_set | ( | const struct tile * | ptile | ) |
Returns TRUE if there is a "crosshair" decoration set at the given tile.
Definition at line 2096 of file view_map_common.cpp.
Referenced by freeciv::layer_overlays::fill_sprite_array().
| 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.
Definition at line 2199 of file view_map_common.cpp.
Referenced by update_map_canvas().
| bool mapdeco_is_highlight_set | ( | const struct tile * | ptile | ) |
Return TRUE if the given tile is highlighted.
Definition at line 2061 of file view_map_common.cpp.
Referenced by freeciv::layer_grid::fill_sprite_array(), and find_city_or_settler_near_tile().
| void mapdeco_set_crosshair | ( | const struct tile * | ptile, |
| bool | crosshair | ||
| ) |
Marks the given tile as having a "crosshair" map decoration.
Definition at line 2072 of file view_map_common.cpp.
Referenced by popup_tile_info().
| void mapdeco_set_gotoroute | ( | const struct unit * | punit | ) |
Set the map decorations for the given unit's goto route.
A goto route consists of one or more goto lines, with each line being from the center of one tile to the center of another tile.
Definition at line 2160 of file view_map_common.cpp.
Referenced by popup_tile_info().
Animates punit's "smooth" move from (x0, y0) to (x0+dx, y0+dy).
Note: Works only for adjacent-tile moves.
Definition at line 1573 of file view_map_common.cpp.
Referenced by do_move_unit().
|
static |
Normalize (wrap) the GUI position.
This is equivalent to a map wrapping, but in GUI coordinates so that pixel accuracy is preserved.
Definition at line 372 of file view_map_common.cpp.
Referenced by base_set_mapview_origin(), calc_mapview_origin(), and gui_distance_vector().
| void put_drawn_sprites | ( | QPixmap * | pcanvas, |
| const QPoint & | canvas_loc, | ||
| const std::vector< drawn_sprite > & | sprites, | ||
| bool | fog, | ||
| bool | city_unit | ||
| ) |
Draw an array of drawn sprites onto the canvas.
Definition at line 776 of file view_map_common.cpp.
Referenced by put_one_element(), and terrain_canvas().
| void put_nuke_mushroom_pixmaps | ( | struct tile * | ptile | ) |
Animate the nuke explosion at map(x, y).
Definition at line 952 of file view_map_common.cpp.
Referenced by handle_nuke_tile_info().
| void put_one_element | ( | QPixmap * | pcanvas, |
| const std::unique_ptr< freeciv::layer > & | layer, | ||
| const struct tile * | ptile, | ||
| const struct tile_edge * | pedge, | ||
| const struct tile_corner * | pcorner, | ||
| const struct unit * | punit, | ||
| const QPoint & | canvas_loc | ||
| ) |
Draw one layer of a tile, edge, corner, unit, and/or city onto the canvas at the given position.
Definition at line 815 of file view_map_common.cpp.
Referenced by put_one_tile(), put_terrain(), put_unit(), and update_map_canvas().
|
static |
Draw some or all of a tile onto the canvas.
Definition at line 985 of file view_map_common.cpp.
Referenced by update_map_canvas().
| 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.
The area of drawing is tileset_full_tile_height(tileset) x tileset_full_tile_width(tileset) (even though most tiles are not this tall).
Definition at line 858 of file view_map_common.cpp.
Referenced by hud_units::update_actions().
| 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.
The area of drawing is tileset_unit_height(tileset) x tileset_unit_width(tileset).
Definition at line 842 of file view_map_common.cpp.
Referenced by units_select::create_pixmap(), unit_list_widget::create_unit_image(), hud_unit_combat::init_images(), move_unit_map_canvas(), choice_dialog::next_unit(), choice_dialog::prev_unit(), freeciv::upkeep_widget::refresh(), choice_dialog::set_layout(), and hud_units::update_actions().
| 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.
The proper way to do this is probably something like what Civ II does (one sprite drawn N times on top of itself), but we just use separate sprites (limiting the number of combinations).
Definition at line 876 of file view_map_common.cpp.
Referenced by unit_list_widget::create_unit_image(), and freeciv::upkeep_widget::refresh().
| Q_GLOBAL_STATIC | ( | QElapsedTimer | , |
| anim_timer | |||
| ) |
Refreshes a single city on the map canvas.
If full_refresh is given then the citymap area and the city text will also be refreshed. Otherwise only the base city sprite is refreshed.
Definition at line 128 of file view_map_common.cpp.
Referenced by city_packet_common(), client_remove_city(), handle_unit_packet_common(), city_dialog::setup_ui(), and toggle_city_color().
| void refresh_tile_mapcanvas | ( | const tile * | ptile, |
| bool | full_refresh | ||
| ) |
Refreshes a single tile on the map canvas.
Definition at line 104 of file view_map_common.cpp.
Referenced by editor_end_selection_rectangle(), handle_edit_startpos(), handle_edit_startpos_full(), handle_tile_info(), handle_unit_bombard_info(), link_mark_add_new(), link_mark_restore(), mapdeco_add_gotoline(), mapdeco_clear_crosshairs(), mapdeco_clear_gotoroutes(), and mapdeco_set_crosshair().
Refreshes a single unit on the map canvas.
Definition at line 114 of file view_map_common.cpp.
Referenced by blink_active_unit(), client_remove_unit(), current_focus_append(), decrease_unit_hp_smooth(), do_move_unit(), handle_unit_combat_info(), handle_unit_packet_common(), toggle_unit_color(), and unit_focus_set().
| void set_mapview_origin | ( | float | gui_x0, |
| float | gui_y0 | ||
| ) |
Change the mapview origin, clip it, and update everything.
Definition at line 573 of file view_map_common.cpp.
Referenced by freeciv::renderer::set_origin().
| 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.
Definition at line 1335 of file view_map_common.cpp.
Referenced by update_map_canvas().
|
static |
Draw a label for the given tile.
(canvas_x, canvas_y) gives the location on the given canvas at which to draw the label. This is the location of the tile itself so the text must be drawn underneath it. pcity gives the city to be drawn, while (*width, *height) should be set by show_tile_label to contain the width and height of the text block (centered directly underneath the city's tile).
Definition at line 1309 of file view_map_common.cpp.
Referenced by show_tile_labels().
| 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.
Definition at line 1398 of file view_map_common.cpp.
Referenced by update_map_canvas().
| bool tile_to_canvas_pos | ( | float * | canvas_x, |
| float * | canvas_y, | ||
| const tile * | ptile | ||
| ) |
Finds the canvas coordinates for a map position.
Beside setting the results in canvas_x, canvas_y it returns whether the tile is inside the visible mapview canvas.
The result represents the upper left pixel (origin) of the bounding box of the tile. Note that in iso-view this origin is not a part of the tile itself - so to make the operation reversible you would have to call canvas_to_map_pos on the center of the tile, not the origin.
The center of a tile is defined as: { tile_to_canvas_pos(&canvas_x, &canvas_y, ptile); canvas_x += tileset_tile_width(tileset) / 2; canvas_y += tileset_tile_height(tileset) / 2; }
This pixel is one position closer to the lower right, which may be important to remember when doing some round-off operations. Other parts of the code assume tileset_tile_width(tileset) and tileset_tile_height(tileset) to be even numbers.
Definition at line 289 of file view_map_common.cpp.
Referenced by animate_unit_explosion(), info_tile::calc_size(), draw_calculated_trade_routes(), draw_segment(), link_mark_draw(), move_unit_map_canvas(), put_cross_overlay_tile(), put_nuke_mushroom_pixmaps(), tile_visible_and_not_on_border_mapcanvas(), tile_visible_mapcanvas(), trade_route_to_canvas_lines(), and freeciv::renderer::unqueue_updates().
| 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.
This information is used to determine when we need to recenter the map canvas.
The logic of this function is simple: if a tile is within 1.5 tiles of a border of the canvas and that border is not aligned with the edge of the map, then the tile is on the "border" of the map canvas.
This function is only correct for the current topology.
Definition at line 726 of file view_map_common.cpp.
Referenced by auto_center_on_focus_unit(), do_move_unit(), and unit_focus_advance().
| bool tile_visible_mapcanvas | ( | struct tile * | ptile | ) |
Return TRUE iff the given map position has a tile visible on the map canvas.
Definition at line 708 of file view_map_common.cpp.
Referenced by handle_unit_bombard_info(), handle_unit_combat_info(), link_mark_add_new(), link_mark_restore(), and move_unit_map_canvas().
| enum topo_comp_lvl tileset_map_topo_compatible | ( | int | topology_id, |
| struct tileset * | tset | ||
| ) |
Are the topology and tileset compatible?
Definition at line 2544 of file view_map_common.cpp.
Referenced by handle_map_info(), handle_set_topology(), and tilespec_reread().
| void toggle_city_color | ( | struct city * | pcity | ) |
Toggle the city color.
This cycles through the possible colors for the citymap as shown on the mapview. These colors are listed in the city_colors array; above.
Definition at line 918 of file view_map_common.cpp.
Referenced by key_city_overlay().
| void toggle_unit_color | ( | struct unit * | punit | ) |
Toggle the unit color.
This cycles through the possible colors for the citymap as shown on the mapview. These colors are listed in the city_colors array; above.
Definition at line 936 of file view_map_common.cpp.
Referenced by key_city_overlay().
|
static |
Depending on where ptile1 and ptile2 are on the map canvas, a trade route line may need to be drawn as two disjointed line segments.
This function fills the given line array 'lines' with the necessary line segments.
The return value is the number of line segments that need to be drawn.
NB: It is assumed ptile1 and ptile2 are already consistently ordered. NB: 'lines' must be able to hold least MAX_TRADE_ROUTE_DRAW_LINES elements.
Definition at line 1009 of file view_map_common.cpp.
Referenced by draw_trade_route_line().
| void unqueue_mapview_updates | ( | ) |
See comment in update_map_canvas_visible().
Definition at line 1907 of file view_map_common.cpp.
Referenced by animate_unit_explosion(), decrease_unit_hp_smooth(), map_canvas_resized(), move_unit_map_canvas(), and put_nuke_mushroom_pixmaps().
| void update_city_description | ( | struct city * | pcity | ) |
Update the city description for the given city.
Definition at line 1284 of file view_map_common.cpp.
Referenced by do_move_unit(), handle_city_info(), handle_city_short_info(), handle_traderoute_info(), handle_unit_packet_common(), and show_city_descriptions().
| 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 dimensions (also in map coordinates).
In non-iso view, this is easy. In iso view, we have to use the Painter's Algorithm to draw the tiles in back first. When we draw a tile, we tell the GUI which part of the tile to draw - which is necessary unless we have an extra buffering step.
After refreshing the backing store tile-by-tile, we write the store out to the display if write_to_screen is specified.
x, y, width, and height are in map coordinates; they need not be normalized or even real.
Definition at line 1129 of file view_map_common.cpp.
Referenced by base_set_mapview_origin(), editor_end_selection_rectangle(), and freeciv::renderer::unqueue_updates().
| void update_map_canvas_visible | ( | ) |
Schedules an update of (only) the visible part of the map at the next unqueue_mapview_update().
Definition at line 1243 of file view_map_common.cpp.
Referenced by client_state(), editor_start_selection_rectangle(), gui_qt_apply_font(), handle_city_info(), handle_new_year(), handle_player_info(), handle_start_phase(), handle_traderoute_info(), city_dialog::hideEvent(), link_marks_clear_all(), map_canvas_resized(), citybar_painter::option_changed(), put_nuke_mushroom_pixmaps(), request_toggle_city_buycost(), request_toggle_city_growth(), request_toggle_city_names(), request_toggle_city_outlines(), request_toggle_city_output(), request_toggle_city_productions(), request_toggle_city_trade_routes(), request_toggle_map_borders(), request_toggle_map_grid(), request_toggle_map_native(), mr_menu::setup_menus(), city_dialog::showEvent(), tilespec_reread(), view_option_changed_callback(), and mr_menu::zoom_scale_fonts().
| std::map<freeciv::map_updates_handler::update_type, QRectF> update_rects | ( | ) |
Calculates the area covered by each update type.
The area array gives the offset from the tile origin as well as the width and height of the area to be updated. This is initialized each time when entering the function from the existing tileset variables.
A TILE update covers the base tile (width x height) plus a half-tile in each direction (for edge/corner graphics), making its area 2 width x 2 height.
A UNIT update covers a unit_width x unit_height area. This is centered horizontally over the tile but extends up above the tile (e.g., units in iso-view).
A CITYMAP update covers the whole citymap of a tile. This includes the citymap area itself plus an extra half-tile in each direction (for edge/corner graphics).
Definition at line 1875 of file view_map_common.cpp.
Referenced by freeciv::renderer::unqueue_updates().
| void update_tile_label | ( | const tile * | ptile | ) |
Update the label for the given tile.
Definition at line 1293 of file view_map_common.cpp.
Referenced by show_tile_labels().
|
static |
Definition at line 911 of file view_map_common.cpp.
Referenced by toggle_city_color(), and toggle_unit_color().
|
static |
Definition at line 2343 of file view_map_common.cpp.
Referenced by link_mark_add_new(), link_mark_restore(), link_marks_clear_all(), link_marks_decrease_turn_counters(), link_marks_free(), and link_marks_init().
| struct view mapview |
Definition at line 75 of file view_map_common.cpp.
Referenced by animate_unit_explosion(), base_canvas_to_map_pos(), base_set_mapview_origin(), calc_mapview_origin(), can_do_cached_drawing(), map_view::center_on_tile(), create_line_at_mouse_pos(), draw_segment(), draw_trade_route_line(), minimap_view::draw_viewport(), editor_end_selection_rectangle(), fc_game_tab_widget::event(), fc_client::eventFilter(), free_mapcanvas_and_overview(), get_center_tile_mapcanvas(), get_mapview_scroll_pos(), get_mapview_scroll_window(), fc_shortcuts::invoke(), link_mark_draw(), map_canvas_resized(), mapdeco_init(), fc_shortcuts::maybe_route_mouse_shortcut(), move_unit_map_canvas(), hud_battle_log::moveEvent(), put_nuke_mushroom_pixmaps(), redraw_overview(), freeciv::renderer::render(), minimap_view::resizeEvent(), show_city_descriptions(), show_tile_labels(), tile_to_canvas_pos(), tile_visible_and_not_on_border_mapcanvas(), freeciv::renderer::unqueue_updates(), and update_map_canvas().
|
static |
Definition at line 1276 of file view_map_common.cpp.
Referenced by show_city_descriptions(), and update_rects().
|
static |
Definition at line 1276 of file view_map_common.cpp.
Referenced by show_city_descriptions(), and update_rects().
|
static |
Definition at line 1279 of file view_map_common.cpp.
Referenced by show_tile_labels(), and update_rects().
|
static |
Definition at line 88 of file view_map_common.cpp.
Referenced by draw_trade_route_line().