Freeciv21
Develop your civilization from humble roots to a global empire
layer_editor.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 // SPDX-FileCopyrightText: Freeciv authors
3 // SPDX-FileCopyrightText: Freeciv21 authors
4 // SPDX-FileCopyrightText: Louis Moureaux <m_louis30@yahoo.com>
5 
6 #include "layer_editor.h"
7 
8 #include "editor.h"
9 #include "map.h"
10 #include "sprite_g.h"
11 #include "tilespec.h"
12 
13 #include <memory>
14 
15 namespace freeciv {
16 
18  : freeciv::layer(ts, LAYER_EDITOR)
19 {
20 }
21 
23 {
24  // FIXME: Use better sprites.
25  auto color = load_sprite({"colors.overlay_0"}, true);
26  auto unworked = load_sprite({"mask.unworked_tile"}, true);
27 
29  auto mask = std::unique_ptr<QPixmap>(
30  crop_sprite(color, 0, 0, W, H, get_mask_sprite(tileset()), 0, 0));
31  auto selected = std::unique_ptr<QPixmap>(
32  crop_sprite(mask.get(), 0, 0, W, H, unworked, 0, 0));
33  m_selected = *selected;
34 
35  // FIXME: Use a more representative sprite.
36  m_starting_position = load_sprite({"user.attention"}, true);
37 }
38 
39 std::vector<drawn_sprite>
40 layer_editor::fill_sprite_array(const tile *ptile, const tile_edge *pedge,
41  const tile_corner *pcorner,
42  const unit *punit) const
43 {
44  if (!ptile && !editor_is_active()) {
45  return {};
46  }
47 
48  std::vector<drawn_sprite> sprs;
49 
50  if (editor_tile_is_selected(ptile)) {
51  sprs.emplace_back(tileset(), &m_selected);
52  }
53 
54  if (nullptr != map_startpos_get(ptile)) {
55  sprs.emplace_back(tileset(), m_starting_position);
56  }
57 
58  return sprs;
59 }
60 
61 } // namespace freeciv
QPixmap crop_sprite(const QPixmap *sprite)
Helper function to crop a sprite.
Definition: canvas.cpp:115
std::vector< drawn_sprite > fill_sprite_array(const tile *ptile, const tile_edge *pedge, const tile_corner *pcorner, const unit *punit) const override
Returns the list of sprites drawn by this layer somewhere on the map.
layer_editor(struct tileset *ts)
void load_sprites() override
Loads all sprites that do not depend on the ruleset.
QPixmap * m_starting_position
Definition: layer_editor.h:27
A layer when drawing the map.
Definition: layer.h:153
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
struct tileset * tileset() const
Definition: layer.h:241
bool editor_tile_is_selected(const struct tile *ptile)
Returns TRUE if the given tile is selected.
Definition: editor.cpp:1109
bool editor_is_active()
Returns TRUE if the client is in edit mode.
Definition: editor.cpp:335
struct startpos * map_startpos_get(const struct tile *ptile)
Returns the start position at the given tile, or nullptr if none exists there.
Definition: map.cpp:1548
Definition: path.cpp:10
Definition: tile.h:42
Definition: unit.h:134
const QPixmap * get_mask_sprite(const struct tileset *t)
Return tile mask sprite.
Definition: tilespec.cpp:3486
int tileset_tile_height(const struct tileset *t)
Return the tile height of the current tileset.
Definition: tilespec.cpp:383
int tileset_tile_width(const struct tileset *t)
Return the tile width of the current tileset.
Definition: tilespec.cpp:371