The Battle for Wesnoth  1.15.2+dev
widget_definition.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2018 by Mark de Wever <koraq@xs4all.nl>
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 #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  *
31  * == State ==
32  *
33  * @begin{parent}{name="generic/"}
34  * @begin{tag}{name="state"}{min=0}{max=1}
35  * Definition of a state. A state contains the info what to do in a state.
36  * Atm this is rather focused on the drawing part, might change later.
37  * Keys:
38  * @begin{table}{config}
39  * draw & section & & Section with drawing directions for a
40  *canvas. $
41  * @end{table}
42  * @end{tag}{name="state"}
43  * @end{parent}{name="generic/"}
44  *
45  */
47  : canvas_cfg_(cfg ? cfg.child("draw") : cfg)
48 {
49  VALIDATE(canvas_cfg_, _("No state or draw section defined."));
50 }
51 
52 /*WIKI
53  * @page = GUIToolkitWML
54  * @order = 1_widget
55  * @begin{parent}{name=generic/widget_definition/}
56  * == Resolution ==
57  * @begin{tag}{name="resolution"}{min="0"}{max="-1"}
58  *
59  * Depending on the resolution a widget can look different. Resolutions are
60  * evaluated in order of appearance. The ''window_width'' and ''window_height''
61  * are the upper limit this resolution is valid for. When one of the sizes
62  * gets above the limit, the next resolution is selected. There's one special
63  * case where both values are ''0''. This resolution always matches. (Resolution
64  * definitions behind that one will never be picked.) This resolution can be
65  * used as upper limit or if there's only one resolution.
66  *
67  * The default (and also minimum) size of a button is determined by two items,
68  * the wanted default size and the size needed for the text. The size of the
69  * text differs per used widget so needs to be determined per button.
70  *
71  * Container widgets like panels and windows have other rules for their sizes.
72  * Their sizes are based on the size of their children (and the border they need
73  * themselves). It's wise to set all sizes to 0 for these kind of widgets.
74  *
75  * @begin{table}{config}
76  * window_width & unsigned & 0 & Width of the application window. $
77  * window_height & unsigned & 0 & Height of the application window. $
78  *
79  *
80  * min_width & unsigned & 0 & The minimum width of the widget. $
81  * min_height & unsigned & 0 & The minimum height of the widget. $
82  *
83  *
84  * default_width & unsigned & 0 & The default width of the widget. $
85  * default_height & unsigned & 0 & The default height of the widget. $
86  *
87  *
88  * max_width & unsigned & 0 & The maximum width of the widget. $
89  * max_height & unsigned & 0 & The maximum height of the widget. $
90  *
91  * text_extra_width & unsigned & 0 &
92  * The extra width needed to determine the minimal size for the text. $
93  *
94  * text_extra_height & unsigned & 0 &
95  * The extra height needed to determine the minimal size for the text. $
96  *
97  * text_font_family & font_family & "" &
98  * The font family, needed to determine the minimal size for the text. $
99  *
100  * text_font_size & unsigned & 0 &
101  * The font size, which needs to be used to determine the minimal size for
102  * the text. $
103  *
104  * text_font_style & font_style & "" &
105  * The font style, which needs to be used to determine the minimal size for
106  * the text. $
107  *
108  *
109  * state & section & &
110  * Every widget has one or more state sections. Note they aren't called
111  * state but state_xxx the exact names are listed per widget. $
112  * @end{table}
113  * @end{tag}{name="resolution"}
114  * @end{parent}{name=generic/widget_definition/}
115  */
116 
118  : window_width(cfg["window_width"])
119  , window_height(cfg["window_height"])
120  , min_width(cfg["min_width"])
121  , min_height(cfg["min_height"])
122  , default_width(cfg["default_width"])
123  , default_height(cfg["default_height"])
124  , max_width(cfg["max_width"])
125  , max_height(cfg["max_height"])
126  , linked_groups()
127  , text_extra_width(cfg["text_extra_width"])
128  , text_extra_height(cfg["text_extra_height"])
129  , text_font_size(cfg["text_font_size"])
130  , text_font_family(font::str_to_family_class(cfg["text_font_family"]))
131  , text_font_style(decode_font_style(cfg["text_font_style"]))
132  , state()
133 {
134  DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height
135  << '\n';
136 
138 }
139 
140 /*WIKI
141  * @page = GUIWidgetDefinitionWML
142  * @order = 1
143  *
144  * {{Autogenerated}}
145  *
146  * = Widget definition =
147  *
148  * This page describes the definition of all widgets in the toolkit. Every
149  * widget has some parts in common, first of all; every definition has the
150  * following fields.
151  * @begin{parent}{name="generic/"}
152  * @begin{tag}{name=widget_definition}{min=0}{max=1}
153  * @begin{table}{config}
154  * id & string & & Unique id for this gui (theme). $
155  * description & t_string & & Unique translatable name for this gui. $
156  *
157  * resolution & section & & The definitions of the widget in various
158  * resolutions. $
159  * @end{table}
160  * @end{tag}{name=widget_definition}
161  * @end{parent}{name="generic/"}
162  */
164  : id(cfg["id"]), description(cfg["description"].t_str()), resolutions()
165 {
166  VALIDATE(!id.empty(), missing_mandatory_wml_key("styled_widget", "id"));
168  missing_mandatory_wml_key("styled_widget", "description"));
169 
170  /*
171  * Do this validation here instead of in load_resolutions so the
172  * translatable string is not in the header and we don't need to pull in
173  * extra header dependencies.
174  */
175  config::const_child_itors itors = cfg.child_range("resolution");
176  VALIDATE(!itors.empty(), _("No resolution defined."));
177 }
178 
179 } // namespace gui2
Define the common log macros for the gui toolkit.
#define DBG_GUI_P
Definition: log.hpp:68
Note: Specific to sdl_ttf.
Add a special kind of assert to validate whether the input from WML doesn&#39;t contain any problems that...
state_definition(const config &cfg)
child_itors child_range(config_key_type key)
Definition: config.cpp:362
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
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.
Generic file dialog.
Definition: field-fwd.hpp:22
resolution_definition(const config &cfg)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
styled_widget_definition(const config &cfg)
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:210
std::vector< linked_group_definition > linked_groups
bool empty() const
Definition: tstring.hpp:182
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:68
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:37