00001 /* $Id: settings.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2007 - 2012 by Mark de Wever <koraq@xs4all.nl> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 /** 00017 * @file 00018 * This file contains the settings handling of the widget library. 00019 */ 00020 00021 #ifndef GUI_WIDGETS_SETTING_HPP_INCLUDED 00022 #define GUI_WIDGETS_SETTING_HPP_INCLUDED 00023 00024 #include "gui/auxiliary/widget_definition/window.hpp" 00025 00026 #include <boost/function.hpp> 00027 00028 #include <string> 00029 #include <vector> 00030 00031 namespace gui2 { 00032 00033 struct tgui_definition; 00034 class ttip; 00035 00036 /** Do we wish to use the new library or not. */ 00037 extern bool new_widgets; 00038 00039 /** 00040 * Registers a window. 00041 * 00042 * This function registers the available windows defined in WML. All windows 00043 * need to register themselves before @ref gui2::init) is called. 00044 * 00045 * @warning This function runs before @ref main() so needs to be careful 00046 * regarding the static initialization problem. 00047 * 00048 * @note Double registering a window can't hurt, but no way to probe for it, 00049 * this can be added if needed. The same for an unregister function. 00050 * 00051 * @param id The id of the window to register. 00052 */ 00053 void register_window(const std::string& id); 00054 00055 /** 00056 * Special helper class to get the list of registered windows. 00057 * 00058 * This is used in the unit tests, but these implementation details shouldn't 00059 * be used in the normal code. 00060 */ 00061 class tunit_test_access_only 00062 { 00063 friend std::vector<std::string>& unit_test_registered_window_list(); 00064 00065 /** Returns a copy of the list of registered windows. */ 00066 static std::vector<std::string> get_registered_window_list(); 00067 }; 00068 00069 /** 00070 * Registers a widgets. 00071 * 00072 * This function registers the available widgets defined in WML. All widgets 00073 * need to register themselves before @ref gui2::init) is called. 00074 * 00075 * @warning This function runs before @ref main() so needs to be careful 00076 * regarding the static initialization problem. 00077 * 00078 * @param id The id of the widget to register. 00079 * @param functor The function to load the definitions. 00080 */ 00081 void register_widget(const std::string& id 00082 , boost::function<void( 00083 tgui_definition& gui_definition 00084 , const std::string& definition_type 00085 , const config& cfg 00086 , const char *key)> functor); 00087 00088 /** 00089 * Loads the definitions of a widget. 00090 * 00091 * @param gui_definition The gui definition the widget definition 00092 * belongs to. 00093 * @param definition_type The type of the widget whose definitions are 00094 * to be loaded. 00095 * @param definitions The definitions serialized from a config 00096 * object. 00097 */ 00098 void load_widget_definitions( 00099 tgui_definition& gui_definition 00100 , const std::string& definition_type 00101 , const std::vector<tcontrol_definition_ptr>& definitions); 00102 00103 /** 00104 * Loads the definitions of a widget. 00105 * 00106 * This function is templated and kept small so only loads the definitions from 00107 * the config and then lets the real job be done by the @ref 00108 * load_widget_definitions above. 00109 * 00110 * @param gui_definition The gui definition the widget definition 00111 * belongs to. 00112 * @param definition_type The type of the widget whose definitions are 00113 * to be loaded. 00114 * @param config The config to serialiaze the definitions 00115 * from. 00116 * @param key Optional id of the definition to load. 00117 */ 00118 template<class T> 00119 void load_widget_definitions( 00120 tgui_definition& gui_definition 00121 , const std::string& definition_type 00122 , const config& cfg 00123 , const char *key) 00124 { 00125 std::vector<tcontrol_definition_ptr> definitions; 00126 00127 foreach(const config& definition 00128 , cfg.child_range(key ? key : definition_type + "_definition")) { 00129 00130 definitions.push_back(new T(definition)); 00131 } 00132 00133 load_widget_definitions(gui_definition, definition_type, definitions); 00134 } 00135 00136 00137 tresolution_definition_ptr get_control( 00138 const std::string& control_type, const std::string& definition); 00139 00140 /** Helper struct to signal that get_window_builder failed. */ 00141 struct twindow_builder_invalid_id {}; 00142 00143 /** 00144 * Returns an interator to the requested builder. 00145 * 00146 * The builder is determined by the @p type and the current screen 00147 * resolution. 00148 * 00149 * @pre There is a valid builder for @p type at the 00150 * current resolution. 00151 * 00152 * @throw twindow_builder_invalid_id 00153 * When the precondition is violated. 00154 * 00155 * @param type The type of builder window to get. 00156 * 00157 * @returns An iterator to the requested builder. 00158 */ 00159 std::vector<twindow_builder::tresolution>::const_iterator 00160 get_window_builder(const std::string& type); 00161 00162 /** Loads the setting for the theme. */ 00163 void load_settings(); 00164 00165 /** This namespace contains the 'global' settings. */ 00166 namespace settings { 00167 00168 /** 00169 * The screen resolution should be available for all widgets since 00170 * their drawing method will depend on it. 00171 */ 00172 extern unsigned screen_width; 00173 extern unsigned screen_height; 00174 00175 /** 00176 * The size of the map area, if not available equal to the screen 00177 * size. 00178 */ 00179 extern unsigned gamemap_width; 00180 extern unsigned gamemap_height; 00181 00182 /** These are copied from the active gui. */ 00183 extern unsigned popup_show_delay; 00184 extern unsigned popup_show_time; 00185 extern unsigned help_show_time; 00186 extern unsigned double_click_time; 00187 extern unsigned repeat_button_repeat_time; 00188 00189 extern std::string sound_button_click; 00190 extern std::string sound_toggle_button_click; 00191 extern std::string sound_toggle_panel_click; 00192 extern std::string sound_slider_adjust; 00193 00194 extern t_string has_helptip_message; 00195 00196 std::vector<ttip> get_tips(); 00197 } 00198 00199 } // namespace gui2 00200 00201 #endif 00202
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:00 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |