The Battle for Wesnoth
1.17.23+dev
gui
core
widget_definition.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2007 - 2023
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
18
#include "
gui/core/widget_definition.hpp
"
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
28
state_definition::state_definition
(
const
config
& cfg)
29
: canvas_cfg_(
VALIDATE_WML_CHILD
(cfg,
"draw"
,
_
(
"No draw section defined for state."
)))
30
{}
31
32
resolution_definition::resolution_definition
(
const
config
& cfg)
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
51
linked_groups
=
parse_linked_group_definitions
(cfg);
52
}
53
54
styled_widget_definition::styled_widget_definition
(
const
config
& cfg)
55
:
id
(cfg[
"id"
]), description(cfg[
"description"
].t_str()), resolutions()
56
{
57
VALIDATE
(!
id
.empty(),
missing_mandatory_wml_key
(
"styled_widget"
,
"id"
));
58
VALIDATE
(!
description
.
empty
(),
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
config
A config object defines a single node in a WML file, with access to child nodes.
Definition:
config.hpp:161
config::child_range
child_itors child_range(config_key_type key)
Definition:
config.cpp:277
config::const_child_itors
boost::iterator_range< const_child_iterator > const_child_itors
Definition:
config.hpp:285
t_string::empty
bool empty() const
Definition:
tstring.hpp:187
gettext.hpp
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
log.hpp
Define the common log macros for the gui toolkit.
DBG_GUI_P
#define DBG_GUI_P
Definition:
log.hpp:66
id
std::string id
Text to match against addon_info.tags()
Definition:
manager.cpp:215
helper.hpp
font
Collection of helper functions relating to Pango formatting.
Definition:
editor_controller.hpp:39
font::str_to_family_class
family_class str_to_family_class(const std::string &str)
Definition:
font_options.hpp:34
gui2
Generic file dialog.
Definition:
draw_manager.hpp:19
gui2::parse_linked_group_definitions
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
Definition:
linked_group_definition.cpp:24
gui2::decode_font_style
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
gui2::resolution_definition::window_width
unsigned window_width
Definition:
widget_definition.hpp:81
gui2::resolution_definition::linked_groups
std::vector< linked_group_definition > linked_groups
Definition:
widget_definition.hpp:93
gui2::resolution_definition::resolution_definition
resolution_definition(const config &cfg)
Definition:
widget_definition.cpp:32
gui2::resolution_definition::window_height
unsigned window_height
Definition:
widget_definition.hpp:82
gui2::state_definition::state_definition
state_definition(const config &cfg)
Definition:
widget_definition.cpp:28
gui2::styled_widget_definition::description
t_string description
Definition:
widget_definition.hpp:124
gui2::styled_widget_definition::styled_widget_definition
styled_widget_definition(const config &cfg)
Definition:
widget_definition.cpp:54
widget_definition.hpp
missing_mandatory_wml_key
std::string missing_mandatory_wml_key(const std::string §ion, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key.
Definition:
wml_exception.cpp:74
wml_exception.hpp
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
VALIDATE_WML_CHILD
#define VALIDATE_WML_CHILD(cfg, key, message)
Definition:
wml_exception.hpp:47
VALIDATE
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
Definition:
wml_exception.hpp:40
Generated by
1.9.1