The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
theme.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 /**
16  * @file
17  * Definitions related to theme-support.
18  */
19 
20 #ifndef THEME_HPP_INCLUDED
21 #define THEME_HPP_INCLUDED
22 
23 #include "config.hpp"
24 #include "generic_event.hpp"
25 
26 #include <SDL_video.h>
27 
28 typedef struct { size_t x1,y1,x2,y2; } _rect;
29 
30 struct theme_info
31 {
35 };
36 
37 class theme
38 {
39 
40  class object
41  {
42  public:
43  object();
44  object(const config& cfg);
45  virtual ~object() { }
46 
47  SDL_Rect& location(const SDL_Rect& screen) const;
48  const SDL_Rect& get_location() const { return loc_; }
49  const std::string& get_id() const { return id_; }
50 
51  // This supports relocating of theme elements ingame.
52  // It is needed for [change] tags in theme WML.
53  void modify_location(const _rect& rect);
54  void modify_location(std::string rect_str, SDL_Rect rect_ref);
55 
56  // All on-screen objects have 'anchoring' in the x and y dimensions.
57  // 'fixed' means that they have fixed co-ordinates and don't move.
58  // 'top anchored' means they are anchored to the top (or left) side
59  // of the screen - the top (or left) edge stays a constant distance
60  // from the top of the screen.
61  // 'bottom anchored' is the inverse of top anchored.
62  // 'proportional' means the location and dimensions change
63  // proportionally to the screen size.
65 
66  private:
69  SDL_Rect loc_;
70  mutable SDL_Rect relative_loc_;
71  mutable SDL_Rect last_screen_;
72 
74 
75  static ANCHORING read_anchor(const std::string& str);
76  };
77 
78  struct tborder
79  {
80 
81  tborder();
82  tborder(const config& cfg);
83 
84  double size;
85 
88 
91 
94 
97 
100 
103 
106 
107  };
108 
109 public:
110 
111  class label : public object
112  {
113  public:
114  label();
115  explicit label(const config& cfg);
116 
117  using object::location;
118 
119  const std::string& text() const { return text_; }
120  void set_text(const std::string& text) { text_ = text; }
121  const std::string& icon() const { return icon_; }
122 
123  bool empty() const { return text_.empty() && icon_.empty(); }
124 
125  size_t font_size() const { return font_; }
126  Uint32 font_rgb() const { return font_rgb_; }
127  bool font_rgb_set() const { return font_rgb_set_; }
128  private:
130  size_t font_;
132  Uint32 font_rgb_;
133  };
134 
135  class status_item : public object
136  {
137  public:
138 
139  explicit status_item(const config& cfg);
140 
141  using object::location;
142 
143  const std::string& prefix() const { return prefix_; }
144  const std::string& postfix() const { return postfix_; }
145 
146  // If the item has a label associated with it, Show where the label is
147  const label* get_label() const { return label_.empty() ? nullptr : &label_; }
148 
149  size_t font_size() const { return font_; }
150  Uint32 font_rgb() const { return font_rgb_; }
151  bool font_rgb_set() const { return font_rgb_set_; }
152 
153  private:
156  size_t font_;
158  Uint32 font_rgb_;
159  };
160 
161  class panel : public object
162  {
163  public:
164  explicit panel(const config& cfg);
165 
166  using object::location;
167 
168  const std::string& image() const { return image_; }
169 
170  private:
172  };
173 
174  class action : public object
175  {
176  public:
177  action();
178  explicit action(const config& cfg);
179 
180  using object::location;
181 
182  bool is_context() const { return context_; }
183 
184  const std::string& title() const { return title_; }
185 
186  const std::string tooltip(size_t index) const;
187 
188  const std::string& type() const { return type_; }
189 
190  const std::string& image() const { return image_; }
191 
192  const std::string& overlay() const { return overlay_; }
193 
194  const std::vector<std::string>& items() const { return items_; }
195 
196  void set_title(const std::string& new_title) { title_ = new_title; }
197  private:
200  std::vector<std::string> items_;
201  };
202 
203  class slider : public object
204  {
205  public:
206  slider();
207  explicit slider(const config& cfg);
208 
209  using object::location;
210 
211  const std::string& title() const { return title_; }
212 
213  const std::string& tooltip() const { return tooltip_; }
214 
215  const std::string& image() const { return image_; }
216 
217  const std::string& overlay() const { return overlay_; }
218 
219  bool black_line() const { return black_line_; }
220 
221  void set_title(const std::string& new_title) { title_ = new_title; }
222  private:
225  };
226 
227  class menu : public object
228  {
229  public:
230  menu();
231  explicit menu(const config& cfg);
232 
233  using object::location;
234 
235  bool is_button() const { return button_; }
236 
237  bool is_context() const { return context_; }
238 
239  const std::string& title() const { return title_; }
240 
241  const std::string& tooltip() const { return tooltip_; }
242 
243  const std::string& image() const { return image_; }
244 
245  const std::string& overlay() const { return overlay_; }
246 
247  const std::vector<std::string>& items() const { return items_; }
248 
249  void set_title(const std::string& new_title) { title_ = new_title; }
250  private:
251  bool button_;
252  bool context_;
254  std::vector<std::string> items_;
255  };
256 
257  explicit theme(const config& cfg, const SDL_Rect& screen);
258  bool set_resolution(const SDL_Rect& screen);
259  void modify(const config &cfg);
260 
261  const std::vector<panel>& panels() const { return panels_; }
262  const std::vector<label>& labels() const { return labels_; }
263  const std::vector<menu>& menus() const { return menus_; }
264  const std::vector<slider>& sliders() const { return sliders_; }
265  const std::vector<action>& actions() const { return actions_; }
266 
267  const menu* context_menu() const
268  { return context_.is_context() ? &context_ : nullptr; }
269 
270  //refresh_title2 changes the title of a menu entry, identified by id.
271  //If no menu entry is found, an empty menu object is returned.
272  object* refresh_title(const std::string& id, const std::string& new_title);
273  object* refresh_title2(const std::string& id, const std::string& title_tag);
274  void modify_label(const std::string& id, const std::string& text);
275 
276  const status_item* get_status_item(const std::string& item) const;
277  const menu *get_menu_item(const std::string &key) const;
278  const action* get_action_item(const std::string &key) const;
279 
280  const SDL_Rect& main_map_location(const SDL_Rect& screen) const
281  { return main_map_.location(screen); }
282  const SDL_Rect& mini_map_location(const SDL_Rect& screen) const
283  { return mini_map_.location(screen); }
284  const SDL_Rect& unit_image_location(const SDL_Rect& screen) const
285  { return unit_image_.location(screen); }
286  const SDL_Rect& palette_location(const SDL_Rect& screen) const
287  { return palette_.location(screen); }
288 
289  static void set_known_themes(const config* cfg);
290  static std::vector<theme_info> get_known_themes();
291 
292  const tborder& border() const { return border_; }
293 
295 
296 private:
298  void add_object(const config& cfg);
299  void remove_object(std::string id);
300  void set_object_location(theme::object& element, std::string rect_str, std::string ref_id);
301 
302  //notify observers that the theme has been rebuilt completely
303  //atm this is used for replay_controller to add replay controls to the standard theme
305 
306  static std::map<std::string, config> known_themes;
309  std::vector<panel> panels_;
310  std::vector<label> labels_;
311  std::vector<menu> menus_;
312  std::vector<action> actions_;
313  std::vector<slider> sliders_;
314 
317 
318  std::map<std::string,status_item> status_;
319 
321 
323 };
324 
325 #endif
std::vector< label > labels_
Definition: theme.hpp:310
t_string description
Definition: theme.hpp:34
size_t y2
Definition: theme.hpp:28
bool context_
Definition: theme.hpp:252
const std::string & tooltip() const
Definition: theme.hpp:241
std::string title_
Definition: theme.hpp:253
const std::string & text() const
Definition: theme.hpp:119
std::string image_
Definition: theme.hpp:253
events::generic_event theme_reset_event_
Definition: theme.hpp:304
config cfg_
Definition: theme.hpp:308
std::string cur_theme
Definition: theme.hpp:307
void set_title(const std::string &new_title)
Definition: theme.hpp:196
std::string overlay_
Definition: theme.hpp:253
std::string border_image_bottom_odd
Definition: theme.hpp:104
const std::string & title() const
Definition: theme.hpp:239
std::string border_image_top_even
Definition: theme.hpp:102
Uint32 font_rgb_
Definition: theme.hpp:158
std::vector< std::string > items_
Definition: theme.hpp:254
std::string title_
Definition: theme.hpp:199
std::string border_image_bottom_even
Definition: theme.hpp:105
std::string border_image_top_odd
Definition: theme.hpp:101
std::string corner_image_top_left
Definition: theme.hpp:89
Definition: theme.hpp:28
const SDL_Rect & mini_map_location(const SDL_Rect &screen) const
Definition: theme.hpp:282
std::vector< action > actions_
Definition: theme.hpp:312
Uint32 font_rgb() const
Definition: theme.hpp:126
std::string prefix_
Definition: theme.hpp:154
static void set_known_themes(const config *cfg)
Definition: theme.cpp:912
const std::string tooltip(size_t index) const
Definition: theme.cpp:593
void set_title(const std::string &new_title)
Definition: theme.hpp:221
std::string title_
Definition: theme.hpp:223
const std::string & overlay() const
Definition: theme.hpp:217
bool black_line_
Definition: theme.hpp:224
const std::vector< std::string > & items() const
Definition: theme.hpp:194
std::string id
Definition: theme.hpp:32
game_display * screen
Definition: resources.cpp:27
t_string name
Definition: theme.hpp:33
void remove_object(std::string id)
Definition: theme.cpp:786
std::vector< panel > panels_
Definition: theme.hpp:309
SDL_Rect last_screen_
Definition: theme.hpp:71
const std::vector< menu > & menus() const
Definition: theme.hpp:263
const std::string & image() const
Definition: theme.hpp:168
std::string image_
Definition: theme.hpp:223
std::string border_image_right
Definition: theme.hpp:99
std::string corner_image_bottom_right_even
Definition: theme.hpp:96
std::vector< slider > sliders_
Definition: theme.hpp:313
object mini_map_
Definition: theme.hpp:320
object palette_
Definition: theme.hpp:320
std::string text_
Definition: theme.hpp:129
void add_object(const config &cfg)
Definition: theme.cpp:703
bool font_rgb_set() const
Definition: theme.hpp:127
bool auto_tooltip_
Definition: theme.hpp:198
Definitions for the interface to Wesnoth Markup Language (WML).
std::string type_
Definition: theme.hpp:199
bool context_
Definition: theme.hpp:198
std::string overlay_
Definition: theme.hpp:223
std::string tooltip_
Definition: theme.hpp:199
status_item(const config &cfg)
Definition: theme.cpp:484
static std::map< std::string, config > known_themes
Definition: theme.hpp:306
std::string postfix_
Definition: theme.hpp:154
SDL_Rect & location(const SDL_Rect &screen) const
Definition: theme.cpp:342
std::string image_
Definition: theme.hpp:199
const std::vector< label > & labels() const
Definition: theme.hpp:262
Uint32 font_rgb() const
Definition: theme.hpp:150
bool font_rgb_set() const
Definition: theme.hpp:151
const std::string & image() const
Definition: theme.hpp:215
std::vector< menu > menus_
Definition: theme.hpp:311
const status_item * get_status_item(const std::string &item) const
Definition: theme.cpp:900
menu context_
Definition: theme.hpp:315
const std::string & postfix() const
Definition: theme.hpp:144
const std::string & overlay() const
Definition: theme.hpp:192
const std::string & get_id() const
Definition: theme.hpp:49
std::string corner_image_top_right_even
Definition: theme.hpp:93
const std::string & icon() const
Definition: theme.hpp:121
bool button_
Definition: theme.hpp:251
events::generic_event & theme_reset_event()
Definition: theme.hpp:294
theme(const config &cfg, const SDL_Rect &screen)
Definition: theme.cpp:613
const menu * get_menu_item(const std::string &key) const
Definition: theme.cpp:945
void modify(const config &cfg)
Definition: theme.cpp:833
std::string corner_image_bottom_left
Definition: theme.hpp:90
const SDL_Rect & unit_image_location(const SDL_Rect &screen) const
Definition: theme.hpp:284
const std::string & image() const
Definition: theme.hpp:243
size_t font_size() const
Definition: theme.hpp:149
const menu * context_menu() const
Definition: theme.hpp:267
virtual ~object()
Definition: theme.hpp:45
std::string tooltip_
Definition: theme.hpp:223
std::string image_
Definition: theme.hpp:171
const std::string & title() const
Definition: theme.hpp:184
std::string background_image
Definition: theme.hpp:86
std::string corner_image_bottom_right_odd
Definition: theme.hpp:95
bool empty() const
Definition: theme.hpp:123
std::string icon_
Definition: theme.hpp:129
const SDL_Rect & palette_location(const SDL_Rect &screen) const
Definition: theme.hpp:286
bool black_line() const
Definition: theme.hpp:219
const std::vector< action > & actions() const
Definition: theme.hpp:265
static std::vector< theme_info > get_known_themes()
Definition: theme.cpp:928
const std::vector< slider > & sliders() const
Definition: theme.hpp:264
object * refresh_title(const std::string &id, const std::string &new_title)
Definition: theme.cpp:961
std::string tooltip_
Definition: theme.hpp:253
GLuint index
Definition: glew.h:1782
Definition: theme.hpp:37
void modify_label(const std::string &id, const std::string &text)
Definition: theme.cpp:992
Uint32 font_rgb_
Definition: theme.hpp:132
size_t font_
Definition: theme.hpp:130
bool is_button() const
Definition: theme.hpp:235
ANCHORING xanchor_
Definition: theme.hpp:73
const std::string & title() const
Definition: theme.hpp:211
double size
Definition: theme.hpp:84
std::string corner_image_top_right_odd
Definition: theme.hpp:92
bool is_context() const
Definition: theme.hpp:182
const tborder & border() const
Definition: theme.hpp:292
const action * get_action_item(const std::string &key) const
Definition: theme.cpp:953
std::string tile_image
Definition: theme.hpp:87
const std::vector< panel > & panels() const
Definition: theme.hpp:261
bool location_modified_
Definition: theme.hpp:67
bool tooltip_name_prepend_
Definition: theme.hpp:198
bool set_resolution(const SDL_Rect &screen)
Definition: theme.cpp:633
std::string border_image_left
Definition: theme.hpp:98
const std::vector< std::string > & items() const
Definition: theme.hpp:247
void set_text(const std::string &text)
Definition: theme.hpp:120
std::string overlay_
Definition: theme.hpp:199
const SDL_Rect & main_map_location(const SDL_Rect &screen) const
Definition: theme.hpp:280
std::vector< std::string > items_
Definition: theme.hpp:200
object * refresh_title2(const std::string &id, const std::string &title_tag)
Definition: theme.cpp:982
const std::string & prefix() const
Definition: theme.hpp:143
theme::object & find_element(std::string id)
Definition: theme.cpp:878
void modify_location(const _rect &rect)
Definition: theme.cpp:414
std::string id_
Definition: theme.hpp:68
bool is_context() const
Definition: theme.hpp:237
void set_object_location(theme::object &element, std::string rect_str, std::string ref_id)
Definition: theme.cpp:819
object unit_image_
Definition: theme.hpp:320
const SDL_Rect & get_location() const
Definition: theme.hpp:48
tborder border_
Definition: theme.hpp:322
const std::string & tooltip() const
Definition: theme.hpp:213
size_t font_size() const
Definition: theme.hpp:125
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
static ANCHORING read_anchor(const std::string &str)
Definition: theme.cpp:399
bool font_rgb_set_
Definition: theme.hpp:131
std::map< std::string, status_item > status_
Definition: theme.hpp:318
ANCHORING yanchor_
Definition: theme.hpp:73
SDL_Rect relative_loc_
Definition: theme.hpp:70
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void set_title(const std::string &new_title)
Definition: theme.hpp:249
const std::string & overlay() const
Definition: theme.hpp:245
const std::string & type() const
Definition: theme.hpp:188
const std::string & image() const
Definition: theme.hpp:190
object main_map_
Definition: theme.hpp:320
panel(const config &cfg)
Definition: theme.cpp:525
action action_context_
Definition: theme.hpp:316
const label * get_label() const
Definition: theme.hpp:147
SDL_Rect loc_
Definition: theme.hpp:69