The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
window_builder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 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 #ifndef GUI_AUXILIARY_WINDOW_BUILDER_HPP_INCLUDED
16 #define GUI_AUXILIARY_WINDOW_BUILDER_HPP_INCLUDED
17 
19 #include "gui/widgets/grid.hpp"
21 
22 #include "utils/functional.hpp"
23 
24 class config;
25 class CVideo;
26 
27 namespace gui2
28 {
29 
30 class twindow;
31 
32 /**
33  * Builds a window.
34  *
35  * @param video The frame buffer to draw upon.
36  * @param type The type id string of the window, this window
37  * must be registered at startup.
38  */
39 twindow* build(CVideo& video, const std::string& type);
40 
41 /** Contains the info needed to instantiate a widget. */
43 {
44 public:
45  /**
46  * The replacements type is used to define replacement types.
47  *
48  * Certain widgets need to build a part of themselves upon instantiation
49  * but at the time of the definition it's not yet known what exactly. By
50  * using and `[instance]' widget this decision can be postponed until
51  * instantiation.
52  */
53  typedef std::map<std::string, boost::intrusive_ptr<tbuilder_widget> >
55 
56  explicit tbuilder_widget(const config& cfg);
57 
58  virtual ~tbuilder_widget()
59  {
60  }
61 
62  virtual twidget* build() const = 0;
63 
64  virtual twidget* build(const treplacements& replacements) const = 0;
65 
66  /** Parameters for the widget. */
69 
70 #ifndef LOW_MEM
73 #endif
74 };
75 
78 
79 /**
80  * Registers a widget to be build.
81  *
82  * @warning This function runs before @ref main() so needs to be careful
83  * regarding the static initialization problem.
84  *
85  * @param id The id of the widget as used in WML.
86  * @param functor The functor to create the widget.
87  */
88 void
90  std::function<tbuilder_widget_ptr(config)> functor);
91 
92 
93 /**
94  * Create a widget builder.
95  *
96  * This object holds the instance builder for a single widget.
97  *
98  * @param cfg The config object holding the information
99  * regarding the widget instance.
100  *
101  * @returns The builder for the widget instance.
102  */
103 tbuilder_widget_ptr create_builder_widget(const config& cfg);
104 
105 /**
106  * Helper to generate a widget from a WML widget instance.
107  *
108  * Mainly used as functor for @ref register_builder_widget.
109  *
110  * @param cfg The config with the information to
111  * Instantiate the widget.
112  *
113  * @returns A generic widget builder pointer.
114  */
115 template <class T>
116 tbuilder_widget_ptr build_widget(const config& cfg)
117 {
118  return new T(cfg);
119 }
120 
122 {
123 public:
124  explicit tbuilder_grid(const config& cfg);
125 
126  unsigned rows;
127  unsigned cols;
128 
129  /** The grow factor for the rows / columns. */
130  std::vector<unsigned> row_grow_factor;
131  std::vector<unsigned> col_grow_factor;
132 
133  /** The flags per grid cell. */
134  std::vector<unsigned> flags;
135 
136  /** The border size per grid cell. */
137  std::vector<unsigned> border_size;
138 
139  /** The widgets per grid cell. */
140  std::vector<tbuilder_widget_ptr> widgets;
141 
142  tgrid* build() const;
143  twidget* build(const treplacements& replacements) const;
144 
145 
146  tgrid* build(tgrid* grid) const;
147  void build(tgrid& grid, const treplacements& replacements) const;
148 };
149 
152 
154 {
155 public:
157  {
158  }
159 
160  const std::string& read(const config& cfg);
161 
162  struct tresolution
163  {
164  public:
165  explicit tresolution(const config& cfg);
166 
167  unsigned window_width;
168  unsigned window_height;
169 
171 
177 
179 
182 
183  unsigned maximum_width;
184  unsigned maximum_height;
185 
187 
189 
191  {
192  tlinked_group() : id(), fixed_width(false), fixed_height(false)
193  {
194  }
195 
199  };
200 
201  std::vector<tlinked_group> linked_groups;
202 
203  /** Helper struct to store information about the tips. */
204  struct ttip
205  {
206  ttip(const config& cfg, const std::string& tagname);
207 
209  };
210 
213 
214  tbuilder_grid_ptr grid;
215  };
216 
217  std::vector<tresolution> resolutions;
218 
219 private:
222 };
223 
224 /**
225  * Builds a window.
226  */
228 
229 } // namespace gui2
230 
231 #endif
std::vector< unsigned > col_grow_factor
boost::intrusive_ptr< const tbuilder_grid > tbuilder_grid_const_ptr
twindow * build(CVideo &video, const twindow_builder::tresolution *definition)
Builds a window.
Contains the info needed to instantiate a widget.
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
Definition: video.hpp:58
itor second functor(surf, f[1])
Base container class.
Definition: grid.hpp:29
std::vector< tbuilder_widget_ptr > widgets
The widgets per grid cell.
std::vector< unsigned > row_grow_factor
The grow factor for the rows / columns.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
std::vector< unsigned > flags
The flags per grid cell.
const std::string & read(const config &cfg)
virtual twidget * build() const =0
std::vector< tresolution > resolutions
ttip(const config &cfg, const std::string &tagname)
tbuilder_grid(const config &cfg)
GLuint res
Definition: glew.h:9258
std::string id
Parameters for the widget.
boost::intrusive_ptr< const tbuilder_widget > const_tbuilder_widget_ptr
Helper struct to store information about the tips.
std::vector< unsigned > border_size
The border size per grid cell.
tbuilder_widget_ptr create_builder_widget(const config &cfg)
Create a widget builder.
void register_builder_widget(const std::string &id, std::function< tbuilder_widget_ptr(config)> functor)
Registers a widget to be build.
tbuilder_widget_ptr build_widget(const config &cfg)
Helper to generate a widget from a WML widget instance.
tbuilder_widget(const config &cfg)
boost::intrusive_ptr< tbuilder_widget > tbuilder_widget_ptr
boost::intrusive_ptr< tbuilder_grid > tbuilder_grid_ptr
std::vector< tlinked_group > linked_groups
Base class for all widgets.
Definition: widget.hpp:49
std::map< std::string, boost::intrusive_ptr< tbuilder_widget > > treplacements
The replacements type is used to define replacement types.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
game_logic::function_symbol_table functions
GLsizei const GLcharARB ** string
Definition: glew.h:4503
tgrid * build() const