The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
widget_definition.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2016 by Mark de Wever <[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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "gettext.hpp"
20 #include "gui/core/log.hpp"
21 #include "gui/widgets/helper.hpp"
22 #include "wml_exception.hpp"
23 
24 namespace gui2
25 {
26 
27 /*WIKI
28  * @page = GUIToolkitWML
29  * @order = 1_widget
30  * @begin{parent}{name=generic/widget_definition/}
31  * == Resolution ==
32  * @begin{tag}{name="resolution"}{min="0"}{max="-1"}
33  *
34  * Depending on the resolution a widget can look different. Resolutions are
35  * evaluated in order of appearance. The ''window_width'' and ''window_height''
36  * are the upper limit this resolution is valid for. When one of the sizes
37  * gets above the limit, the next resolution is selected. There's one special
38  * case where both values are ''0''. This resolution always matches. (Resolution
39  * definitions behind that one will never be picked.) This resolution can be
40  * used as upper limit or if there's only one resolution.
41  *
42  * The default (and also minimum) size of a button is determined by two items,
43  * the wanted default size and the size needed for the text. The size of the
44  * text differs per used widget so needs to be determined per button.
45  *
46  * Container widgets like panels and windows have other rules for their sizes.
47  * Their sizes are based on the size of their children (and the border they need
48  * themselves). It's wise to set all sizes to 0 for these kind of widgets.
49  *
50  * @begin{table}{config}
51  * window_width & unsigned & 0 & Width of the application window. $
52  * window_height & unsigned & 0 & Height of the application window. $
53  *
54  *
55  * min_width & unsigned & 0 & The minimum width of the widget. $
56  * min_height & unsigned & 0 & The minimum height of the widget. $
57  *
58  *
59  * default_width & unsigned & 0 & The default width of the widget. $
60  * default_height & unsigned & 0 & The default height of the widget. $
61  *
62  *
63  * max_width & unsigned & 0 & The maximum width of the widget. $
64  * max_height & unsigned & 0 & The maximum height of the widget. $
65  *
66  * text_extra_width & unsigned & 0 &
67  * The extra width needed to determine the minimal size for the text. $
68  *
69  * text_extra_height & unsigned & 0 &
70  * The extra height needed to determine the minimal size for the text. $
71  *
72  * text_font_family & font_family & "" &
73  * The font family, needed to determine the minimal size for the text. $
74  *
75  * text_font_size & unsigned & 0 &
76  * The font size, which needs to be used to determine the minimal size for
77  * the text. $
78  *
79  * text_font_style & font_style & "" &
80  * The font style, which needs to be used to determine the minimal size for
81  * the text. $
82  *
83  *
84  * state & section & &
85  * Every widget has one or more state sections. Note they aren't called
86  * state but state_xxx the exact names are listed per widget. $
87  * @end{table}
88  * @end{tag}{name="resolution"}
89  * @end{parent}{name=generic/widget_definition/}
90  */
91 
93  : window_width(cfg["window_width"])
94  , window_height(cfg["window_height"])
95  , min_width(cfg["min_width"])
96  , min_height(cfg["min_height"])
97  , default_width(cfg["default_width"])
98  , default_height(cfg["default_height"])
99  , max_width(cfg["max_width"])
100  , max_height(cfg["max_height"])
101  , text_extra_width(cfg["text_extra_width"])
102  , text_extra_height(cfg["text_extra_height"])
103  , text_font_size(cfg["text_font_size"])
104  , text_font_family(font::str_to_family_class(cfg["text_font_family"]))
105  , text_font_style(decode_font_style(cfg["text_font_style"]))
106  , state()
107 {
108  DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height
109  << '\n';
110 }
111 
112 /*WIKI
113  * @page = GUIWidgetDefinitionWML
114  * @order = 1
115  *
116  * {{Autogenerated}}
117  *
118  * = Widget definition =
119  *
120  * This page describes the definition of all widgets in the toolkit. Every
121  * widget has some parts in common, first of all; every definition has the
122  * following fields.
123  * @begin{parent}{name="generic/"}
124  * @begin{tag}{name=widget_definition}{min=0}{max=1}
125  * @begin{table}{config}
126  * id & string & & Unique id for this gui (theme). $
127  * description & t_string & & Unique translatable name for this gui. $
128  *
129  * resolution & section & & The definitions of the widget in various
130  * resolutions. $
131  * @end{table}
132  * @end{tag}{name=widget_definition}
133  * @end{parent}{name="generic/"}
134  */
136  : id(cfg["id"]), description(cfg["description"].t_str()), resolutions()
137 {
138  VALIDATE(!id.empty(), missing_mandatory_wml_key("control", "id"));
140  missing_mandatory_wml_key("control", "description"));
141 
142  /*
143  * Do this validation here instead of in load_resolutions so the
144  * translatable string is not in the header and we don't need to pull in
145  * extra header dependencies.
146  */
147  config::const_child_itors itors = cfg.child_range("resolution");
148  VALIDATE(itors.first != itors.second, _("No resolution defined."));
149 }
150 
151 } // namespace gui2
Define the common log macros for the gui toolkit.
unsigned decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:55
#define DBG_GUI_P
Definition: log.hpp:69
child_itors child_range(const std::string &key)
Definition: config.cpp:613
Graphical text output.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
std::pair< const_child_iterator, const_child_iterator > const_child_itors
Definition: config.hpp:214
std::string missing_mandatory_wml_key(const std::string &section, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
GLuint id
Definition: glew.h:1647
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
tresolution_definition_(const config &cfg)
family_class str_to_family_class(const std::string &str)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool empty() const
Definition: tstring.hpp:166
tcontrol_definition(const config &cfg)