The Battle for Wesnoth  1.17.0-dev
widget_definition.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2021
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_(cfg ? cfg.child("draw") : cfg)
30 {
31  VALIDATE(canvas_cfg_, _("No state or draw section defined."));
32 }
33 
35  : window_width(cfg["window_width"])
36  , window_height(cfg["window_height"])
37  , min_width(cfg["min_width"])
38  , min_height(cfg["min_height"])
39  , default_width(cfg["default_width"])
40  , default_height(cfg["default_height"])
41  , max_width(cfg["max_width"])
42  , max_height(cfg["max_height"])
43  , linked_groups()
44  , text_extra_width(cfg["text_extra_width"])
45  , text_extra_height(cfg["text_extra_height"])
46  , text_font_size(cfg["text_font_size"])
47  , text_font_family(font::str_to_family_class(cfg["text_font_family"]))
48  , text_font_style(decode_font_style(cfg["text_font_style"]))
49  , state()
50 {
51  DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height
52  << '\n';
53 
55 }
56 
58  : id(cfg["id"]), description(cfg["description"].t_str()), resolutions()
59 {
60  VALIDATE(!id.empty(), missing_mandatory_wml_key("styled_widget", "id"));
62  missing_mandatory_wml_key("styled_widget", "description"));
63 
64  /*
65  * Do this validation here instead of in load_resolutions so the
66  * translatable string is not in the header and we don't need to pull in
67  * extra header dependencies.
68  */
69  config::const_child_itors itors = cfg.child_range("resolution");
70  VALIDATE(!itors.empty(), _("No resolution defined."));
71 }
72 
73 } // namespace gui2
Define the common log macros for the gui toolkit.
#define DBG_GUI_P
Definition: log.hpp:66
Collection of helper functions relating to Pango formatting.
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:361
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
static std::string _(const char *str)
Definition: gettext.hpp:93
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:23
resolution_definition(const config &cfg)
#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:205
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
std::vector< linked_group_definition > linked_groups
bool empty() const
Definition: tstring.hpp:187
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:60
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:38