00001 /* $Id: window_builder.hpp 54216 2012-05-19 08:46:07Z mordante $ */ 00002 /* 00003 Copyright (C) 2008 - 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 #ifndef GUI_AUXILIARY_WINDOW_BUILDER_HPP_INCLUDED 00017 #define GUI_AUXILIARY_WINDOW_BUILDER_HPP_INCLUDED 00018 00019 #include "gui/auxiliary/formula.hpp" 00020 #include "gui/widgets/grid.hpp" 00021 #include "reference_counted_object.hpp" 00022 00023 #include <boost/function.hpp> 00024 00025 #include <string> 00026 #include <vector> 00027 00028 class config; 00029 class CVideo; 00030 00031 namespace gui2 { 00032 00033 class twindow; 00034 00035 /** 00036 * Builds a window. 00037 * 00038 * @param video The frame buffer to draw upon. 00039 * @param type The type id string of the window, this window 00040 * must be registered at startup. 00041 */ 00042 twindow* build(CVideo& video, const std::string& type); 00043 00044 /** Contains the info needed to instantiate a widget. */ 00045 struct tbuilder_widget 00046 : public reference_counted_object 00047 { 00048 public: 00049 explicit tbuilder_widget(const config& cfg); 00050 00051 virtual ~tbuilder_widget() {} 00052 00053 virtual twidget* build() const = 0; 00054 00055 /** Parameters for the widget. */ 00056 std::string id; 00057 std::string linked_group; 00058 00059 #ifndef LOW_MEM 00060 int debug_border_mode; 00061 unsigned debug_border_color; 00062 #endif 00063 }; 00064 00065 typedef boost::intrusive_ptr<tbuilder_widget> tbuilder_widget_ptr; 00066 typedef boost::intrusive_ptr<const tbuilder_widget> const_tbuilder_widget_ptr; 00067 00068 /** 00069 * Registers a widget to be build. 00070 * 00071 * @warning This function runs before @ref main() so needs to be careful 00072 * regarding the static initialization problem. 00073 * 00074 * @param id The id of the widget as used in WML. 00075 * @param functor The functor to create the widget. 00076 */ 00077 void register_builder_widget(const std::string& id 00078 , boost::function<tbuilder_widget_ptr(config)> functor); 00079 00080 /** 00081 * Helper to generate a widget from a WML widget instance. 00082 * 00083 * Mainly used as functor for @ref register_builder_widget. 00084 * 00085 * @param cfg The config with the information to 00086 * instanciate the widget. 00087 * 00088 * @returns A generic widget builder pointer. 00089 */ 00090 template<class T> 00091 tbuilder_widget_ptr build_widget(const config& cfg) 00092 { 00093 return new T(cfg); 00094 } 00095 00096 struct tbuilder_grid 00097 : public tbuilder_widget 00098 { 00099 public: 00100 explicit tbuilder_grid(const config& cfg); 00101 00102 unsigned rows; 00103 unsigned cols; 00104 00105 /** The grow factor for the rows / columns. */ 00106 std::vector<unsigned> row_grow_factor; 00107 std::vector<unsigned> col_grow_factor; 00108 00109 /** The flags per grid cell. */ 00110 std::vector<unsigned> flags; 00111 00112 /** The border size per grid cell. */ 00113 std::vector<unsigned> border_size; 00114 00115 /** The widgets per grid cell. */ 00116 std::vector<tbuilder_widget_ptr> widgets; 00117 00118 tgrid* build() const; 00119 tgrid* build(tgrid* grid) const; 00120 }; 00121 00122 typedef boost::intrusive_ptr<tbuilder_grid> tbuilder_grid_ptr; 00123 typedef boost::intrusive_ptr<const tbuilder_grid> tbuilder_grid_const_ptr; 00124 00125 class twindow_builder 00126 { 00127 public: 00128 00129 twindow_builder() 00130 : resolutions() 00131 , id_() 00132 , description_() 00133 { 00134 } 00135 00136 const std::string& read(const config& cfg); 00137 00138 struct tresolution 00139 { 00140 public: 00141 explicit tresolution(const config& cfg); 00142 00143 unsigned window_width; 00144 unsigned window_height; 00145 00146 bool automatic_placement; 00147 00148 tformula<unsigned> x; 00149 tformula<unsigned> y; 00150 tformula<unsigned> width; 00151 tformula<unsigned> height; 00152 00153 unsigned vertical_placement; 00154 unsigned horizontal_placement; 00155 00156 unsigned maximum_width; 00157 unsigned maximum_height; 00158 00159 bool click_dismiss; 00160 00161 std::string definition; 00162 00163 struct tlinked_group 00164 { 00165 tlinked_group() 00166 : id() 00167 , fixed_width(false) 00168 , fixed_height(false) 00169 { 00170 } 00171 00172 std::string id; 00173 bool fixed_width; 00174 bool fixed_height; 00175 }; 00176 00177 std::vector<tlinked_group> linked_groups; 00178 00179 /** Helper struct to store information about the tips. */ 00180 struct ttip 00181 { 00182 ttip(const config& cfg); 00183 00184 std::string id; 00185 }; 00186 00187 ttip tooltip; 00188 ttip helptip; 00189 00190 tbuilder_grid_ptr grid; 00191 }; 00192 00193 std::vector<tresolution> resolutions; 00194 00195 private: 00196 std::string id_; 00197 std::string description_; 00198 }; 00199 00200 /** 00201 * Builds a window. 00202 */ 00203 twindow *build(CVideo &video, const twindow_builder::tresolution *res); 00204 00205 } // namespace gui2 00206 00207 #endif 00208
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:57 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |