16 #define GETTEXT_DOMAIN "wesnoth-lib"
38 , description_(cfg[
"description"].t_str())
39 , popup_show_delay_(0)
42 , double_click_time_(0)
43 , repeat_button_repeat_time_(0)
44 , sound_button_click_()
45 , sound_toggle_button_click_()
46 , sound_toggle_panel_click_()
47 , sound_slider_adjust_()
48 , has_helptip_message_()
49 , tips_(tip_of_the_day::
load(cfg))
64 const std::string key = widget_parser.key
66 : type_id +
"_definition";
68 bool found_default_def =
false;
74 const std::string& def_id = def_ptr->id;
76 if(def_map.find(def_id) != def_map.end()) {
77 ERR_GUI_P <<
"Skipping duplicate definition '" << def_id <<
"' for '" << type_id <<
"'";
81 def_map.emplace(def_id, std::move(def_ptr));
83 if(def_id ==
"default") {
84 found_default_def =
true;
90 if(
id_ ==
"default") {
91 VALIDATE(found_default_def,
"No default definition found for widget '" + type_id +
"'");
104 if(
id_ ==
"default") {
108 const std::string error_msg(
109 "Window not defined in WML: '" + window_type +
"'."
110 "Perhaps a mismatch between data and source versions. Try --data-dir <trunk-dir>");
128 using namespace std::chrono_literals;
165 template<
typename TList,
typename TConv>
166 const typename TList::value_type& get_best_resolution(
const TList& list,
const TConv&
get_size)
168 using resolution_t =
const typename TList::value_type;
170 resolution_t* best_resolution =
nullptr;
171 int best_resolution_score = std::numeric_limits<int>::min();
176 for(
const auto& res : list) {
183 if(
w <= screen_w &&
h <= screen_h) {
188 score = std::min(screen_w -
w, 0) + std::min(screen_h -
h, 0);
191 if(score >= best_resolution_score) {
192 best_resolution = &res;
193 best_resolution_score = score;
197 assert(best_resolution !=
nullptr);
198 return *best_resolution;
205 const auto& current_types =
current_gui->second.widget_types;
206 const auto& default_types =
default_gui->second.widget_types;
208 const auto widget_definitions = current_types.find(control_type);
210 gui_definition::widget_definition_map_t::const_iterator control;
212 if(widget_definitions == current_types.end()) {
216 control = widget_definitions->second.find(definition);
218 if(control == widget_definitions->second.end()) {
220 bool found_fallback =
false;
223 auto default_widget_definitions = default_types.find(control_type);
225 VALIDATE(widget_definitions != current_types.end(),
226 formatter() <<
"Type '" << control_type <<
"' is unknown.");
228 control = default_widget_definitions->second.find(definition);
229 found_fallback = control != default_widget_definitions->second.end();
232 if(!found_fallback) {
233 if(definition !=
"default") {
234 LOG_GUI_G <<
"Control: type '" << control_type <<
"' definition '" << definition
235 <<
"' not found, falling back to 'default'.";
239 FAIL(
formatter() <<
"default definition not found for styled_widget " << control_type);
243 const auto& resolutions = (*control->second).resolutions;
246 formatter() <<
"Control: type '" << control_type <<
"' definition '" << definition <<
"' has no resolutions.\n");
250 static_cast<int>(ptr->window_width),
251 static_cast<int>(ptr->window_height)
260 const auto& current_windows =
current_gui->second.window_types;
261 const auto& default_windows =
default_gui->second.window_types;
263 auto iter = current_windows.find(
type);
265 if(iter == current_windows.end()) {
272 iter = default_windows.find(
type);
274 if(iter == default_windows.end()) {
279 const auto& resolutions = iter->second.resolutions;
293 auto& def_map =
current_gui->second.widget_types[widget_type];
297 throw std::invalid_argument(
"widget '" + widget_type +
"' doesn't exist");
300 if(def_map.find(definition_id) != def_map.end()) {
304 def_map.emplace(definition_id, parser->second.parser(cfg));
310 auto& definition_map =
current_gui->second.widget_types[widget_type];
312 auto it = definition_map.find(definition_id);
313 if(it != definition_map.end()) {
314 definition_map.erase(it);
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
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).
std::chrono::milliseconds popup_show_time_
t_string has_helptip_message_
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_
std::chrono::milliseconds repeat_button_repeat_time_
std::chrono::milliseconds double_click_time_
std::string sound_toggle_button_click_
std::chrono::milliseconds popup_show_delay_
std::string sound_slider_adjust_
std::string sound_toggle_panel_click_
gui_definition(const config &cfg)
Private ctor.
std::string sound_button_click_
std::chrono::milliseconds help_show_time_
void activate() const
Activates this GUI.
Definitions for the interface to Wesnoth Markup Language (WML).
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.
Contains the general settings which have a default.
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.
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.