The Battle for Wesnoth  1.15.12+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 
28  : canvas_cfg_(cfg ? cfg.child("draw") : cfg)
29 {
30  VALIDATE(canvas_cfg_, _("No state or draw section defined."));
31 }
32 
34  : window_width(cfg["window_width"])
35  , window_height(cfg["window_height"])
36  , min_width(cfg["min_width"])
37  , min_height(cfg["min_height"])
38  , default_width(cfg["default_width"])
39  , default_height(cfg["default_height"])
40  , max_width(cfg["max_width"])
41  , max_height(cfg["max_height"])
42  , linked_groups()
43  , text_extra_width(cfg["text_extra_width"])
44  , text_extra_height(cfg["text_extra_height"])
45  , text_font_size(cfg["text_font_size"])
46  , text_font_family(font::str_to_family_class(cfg["text_font_family"]))
47  , text_font_style(decode_font_style(cfg["text_font_style"]))
48  , state()
49 {
50  DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height
51  << '\n';
52 
54 }
55 
57  : id(cfg["id"]), description(cfg["description"].t_str()), resolutions()
58 {
59  VALIDATE(!id.empty(), missing_mandatory_wml_key("styled_widget", "id"));
61  missing_mandatory_wml_key("styled_widget", "description"));
62 
63  /*
64  * Do this validation here instead of in load_resolutions so the
65  * translatable string is not in the header and we don't need to pull in
66  * extra header dependencies.
67  */
68  config::const_child_itors itors = cfg.child_range("resolution");
69  VALIDATE(!itors.empty(), _("No resolution defined."));
70 }
71 
72 } // namespace gui2
Define the common log macros for the gui toolkit.
#define DBG_GUI_P
Definition: log.hpp:65
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:356
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
static std::string _(const char *str)
Definition: gettext.hpp:92
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)
#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:204
std::vector< linked_group_definition > linked_groups
bool empty() const
Definition: tstring.hpp:186
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:59
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