The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
settings.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 /**
16  * @file
17  * This file contains the settings handling of the widget library.
18  */
19 
20 #ifndef GUI_WIDGETS_SETTING_HPP_INCLUDED
21 #define GUI_WIDGETS_SETTING_HPP_INCLUDED
22 
23 #include "utils/functional.hpp"
24 #include "config.hpp"
27 #include "tstring.hpp"
28 
29 #include <string>
30 #include <vector>
31 
32 namespace gui2
33 {
34 
35 struct tgui_definition;
36 class ttip;
37 
38 /** Do we wish to use the new library or not. */
39 extern bool new_widgets;
40 
41 /**
42  * Registers a window.
43  *
44  * This function registers the available windows defined in WML. All windows
45  * need to register themselves before @ref gui2::init) is called.
46  *
47  * @warning This function runs before @ref main() so needs to be careful
48  * regarding the static initialization problem.
49  *
50  * @note Double registering a window can't hurt, but no way to probe for it,
51  * this can be added if needed. The same for an unregister function.
52  *
53  * @param id The id of the window to register.
54  */
55 void register_window(const std::string& id);
56 
57 /**
58  * Special helper class to get the list of registered windows.
59  *
60  * This is used in the unit tests, but these implementation details shouldn't
61  * be used in the normal code.
62  */
64 {
65  friend std::vector<std::string>& unit_test_registered_window_list();
66 
67  /** Returns a copy of the list of registered windows. */
68  static std::vector<std::string> get_registered_window_list();
69 };
70 
71 /**
72  * Registers a widgets.
73  *
74  * This function registers the available widgets defined in WML. All widgets
75  * need to register themselves before @ref gui2::init) is called.
76  *
77  * @warning This function runs before @ref main() so needs to be careful
78  * regarding the static initialization problem.
79  *
80  * @param id The id of the widget to register.
81  * @param functor The function to load the definitions.
82  */
83 void register_widget(const std::string& id,
84  std::function<void(tgui_definition& gui_definition,
85  const std::string& definition_type,
86  const config& cfg,
87  const char* key)> functor);
88 
89 /**
90  * Loads the definitions of a widget.
91  *
92  * @param gui_definition The gui definition the widget definition
93  * belongs to.
94  * @param definition_type The type of the widget whose definitions are
95  * to be loaded.
96  * @param definitions The definitions serialized from a config
97  * object.
98  */
100  tgui_definition& gui_definition,
101  const std::string& definition_type,
102  const std::vector<tcontrol_definition_ptr>& definitions);
103 
104 /**
105  * Loads the definitions of a widget.
106  *
107  * This function is templated and kept small so only loads the definitions from
108  * the config and then lets the real job be done by the @ref
109  * load_widget_definitions above.
110  *
111  * @param gui_definition The gui definition the widget definition
112  * belongs to.
113  * @param definition_type The type of the widget whose definitions are
114  * to be loaded.
115  * @param cfg The config to serialise the definitions
116  * from.
117  * @param key Optional id of the definition to load.
118  */
119 template <class T>
121  const std::string& definition_type,
122  const config& cfg,
123  const char* key)
124 {
125  std::vector<tcontrol_definition_ptr> definitions;
126 
127  for (const auto & definition :
128  cfg.child_range(key ? key : definition_type + "_definition"))
129  {
130 
131  definitions.push_back(new T(definition));
132  }
133 
134  load_widget_definitions(gui_definition, definition_type, definitions);
135 }
136 
137 
139  const std::string& definition);
140 
141 /** Helper struct to signal that get_window_builder failed. */
143 {
144 };
145 
146 /**
147  * Returns an interator to the requested builder.
148  *
149  * The builder is determined by the @p type and the current screen
150  * resolution.
151  *
152  * @pre There is a valid builder for @p type at the
153  * current resolution.
154  *
155  * @throw twindow_builder_invalid_id
156  * When the precondition is violated.
157  *
158  * @param type The type of builder window to get.
159  *
160  * @returns An iterator to the requested builder.
161  */
162 std::vector<twindow_builder::tresolution>::const_iterator
164 
165 /** Loads the setting for the theme. */
166 void load_settings();
167 
168 /** This namespace contains the 'global' settings. */
169 namespace settings
170 {
171 
172 /**
173  * The screen resolution should be available for all widgets since
174  * their drawing method will depend on it.
175  */
176 extern unsigned screen_width;
177 extern unsigned screen_height;
178 
179 /**
180  * The offset between the left edge of the screen and the gamemap.
181  */
182 extern unsigned gamemap_x_offset;
183 
184 /**
185  * The size of the map area, if not available equal to the screen
186  * size.
187  */
188 extern unsigned gamemap_width;
189 extern unsigned gamemap_height;
190 
191 /** These are copied from the active gui. */
192 extern unsigned popup_show_delay;
193 extern unsigned popup_show_time;
194 extern unsigned help_show_time;
195 extern unsigned double_click_time;
196 extern unsigned repeat_button_repeat_time;
197 
202 
204 
205 std::vector<ttip> get_tips();
206 }
207 
208 } // namespace gui2
209 
210 #endif
bool new_widgets
Do we wish to use the new library or not.
Definition: settings.cpp:40
child_itors child_range(const std::string &key)
Definition: config.cpp:613
unsigned double_click_time
Definition: settings.cpp:55
void register_window(const std::string &id)
Registers a window.
Definition: settings.cpp:467
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
itor second functor(surf, f[1])
std::string sound_button_click
Definition: settings.cpp:58
static std::vector< std::string > get_registered_window_list()
Returns a copy of the list of registered windows.
Definition: settings.cpp:479
unsigned gamemap_width
The size of the map area, if not available equal to the screen size.
Definition: settings.cpp:49
friend std::vector< std::string > & unit_test_registered_window_list()
Definition: test_gui2.cpp:99
Definitions for the interface to Wesnoth Markup Language (WML).
std::string sound_slider_adjust
Definition: settings.cpp:61
Helper struct to signal that get_window_builder failed.
Definition: settings.hpp:142
Special helper class to get the list of registered windows.
Definition: settings.hpp:63
void load_widget_definitions(tgui_definition &gui_definition, const std::string &definition_type, const std::vector< tcontrol_definition_ptr > &definitions)
Loads the definitions of a widget.
Definition: settings.cpp:568
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
unsigned repeat_button_repeat_time
Definition: settings.cpp:56
void register_widget(const std::string &id, std::function< void(tgui_definition &gui_definition, const std::string &definition_type, const config &cfg, const char *key)> functor)
Registers a widgets.
Definition: settings.cpp:558
t_string has_helptip_message
Definition: settings.cpp:63
unsigned gamemap_height
Definition: settings.cpp:50
std::vector< twindow_builder::tresolution >::const_iterator get_window_builder(const std::string &type)
Returns an interator to the requested builder.
Definition: settings.cpp:624
tresolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
Definition: settings.cpp:576
Contains the general settings which have a default.
Definition: settings.cpp:27
unsigned gamemap_x_offset
The offset between the left edge of the screen and the gamemap.
Definition: settings.cpp:47
unsigned popup_show_time
Definition: settings.cpp:53
unsigned screen_width
The screen resolution should be available for all widgets since their drawing method will depend on i...
Definition: settings.cpp:44
std::string sound_toggle_panel_click
Definition: settings.cpp:60
boost::intrusive_ptr< tresolution_definition_ > tresolution_definition_ptr
void load_settings()
Loads the setting for the theme.
Definition: settings.cpp:484
unsigned popup_show_delay
These are copied from the active gui.
Definition: settings.cpp:52
unsigned screen_height
Definition: settings.cpp:45
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
std::string sound_toggle_button_click
Definition: settings.cpp:59
std::vector< ttip > get_tips()
Definition: settings.cpp:67
GLsizei const GLcharARB ** string
Definition: glew.h:4503
unsigned help_show_time
Definition: settings.cpp:54