Freeciv21
Develop your civilization from humble roots to a global empire
view_map_common.cpp File Reference
#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 tilecanvas_pos_to_tile (float canvas_x, float canvas_y)
 Finds the tile corresponding to pixel coordinates. More...
 
struct tilecanvas_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 tileget_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 cityfind_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_marklink_mark_find (enum text_link_type type, int id)
 Find a link mark in the list. More...
 
static struct link_marklink_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 tilelink_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
 

Macro Definition Documentation

◆ COLOR_MAPVIEW_TILELABEL

#define COLOR_MAPVIEW_TILELABEL   COLOR_MAPVIEW_CITYTEXT

◆ link_marks_iterate

#define link_marks_iterate (   pmark)     TYPED_LIST_ITERATE(struct link_mark, link_marks, pmark)

Definition at line 2339 of file view_map_common.cpp.

◆ link_marks_iterate_end

#define link_marks_iterate_end   LIST_ITERATE_END

Definition at line 2341 of file view_map_common.cpp.

◆ SPECLIST_TAG

#define SPECLIST_TAG   link_mark

Definition at line 2336 of file view_map_common.cpp.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct link_mark

Definition at line 2337 of file view_map_common.cpp.

Typedef Documentation

◆ gotohash

typedef QHash<const struct tile *, struct gotoline_counter *> gotohash

Definition at line 75 of file view_map_common.cpp.

Function Documentation

◆ anim_delay()

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().

◆ animate_unit_explosion()

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().

◆ append_city_buycost_string()

static void append_city_buycost_string ( const struct city pcity,
char *  buffer,
int  buffer_len 
)
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().

◆ base_canvas_to_map_pos()

static void base_canvas_to_map_pos ( int *  map_x,
int *  map_y,
float  canvas_x,
float  canvas_y 
)
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().

◆ base_set_mapview_origin()

static void base_set_mapview_origin ( float  gui_x0,
float  gui_y0 
)
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().

◆ calc_mapview_origin()

static bool calc_mapview_origin ( float *  gui_x0,
float *  gui_y0 
)
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().

◆ can_do_cached_drawing()

static bool can_do_cached_drawing ( )
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().

◆ canvas_pos_to_nearest_tile()

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().

◆ canvas_pos_to_tile()

struct tile* canvas_pos_to_tile ( float  canvas_x,
float  canvas_y 
)

◆ decrease_unit_hp_smooth()

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.

Definition at line 1477 of file view_map_common.cpp.

Referenced by handle_unit_combat_info().

◆ draw_segment()

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().

◆ draw_trade_route_line()

static void draw_trade_route_line ( const struct tile ptile1,
const struct tile ptile2,
enum color_std  color 
)
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().

◆ draw_trade_routes()

static void draw_trade_routes ( )
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().

◆ draw_trade_routes_for_city()

static void draw_trade_routes_for_city ( const struct city pcity_src)
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_city_or_settler_near_tile()

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.

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().

◆ free_mapcanvas_and_overview()

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().

◆ get_center_tile_mapcanvas()

struct tile* get_center_tile_mapcanvas ( )

◆ get_city_mapview_name_and_growth()

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().

◆ get_city_mapview_production()

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().

◆ get_city_mapview_trade_routes()

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().

◆ get_mapview_scroll_pos()

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().

◆ get_mapview_scroll_window()

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().

◆ gui_distance_vector()

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().

◆ gui_to_map_pos()

static void gui_to_map_pos ( const struct tileset t,
int *  map_x,
int *  map_y,
float  gui_x,
float  gui_y 
)
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().

◆ init_mapcanvas_and_overview()

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().

◆ link_mark_add_new()

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().

◆ link_mark_color()

static QColor link_mark_color ( const struct link_mark pmark)
static

Returns the color of the pointed mark.

Definition at line 2406 of file view_map_common.cpp.

Referenced by link_mark_draw().

◆ link_mark_destroy()

static void link_mark_destroy ( struct link_mark pmark)
static

Remove a link mark.

Definition at line 2379 of file view_map_common.cpp.

Referenced by link_marks_init().

◆ link_mark_draw()

static void link_mark_draw ( const struct link_mark pmark)
static

Print a link mark.

Definition at line 2424 of file view_map_common.cpp.

Referenced by link_marks_draw_all().

◆ link_mark_find()

static struct link_mark* link_mark_find ( enum text_link_type  type,
int  id 
)
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().

◆ link_mark_new()

static struct link_mark* link_mark_new ( enum text_link_type  type,
int  id,
int  turns 
)
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().

◆ 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().

◆ link_mark_tile()

static struct tile* link_mark_tile ( const struct link_mark pmark)
static

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().

◆ link_marks_clear_all()

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().

◆ link_marks_decrease_turn_counters()

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().

◆ link_marks_draw_all()

void link_marks_draw_all ( )

Draw all link marks.

Definition at line 2488 of file view_map_common.cpp.

Referenced by update_map_canvas().

◆ link_marks_free()

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().

◆ 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().

◆ map_canvas_resized()

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().

◆ map_to_gui_pos()

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().

◆ map_to_gui_vector()

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().

◆ mapdeco_add_gotoline()

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().

◆ mapdeco_clear_crosshairs()

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().

◆ mapdeco_clear_gotoroutes()

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().

◆ mapdeco_free()

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().

◆ 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().

◆ mapdeco_is_crosshair_set()

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().

◆ mapdeco_is_gotoline_set()

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().

◆ mapdeco_is_highlight_set()

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().

◆ mapdeco_set_crosshair()

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().

◆ mapdeco_set_gotoroute()

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().

◆ move_unit_map_canvas()

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).

Note: Works only for adjacent-tile moves.

Definition at line 1573 of file view_map_common.cpp.

Referenced by do_move_unit().

◆ normalize_gui_pos()

static void normalize_gui_pos ( const struct tileset t,
float *  gui_x,
float *  gui_y 
)
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().

◆ put_drawn_sprites()

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().

◆ put_nuke_mushroom_pixmaps()

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().

◆ put_one_element()

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().

◆ put_one_tile()

static void put_one_tile ( QPixmap *  pcanvas,
const std::unique_ptr< freeciv::layer > &  layer,
const tile ptile,
const QPoint &  canvas_loc 
)
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().

◆ put_terrain()

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().

◆ put_unit()

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().

◆ put_unit_city_overlays()

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()

Q_GLOBAL_STATIC ( QElapsedTimer  ,
anim_timer   
)

◆ refresh_city_mapcanvas()

void refresh_city_mapcanvas ( struct city pcity,
struct tile ptile,
bool  full_refresh 
)

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().

◆ refresh_tile_mapcanvas()

◆ refresh_unit_mapcanvas()

void refresh_unit_mapcanvas ( struct unit punit,
struct tile ptile,
bool  full_refresh 
)

◆ set_mapview_origin()

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().

◆ show_city_descriptions()

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().

◆ show_tile_label()

static QSize show_tile_label ( QPixmap *  pcanvas,
int  canvas_x,
int  canvas_y,
const tile ptile 
)
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().

◆ 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().

◆ tile_to_canvas_pos()

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().

◆ tile_visible_and_not_on_border_mapcanvas()

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().

◆ tile_visible_mapcanvas()

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().

◆ tileset_map_topo_compatible()

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().

◆ toggle_city_color()

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().

◆ toggle_unit_color()

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().

◆ trade_route_to_canvas_lines()

static int trade_route_to_canvas_lines ( const struct tile ptile1,
const struct tile ptile2,
struct trade_route_line lines 
)
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().

◆ unqueue_mapview_updates()

◆ update_city_description()

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().

◆ update_map_canvas()

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().

◆ update_map_canvas_visible()

◆ update_rects()

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().

◆ update_tile_label()

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().

Variable Documentation

◆ color_index

int color_index = 0
static

Definition at line 911 of file view_map_common.cpp.

Referenced by toggle_city_color(), and toggle_unit_color().

◆ link_marks

struct link_mark_list* link_marks = nullptr
static

◆ mapview

◆ max_desc_height

int max_desc_height = 0
static

Definition at line 1276 of file view_map_common.cpp.

Referenced by show_city_descriptions(), and update_rects().

◆ max_desc_width

int max_desc_width = 0
static

Definition at line 1276 of file view_map_common.cpp.

Referenced by show_city_descriptions(), and update_rects().

◆ max_label_size

QSize max_label_size = QSize()
static

Definition at line 1279 of file view_map_common.cpp.

Referenced by show_tile_labels(), and update_rects().

◆ MAX_TRADE_ROUTE_DRAW_LINES

const int MAX_TRADE_ROUTE_DRAW_LINES = 2
static

Definition at line 88 of file view_map_common.cpp.

Referenced by draw_trade_route_line().