The Battle for Wesnoth  1.17.0-dev
drawer.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  *
18  * This wrapper class should be held by the display object when it needs to draw a unit.
19  * The purpose of this is to improve encapsulation -- other parts of the engine like AI
20  * don't need to be exposed to the unit drawing code, and encapsulation like this will
21  * help us to reduce unnecessary includes.
22  *
23  **/
24 
25 #pragma once
26 
27 #include "map/location.hpp"
28 #include "utils/math.hpp"
29 
30 #include <map>
31 #include <vector>
32 
33 class display;
34 class display_context;
35 class gamemap;
36 namespace halo { class manager; }
37 class team;
38 class unit;
39 
40 struct color_t;
41 struct SDL_Rect;
42 class surface;
43 
45 {
46 public:
47  explicit unit_drawer(display & thedisp);
48 
49 private:
52  const gamemap & map;
53  const std::vector<team> & teams;
55  std::size_t viewing_team;
56  std::size_t playing_team;
63  double zoom_factor;
64  std::set<map_location> units_that_can_reach_goal;
65 
66  int hex_size;
68 
69 public:
70  /** draw a unit. */
71  void redraw_unit(const unit & u) const;
72 
73 private:
74  /** draw a health/xp bar of a unit */
75  void draw_bar(const std::string& image, int xpos, int ypos,
76  const map_location& loc, std::size_t height, double filled,
77  const color_t& col, fixed_t alpha) const;
78 
79  /**
80  * Finds the start and end rows on the energy bar image.
81  *
82  * White pixels are substituted for the color of the energy.
83  */
84  const SDL_Rect& calculate_energy_bar(surface surf) const;
85 };
bool is_blindfolded
Definition: drawer.hpp:59
This class represents a single unit of a specific type.
Definition: unit.hpp:121
int hex_size
Definition: drawer.hpp:66
halo::manager & halo_man
Definition: drawer.hpp:54
const team & playing_team_ref
Definition: drawer.hpp:58
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
int hex_size_by_2
Definition: drawer.hpp:67
Encapsulates the map of the game.
Definition: map.hpp:171
General math utility functions.
const gamemap & map
Definition: drawer.hpp:52
const std::vector< team > & teams
Definition: drawer.hpp:53
display & disp
Definition: drawer.hpp:50
int32_t fixed_t
Definition: math.hpp:313
std::set< map_location > units_that_can_reach_goal
Definition: drawer.hpp:64
Encapsulates the map of the game.
Definition: location.hpp:38
const team & viewing_team_ref
Definition: drawer.hpp:57
const display_context & dc
Definition: drawer.hpp:51
std::size_t viewing_team
Definition: drawer.hpp:55
Definition: display.hpp:45
Functions to load and save images from/to disk.
std::size_t playing_team
Definition: drawer.hpp:56
double zoom_factor
Definition: drawer.hpp:63
bool show_everything
Definition: drawer.hpp:60
map_location mouse_hex
Definition: drawer.hpp:62
map_location sel_hex
Definition: drawer.hpp:61