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