The Battle for Wesnoth  1.19.0-dev
widget_definition.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "gettext.hpp"
21 #include "gui/core/log.hpp"
22 #include "gui/widgets/helper.hpp"
23 #include "wml_exception.hpp"
24 
25 namespace gui2
26 {
27 
29  : canvas_cfg_(VALIDATE_WML_CHILD(cfg, "draw", _("No draw section defined for state.")))
30 {}
31 
33  : window_width(cfg["window_width"])
34  , window_height(cfg["window_height"])
35  , min_width(cfg["min_width"])
36  , min_height(cfg["min_height"])
37  , default_width(cfg["default_width"])
38  , default_height(cfg["default_height"])
39  , max_width(cfg["max_width"])
40  , max_height(cfg["max_height"])
41  , linked_groups()
42  , text_extra_width(cfg["text_extra_width"])
43  , text_extra_height(cfg["text_extra_height"])
44  , text_font_size(cfg["text_font_size"])
45  , text_font_family(font::str_to_family_class(cfg["text_font_family"]))
46  , text_font_style(decode_font_style(cfg["text_font_style"]))
47  , state()
48 {
49  DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height;
50 
52 }
53 
55  : id(cfg["id"]), description(cfg["description"].t_str()), resolutions()
56 {
57  VALIDATE(!id.empty(), missing_mandatory_wml_key("styled_widget", "id"));
59  missing_mandatory_wml_key("styled_widget", "description"));
60 
61  /*
62  * Do this validation here instead of in load_resolutions so the
63  * translatable string is not in the header and we don't need to pull in
64  * extra header dependencies.
65  */
66  config::const_child_itors itors = cfg.child_range("resolution");
67  VALIDATE(!itors.empty(), _("No resolution defined."));
68 }
69 
70 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
child_itors child_range(config_key_type key)
Definition: config.cpp:274
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:283
bool empty() const
Definition: tstring.hpp:187
static std::string _(const char *str)
Definition: gettext.hpp:93
Define the common log macros for the gui toolkit.
#define DBG_GUI_P
Definition: log.hpp:66
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
Collection of helper functions relating to Pango formatting.
family_class str_to_family_class(const std::string &str)
Generic file dialog.
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:34
std::vector< linked_group_definition > linked_groups
resolution_definition(const config &cfg)
state_definition(const config &cfg)
styled_widget_definition(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 (attribute).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.