16 #define GETTEXT_DOMAIN "wesnoth-lib"
30 using namespace std::chrono_literals;
40 , description_(cfg[
"description"].t_str())
41 , settings_(cfg.mandatory_child(
"settings"))
42 , tips_(tip_of_the_day::
load(cfg))
57 const std::string key = widget_parser.key
59 : type_id +
"_definition";
61 bool found_default_def =
false;
67 const std::string& def_id = def_ptr->id;
68 auto [
_, success] = def_map.emplace(def_id, std::move(def_ptr));
71 ERR_GUI_P <<
"Skipping duplicate definition '" << def_id <<
"' for '" << type_id <<
"'";
75 if(def_id ==
"default") {
76 found_default_def =
true;
82 if(
id_ ==
"default") {
83 VALIDATE(found_default_def,
"No default definition found for widget '" + type_id +
"'");
96 if(
id_ ==
"default") {
100 const std::string error_msg(
101 "Window not defined in WML: '" + window_type +
"'."
102 "Perhaps a mismatch between data and source versions. Try --data-dir <trunk-dir>");
145 template<
typename TList,
typename TConv>
146 const typename TList::value_type& get_best_resolution(
const TList& list,
const TConv&
get_size)
148 using resolution_t =
const typename TList::value_type;
150 resolution_t* best_resolution =
nullptr;
151 int best_resolution_score = std::numeric_limits<int>::min();
156 for(
const auto& res : list) {
163 if(
w <= screen_w &&
h <= screen_h) {
168 score = std::min(screen_w -
w, 0) + std::min(screen_h -
h, 0);
171 if(score >= best_resolution_score) {
172 best_resolution = &res;
173 best_resolution_score = score;
177 assert(best_resolution !=
nullptr);
178 return *best_resolution;
185 const auto& current_types =
current_gui->second.widget_types;
186 const auto& default_types =
default_gui->second.widget_types;
188 const auto find_definition =
189 [&](
const auto&
widget_types) -> utils::optional<gui_definition::widget_definition_map_t::const_iterator>
192 const auto widget_definitions =
widget_types.find(control_type);
196 formatter() <<
"Control: type '" << control_type <<
"' is unknown.");
198 const auto& options = widget_definitions->second;
201 if(
auto control = options.find(definition); control != options.end()) {
204 return utils::nullopt;
208 auto control = find_definition(current_types);
212 control = find_definition(default_types);
216 if(!control && definition !=
"default") {
217 LOG_GUI_G <<
"Control: type '" << control_type <<
"' definition '" << definition
218 <<
"' not found, falling back to 'default'.";
223 formatter() <<
"Control: definition '" << definition <<
"' not found for styled_widget " << control_type);
226 const auto& resolutions = (*control)->second->resolutions;
229 formatter() <<
"Control: type '" << control_type <<
"' definition '" << definition <<
"' has no resolutions.");
233 static_cast<int>(ptr->window_width),
234 static_cast<int>(ptr->window_height)
243 const auto& current_windows =
current_gui->second.window_types;
244 const auto& default_windows =
default_gui->second.window_types;
246 auto iter = current_windows.find(
type);
248 if(iter == current_windows.end()) {
255 iter = default_windows.find(
type);
257 if(iter == default_windows.end()) {
262 const auto& resolutions = iter->second.resolutions;
276 auto& def_map =
current_gui->second.widget_types[widget_type];
280 throw std::invalid_argument(
"widget '" + widget_type +
"' doesn't exist");
283 auto [
_, success] = def_map.emplace(definition_id, parser->second.parser(cfg));
289 auto& definition_map =
current_gui->second.widget_types[widget_type];
291 auto it = definition_map.find(definition_id);
292 if(it != definition_map.end()) {
293 definition_map.erase(it);
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
std::map< std::string, builder_window > window_types
Map of all known windows (the builder class builds a window).
settings_helper settings_
std::map< std::string, widget_definition_map_t > widget_types
Map of each widget type, by id, and a sub-map of each of the type's definitions, also by id.
std::vector< game_tip > tips_
gui_definition(const config &cfg)
Private ctor.
void activate() const
Activates this GUI.
Definitions for the interface to Wesnoth Markup Language (WML).
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
auto parse_duration(const config_attribute_value &val, const Duration &def=Duration{0})
void point(int x, int y)
Draw a single point.
t_string has_helptip_message
unsigned screen_width
The screen resolution and pixel pitch should be available for all widgets since their drawing method ...
std::vector< game_tip > tips
std::chrono::milliseconds double_click_time
std::string sound_slider_adjust
std::string sound_toggle_button_click
std::chrono::milliseconds popup_show_delay
These are copied from the active gui.
std::string sound_button_click
std::chrono::milliseconds popup_show_time
std::chrono::milliseconds help_show_time
std::string sound_toggle_panel_click
void update_screen_size_variables()
Update the size of the screen variables in settings.
std::chrono::milliseconds repeat_button_repeat_time
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
std::shared_ptr< styled_widget_definition > styled_widget_definition_ptr
bool add_single_widget_definition(const std::string &widget_type, const std::string &definition_id, const config &cfg)
Adds a widget definition to the default GUI.
void remove_single_widget_definition(const std::string &widget_type, const std::string &definition_id)
Removes a widget definition from the default GUI.
std::shared_ptr< resolution_definition > resolution_definition_ptr
const builder_window::window_resolution & get_window_builder(const std::string &type)
Returns an reference to the requested builder.
std::set< std::string > & registered_window_types()
Returns the list of registered windows.
gui_theme_map_t guis
Map of all known GUIs.
std::map< std::string, registered_widget_parser > & registered_widget_types()
Returns the list of registered widgets and their parsers.
std::map< std::string, gui_definition > gui_theme_map_t
gui_theme_map_t::iterator current_gui
Iterator pointing to the current GUI.
gui_theme_map_t::iterator default_gui
Iterator pointing to the default GUI.
resolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
Returns the appropriate config data for a widget instance fom the active GUI definition.
point get_size(const locator &i_locator, bool skip_cache)
Returns the width and height of an image.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::string::const_iterator iterator
This file contains the settings handling of the widget library.
std::chrono::milliseconds popup_show_time
std::string sound_slider_adjust
std::string sound_toggle_button_click
settings_helper(const config &cfg)
std::string sound_toggle_panel_click
std::chrono::milliseconds double_click_time
std::chrono::milliseconds popup_show_delay
std::string sound_button_click
t_string has_helptip_message
std::chrono::milliseconds repeat_button_repeat_time
std::chrono::milliseconds help_show_time
Helper struct to signal that get_window_builder failed.
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 (attribute).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.