The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
label.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef MAP_LABEL_HPP_INCLUDED
16 #define MAP_LABEL_HPP_INCLUDED
17 
18 #include "map/location.hpp"
19 #include "font.hpp"
20 #include "tstring.hpp"
21 
22 class config;
23 class display;
24 class display_context;
25 class team;
26 class terrain_label;
27 
28 
30 {
31 public:
32  typedef std::map<map_location, terrain_label *> label_map;
33  typedef std::map<std::string,label_map> team_label_map;
34 
35  map_labels(const map_labels&);
36  map_labels(const display& disp, const team*);
37  ~map_labels();
38 
40 
41  void write(config& res) const;
42  void read(const config &cfg);
43 
44  const terrain_label* get_label(const map_location& loc, const std::string& team_name) const;
45  // search a team-only label, if fails then try public labels
46  const terrain_label* get_label(const map_location& loc) const;
47  const terrain_label* set_label(const map_location& loc,
48  const t_string& text,
49  const int creator = -1,
50  const std::string& team = "",
51  const SDL_Color color = font::NORMAL_COLOR,
52  const bool visible_in_fog = true,
53  const bool visible_in_shroud = false,
54  const bool immutable = false,
55  const std::string& category = "",
56  const t_string& tooltip = "" );
57 
58  bool enabled() const { return enabled_; }
59  void enable(bool is_enabled);
60 
61 
62  void clear(const std::string&, bool force);
63 
64  void recalculate_labels();
65  void recalculate_shroud();
66 
67  bool visible_global_label(const map_location&) const;
68 
69 
70  const display& disp() const;
71 
72  const std::string& team_name() const;
73  const std::vector<std::string>& all_categories() const;
74 
75  void set_team(const team*);
76 
77  void clear_all();
78 
79 private:
80 
81  void add_label(const map_location &, terrain_label *);
82 
83  void clear_map(label_map &, bool);
84  /// For our private use, a wrapper for get_label() that can return a pointer
85  /// to a non-const terrain_label.
87  { return const_cast<terrain_label*>(get_label(loc, team_name)); }
88  // Note: this is not an overload of get_label() so that we do not block
89  // outsiders from calling get_label for a non-const map_labels object.
90 
91  const display& disp_;
92  const team* team_;
93 
94  team_label_map labels_;
95  bool enabled_;
96 
97  mutable std::vector<std::string> categories;
98  mutable bool categories_dirty;
99 };
100 
101 /// To store label data
102 /// Class implements logic for rendering
104 {
105 public:
106  terrain_label(const t_string& text,
107  const int creator,
108  const std::string& team_name,
109  const map_location& loc,
110  const map_labels& parent,
111  const SDL_Color color = font::NORMAL_COLOR,
112  const bool visible_in_fog = true,
113  const bool visible_in_shroud = false,
114  const bool immutable = false,
115  const std::string& category = "",
116  const t_string& tooltip = "" );
117 
118  terrain_label(const map_labels &, const config &);
119 
120  ~terrain_label();
121 
122  void write(config& res) const;
123  void read(const config &cfg);
124 
125  const t_string& text() const;
126  const t_string& tooltip() const;
127  int creator() const;
128  const std::string& team_name() const;
129  const std::string& category() const;
130  bool visible_in_fog() const;
131  bool visible_in_shroud() const;
132  bool immutable() const;
133  const map_location& location() const;
134  const SDL_Color& color() const;
135 
136  void set_text(const t_string&);
137 
138  void update_info(const t_string&,
139  const int creator,
140  const t_string&,
141  const std::string&,
142  const SDL_Color);
143 
144  void update_info(const t_string& text,
145  const int creator,
146  const t_string& tooltip,
147  const std::string& team_name,
148  const SDL_Color color,
149  const bool visible_in_fog,
150  const bool visible_in_shroud,
151  const bool immutable,
152  const std::string& category);
153 
154  void recalculate();
155  void calculate_shroud();
156 
157 private:
159  const terrain_label& operator=(const terrain_label&);
160  void clear();
161  void draw();
162  bool hidden() const;
163  bool viewable(const display_context & dc) const;
164  std::string cfg_color() const;
165 
166  int handle_;
168 
176  int creator_;
177 
178  SDL_Color color_;
179 
182 
183  SDL_Rect get_rect() const;
184 };
185 
186 #endif
const map_labels * parent_
Definition: label.hpp:180
void recalculate_shroud()
Definition: label.cpp:285
std::map< map_location, terrain_label * > label_map
Definition: label.hpp:32
std::string cfg_color() const
Definition: label.cpp:469
int creator_
Definition: label.hpp:176
map_labels & operator=(const map_labels &)
Definition: label.cpp:61
const std::vector< std::string > & all_categories() const
Definition: label.cpp:296
void write(config &res) const
Definition: label.cpp:70
bool enabled() const
Definition: label.hpp:58
t_string tooltip_
Definition: label.hpp:170
bool visible_in_fog_
Definition: label.hpp:173
const map_location & location() const
Definition: label.cpp:459
bool hidden() const
This is a lightweight test used to see if labels are revealed as a result of unit actions (i...
Definition: label.cpp:594
team_label_map labels_
Definition: label.hpp:94
const SDL_Color NORMAL_COLOR
Definition: font.cpp:564
const terrain_label & operator=(const terrain_label &)
void update_info(const t_string &, const int creator, const t_string &, const std::string &, const SDL_Color)
Definition: label.cpp:485
int creator() const
Definition: label.cpp:429
const terrain_label * set_label(const map_location &loc, const t_string &text, const int creator=-1, const std::string &team="", const SDL_Color color=font::NORMAL_COLOR, const bool visible_in_fog=true, const bool visible_in_shroud=false, const bool immutable=false, const std::string &category="", const t_string &tooltip="")
Definition: label.cpp:145
bool immutable() const
Definition: label.cpp:454
const std::string & team_name() const
Definition: label.cpp:439
bool visible_in_shroud_
Definition: label.hpp:174
const SDL_Color & color() const
Definition: label.cpp:464
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
const t_string & text() const
Definition: label.cpp:419
std::vector< std::string > categories
Definition: label.hpp:97
const std::string & category() const
Definition: label.cpp:434
bool viewable(const display_context &dc) const
This is a test used to see if we should bother with the overhead of actually creating a label...
Definition: label.cpp:624
void clear(const std::string &, bool force)
Definition: label.cpp:217
map_labels(const map_labels &)
Definition: label.cpp:48
const team * team_
Definition: label.hpp:92
void clear()
Definition: label.cpp:644
terrain_label(const t_string &text, const int creator, const std::string &team_name, const map_location &loc, const map_labels &parent, const SDL_Color color=font::NORMAL_COLOR, const bool visible_in_fog=true, const bool visible_in_shroud=false, const bool immutable=false, const std::string &category="", const t_string &tooltip="")
creating new label
Definition: label.cpp:318
std::string category_
Definition: label.hpp:171
void enable(bool is_enabled)
Definition: label.cpp:266
terrain_label * get_label_private(const map_location &loc, const std::string &team_name)
For our private use, a wrapper for get_label() that can return a pointer to a non-const terrain_label...
Definition: label.hpp:86
const std::string & team_name() const
Definition: label.cpp:125
bool immutable_
Definition: label.hpp:175
bool enabled_
Definition: label.hpp:95
int tooltip_handle_
Definition: label.hpp:167
const display & disp() const
Definition: label.cpp:120
SDL_Color color_
Definition: label.hpp:178
GLuint color
Definition: glew.h:5801
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
Definition: label.cpp:97
Encapsulates the map of the game.
Definition: location.hpp:38
void set_team(const team *)
Definition: label.cpp:135
~map_labels()
Definition: label.cpp:56
void add_label(const map_location &, terrain_label *)
Definition: label.cpp:211
void recalculate_labels()
Definition: label.cpp:255
GLuint res
Definition: glew.h:9258
void read(const config &cfg)
Definition: label.cpp:368
bool visible_in_shroud() const
Definition: label.cpp:449
void clear_map(label_map &, bool)
Definition: label.cpp:233
bool visible_in_fog() const
Definition: label.cpp:444
void write(config &res) const
Definition: label.cpp:405
const display & disp_
Definition: label.hpp:91
void draw()
Definition: label.cpp:554
void read(const config &cfg)
Definition: label.cpp:84
std::string team_name_
Definition: label.hpp:172
To store label data Class implements logic for rendering.
Definition: label.hpp:103
void recalculate()
Definition: label.cpp:516
t_string text_
Definition: label.hpp:169
~terrain_label()
Definition: label.cpp:363
const t_string & tooltip() const
Definition: label.cpp:424
void calculate_shroud()
Definition: label.cpp:521
void clear_all()
Definition: label.cpp:246
void set_text(const t_string &)
Definition: label.cpp:480
bool visible_global_label(const map_location &) const
Returns whether or not a global (non-team) label can be shown at a specified location.
Definition: label.cpp:278
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
SDL_Rect get_rect() const
Definition: label.cpp:541
std::map< std::string, label_map > team_label_map
Definition: label.hpp:33
GLsizei const GLcharARB ** string
Definition: glew.h:4503
map_location loc_
Definition: label.hpp:181
bool categories_dirty
Definition: label.hpp:98