Freeciv21
Develop your civilization from humble roots to a global empire
layer.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 2021-2023 Freeciv21 contributors.
3 \_ \ / __/ This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include "layer.h"
15 
16 #include "control.h"
17 #include "options.h"
18 #include "tilespec.h"
19 
20 namespace freeciv {
21 
27 bool layer::do_draw_unit(const tile *ptile, const unit *punit) const
28 {
29  if (!punit) {
30  // Can't draw a non-existing unit.
31  return false;
32  }
33 
34  // There is a unit.
35 
36  if (!ptile) {
37  // No tile (so not on the map) => always draw.
38  return true;
39  }
40 
41  // Handle options to turn off drawing units.
42  if (gui_options->draw_units) {
43  return true;
44  } else if (gui_options->draw_focus_unit && unit_is_in_focus(punit)) {
45  return true;
46  } else {
47  return false;
48  }
49 }
50 
65 bool layer::solid_background(const tile *ptile, const unit *punit,
66  const city *pcity) const
67 {
69  // Solid background turned off (the default).
70  return false;
71  }
72 
73  return do_draw_unit(ptile, punit) || (gui_options->draw_cities && pcity);
74 }
75 
79 QPixmap *layer::load_sprite(const QStringList &possible_names, bool required,
80  bool verbose) const
81 {
82  return ::load_sprite(tileset(), possible_names, required, verbose);
83 }
84 
85 } // namespace freeciv
QPixmap * load_sprite(const QStringList &possible_names, bool required=false, bool verbose=true) const
Shortcut to load a sprite from the tileset.
Definition: layer.cpp:79
bool do_draw_unit(const tile *ptile, const unit *punit) const
Whether a unit should be drawn.
Definition: layer.cpp:27
bool solid_background(const tile *ptile, const unit *punit, const city *pcity) const
Whether a solid background should be drawn on a tile instead of its terrain.
Definition: layer.cpp:65
struct tileset * tileset() const
Definition: layer.h:241
bool unit_is_in_focus(const struct unit *punit)
Return TRUE iff this unit is in focus.
Definition: control.cpp:364
Definition: path.cpp:10
client_options * gui_options
Definition: options.cpp:74
Definition: city.h:291
bool draw_units
Definition: options.h:137
bool draw_cities
Definition: options.h:136
bool draw_focus_unit
Definition: options.h:138
bool solid_color_behind_units
Local Options:
Definition: options.h:79
Definition: tile.h:42
Definition: unit.h:134
static QPixmap * load_sprite(struct tileset *t, const QString &tag_name)
Loads the sprite.
Definition: tilespec.cpp:2270