settings.hpp

Go to the documentation of this file.
00001 /* $Id: settings.hpp 26800 2008-05-23 18:25:20Z mordante $ */
00002 /*
00003    Copyright (C) 2007 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file setting.hpp
00016 //! This file contains the settings handling of the widget library.
00017 
00018 #ifndef __GUI_WIDGETS_SETTING_HPP_INCLUDED__
00019 #define __GUI_WIDGETS_SETTING_HPP_INCLUDED__
00020 
00021 #include "config.hpp"
00022 #include "gui/widgets/canvas.hpp"
00023 #include "gui/widgets/formula.hpp"
00024 #include "gui/widgets/window_builder.hpp"
00025 #include "tstring.hpp"
00026 
00027 #include <map>
00028 #include <string>
00029 #include <vector>
00030 
00031 namespace gui2 {
00032 
00033 enum twindow_type {
00034     ADDON_CONNECT,           //<! The addon connection dialog.
00035     LANGUAGE_SELECTION,      //<! The language selection dialog.
00036     MP_METHOD_SELECTION,     //<! The dialog which allows you to choose the kind
00037                              //!  mp game the user wants to play.
00038 
00039     DUMMY                    //<! Dummy always the last one.
00040 };
00041 
00042 const std::string& get_id(const twindow_type window_type);
00043 
00044 //! Contains the state info for a resolution.
00045 //! Atm all states are the same so there is no need to use inheritance. If that
00046 //! is needed at some point the containers should contain pointers and we should
00047 //! inherit from reference_counted_object.
00048 struct tstate_definition
00049 {
00050 private:
00051     tstate_definition();
00052 
00053 public:
00054     tstate_definition(const config* cfg);
00055 
00056     bool full_redraw;
00057 
00058     tcanvas canvas;
00059 };
00060 
00061 
00062 //! Base class of a resolution, contains the common keys for a resolution.
00063 struct tresolution_definition_ : public reference_counted_object
00064 {
00065 private:
00066     tresolution_definition_();
00067 public:
00068     tresolution_definition_(const config& cfg);
00069 
00070     unsigned window_width;
00071     unsigned window_height;
00072 
00073     unsigned min_width;
00074     unsigned min_height;
00075 
00076     unsigned default_width;
00077     unsigned default_height;
00078 
00079     unsigned max_width;
00080     unsigned max_height;
00081 
00082     unsigned text_extra_width;
00083     unsigned text_extra_height;
00084     unsigned text_font_size;
00085     int text_font_style;
00086 
00087     std::vector<tstate_definition> state;
00088 };
00089 
00090 struct tcontrol_definition : public reference_counted_object
00091 {
00092 private:
00093     tcontrol_definition();
00094 public:
00095 
00096     tcontrol_definition(const config& cfg);
00097 
00098     template<class T>
00099     void load_resolutions(const config::child_list& resolution_list);
00100 
00101     std::string id;
00102     t_string description;
00103 
00104     std::vector<tresolution_definition_*> resolutions;
00105 
00106 };
00107 
00108 struct tbutton_definition : public tcontrol_definition
00109 {
00110     tbutton_definition(const config& cfg);
00111 
00112     struct tresolution : public tresolution_definition_
00113     {
00114         tresolution(const config& cfg);
00115     };
00116 
00117 };
00118 
00119 struct tlabel_definition : public tcontrol_definition
00120 {
00121 
00122     tlabel_definition(const config& cfg);
00123 
00124     struct tresolution : public tresolution_definition_
00125     {
00126         tresolution(const config& cfg);
00127     };
00128 };
00129 
00130 struct tlistbox_definition : public tcontrol_definition
00131 {
00132 
00133     tlistbox_definition(const config& cfg);
00134 
00135     struct tresolution : public tresolution_definition_
00136     {
00137         tresolution(const config& cfg);
00138 
00139         // NOTE maybe we need the borders...
00140 
00141         tbuilder_grid* scrollbar;
00142 
00143     };
00144 };
00145 
00146 struct tpanel_definition : public tcontrol_definition
00147 {
00148 
00149     tpanel_definition(const config& cfg);
00150 
00151     struct tresolution : public tresolution_definition_
00152     {
00153         tresolution(const config& cfg);
00154 
00155         unsigned top_border;
00156         unsigned bottom_border;
00157 
00158         unsigned left_border;
00159         unsigned right_border;
00160     };
00161 };
00162 
00163 struct tspacer_definition : public tcontrol_definition
00164 {
00165 
00166     tspacer_definition(const config& cfg);
00167 
00168     struct tresolution : public tresolution_definition_
00169     {
00170         tresolution(const config& cfg);
00171     };
00172 };
00173 
00174 struct ttext_box_definition : public tcontrol_definition
00175 {
00176 
00177     ttext_box_definition(const config& cfg);
00178 
00179     struct tresolution : public tresolution_definition_
00180     {
00181         tresolution(const config& cfg);
00182 
00183         tformula<unsigned> text_x_offset;
00184         tformula<unsigned> text_y_offset;
00185     };
00186 
00187 };
00188 
00189 struct ttoggle_button_definition : public tcontrol_definition
00190 {
00191     ttoggle_button_definition(const config& cfg);
00192 
00193     struct tresolution : public tresolution_definition_
00194     {
00195         tresolution(const config& cfg);
00196     };
00197 };
00198 
00199 struct ttooltip_definition : public tcontrol_definition
00200 {
00201     ttooltip_definition(const config& cfg);
00202 
00203     struct tresolution : public tresolution_definition_
00204     {
00205         tresolution(const config& cfg);
00206     };
00207 };
00208 
00209 struct tvertical_scrollbar_definition : public tcontrol_definition
00210 {
00211     tvertical_scrollbar_definition(const config& cfg);
00212 
00213     struct tresolution : public tresolution_definition_
00214     {
00215         tresolution(const config& cfg);
00216 
00217         unsigned minimum_positioner_length;
00218 
00219         unsigned top_offset;
00220         unsigned bottom_offset;
00221     };
00222 };
00223 
00224 struct twindow_definition : public tpanel_definition
00225 {
00226     twindow_definition(const config& cfg);
00227 };
00228 
00229 struct tgui_definition
00230 {
00231     tgui_definition() : 
00232         id(),
00233         description(),
00234         popup_show_delay_(0),
00235         popup_show_time_(0),
00236         help_show_time_(0),
00237         double_click_time_(0)
00238     {
00239     }
00240 
00241     std::string id;
00242     t_string description;
00243 
00244     const std::string& read(const config& cfg);
00245 
00246     //! Activates a gui.
00247     void activate() const;
00248     
00249     typedef std::map <std::string /*control type*/, 
00250         std::map<std::string /*id*/, tcontrol_definition*> > 
00251         tcontrol_definition_map;
00252 
00253     tcontrol_definition_map control_definition;
00254 
00255     std::map<std::string, twindow_definition> windows;
00256 
00257     std::map<std::string, twindow_builder> window_types;
00258 private:
00259     template<class T>
00260     void load_definitions(const std::string& definition_type, 
00261         const config::child_list& definition_list);
00262 
00263     unsigned popup_show_delay_;
00264     unsigned popup_show_time_;
00265     unsigned help_show_time_;
00266     unsigned double_click_time_;
00267 };
00268 
00269     tresolution_definition_* get_control(
00270         const std::string& control_type, const std::string& definition);
00271 
00272     std::vector<twindow_builder::tresolution>::const_iterator 
00273         get_window_builder(const std::string& type);
00274 
00275     //! Loads the setting for the theme.
00276     void load_settings();
00277 
00278 
00279     // This namespace contains the 'global' settings.
00280     namespace settings {
00281         //! The screen resolution should be available for all widgets since their
00282         //! drawing method will depend on it.
00283         extern unsigned screen_width;
00284         extern unsigned screen_height;
00285 
00286         //! These are copied from the active gui.
00287         extern unsigned popup_show_delay;
00288         extern unsigned popup_show_time;
00289         extern unsigned help_show_time;
00290         extern unsigned double_click_time;
00291     }
00292 
00293 } // namespace gui2
00294 
00295 #endif
00296 

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs