The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
matrix.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 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_WIDGETS_MATRIX_HPP_INCLUDED
16 #define GUI_WIDGETS_MATRIX_HPP_INCLUDED
17 
18 #include "gui/widgets/control.hpp"
19 #include "gui/widgets/pane.hpp"
21 
24 
25 namespace gui2
26 {
27 
28 // ------------ WIDGET -----------{
29 
30 namespace implementation
31 {
32 struct tbuilder_matrix;
33 }
34 
36 {
37 public:
39 
40  void set_active(const bool active);
41 
42  bool get_active() const;
43 
44  unsigned get_state() const;
45 
46 protected:
47  /**
48  * Possible states of the widget.
49  *
50  * Note the order of the states must be the same as defined in settings.hpp.
51  */
52  enum tstate {
56  };
57 
58 private:
59  /**
60  * Current state of the widget.
61  *
62  * The state of the widget determines what to render and how the widget
63  * reacts to certain 'events'.
64  */
66 };
67 
68 template <class STATE>
69 class tcontrol_NEW : public tcontrol, public STATE
70 {
71 public:
73  const std::string& control_type)
74  : tcontrol(builder, STATE::COUNT, control_type)
75 
76  {
77  }
78 
79  /** See @ref tcontrol::set_active. */
80  virtual void set_active(const bool active) override
81  {
82  STATE::set_active(active);
83  }
84 
85  /** See @ref tcontrol::get_active. */
86  virtual bool get_active() const override
87  {
88  return STATE::get_active();
89  }
90 
91  /** See @ref tcontrol::get_state. */
92  virtual unsigned get_state() const override
93  {
94  return STATE::get_state();
95  }
96 };
97 
99 
100 /** The matrix class. */
101 class tmatrix : public tbase
102 {
103  friend class tdebug_layout_graph;
104 
105 private:
106  explicit tmatrix(const implementation::tbuilder_matrix& builder);
107 
108 public:
109  static tmatrix* build(const implementation::tbuilder_matrix& builder);
110 
111  /***** ***** ***** ***** Item handling. ***** ***** ****** *****/
112 
113  unsigned create_item(const std::map<std::string, string_map>& item_data,
114  const std::map<std::string, std::string>& tags);
115 
116 
117  /***** ***** ***** ***** Inherited operations. ***** ***** ****** *****/
118 
119  /** See @ref twidget::place. */
120  virtual void place(const tpoint& origin, const tpoint& size) override;
121 
122  /** See @ref twidget::layout_initialise. */
123  virtual void layout_initialise(const bool full_initialisation) override;
124 
125  /** See @ref twidget::impl_draw_children. */
126  virtual void impl_draw_children(surface& frame_buffer,
127  int x_offset,
128  int y_offset) override;
129 
130  /** See @ref twidget::layout_children. */
131  virtual void layout_children() override;
132 
133  /** See @ref twidget::child_populate_dirty_list. */
134  virtual void
136  const std::vector<twidget*>& call_stack) override;
137 
138  /** See @ref twidget::request_reduce_width. */
139  virtual void request_reduce_width(const unsigned maximum_width) override;
140 
141  /** See @ref twidget::find_at. */
142  virtual twidget* find_at(const tpoint& coordinate,
143  const bool must_be_active) override;
144 
145  /** See @ref twidget::find_at. */
146  virtual const twidget* find_at(const tpoint& coordinate,
147  const bool must_be_active) const override;
148 
149  /** See @ref twidget::find. */
150  twidget* find(const std::string& id, const bool must_be_active) override;
151 
152  /** See @ref twidget::find. */
153  const twidget* find(const std::string& id,
154  const bool must_be_active) const override;
155 
156  /***** ***** ***** ***** Forwarded to pane_. ***** ***** ****** *****/
157  /**
158  * Sorts the contents of the pane.
159  *
160  * @param compare_functor The functor to use to sort the items.
161  */
162  void sort(const tpane::tcompare_functor& compare_functor)
163  {
164  /********************** OUTLINE *******************/
165  pane_->sort(compare_functor);
166  }
167 
168  /**
169  * Filters the contents of the pane.
170  *
171  * if the @p filter_functor returns @c true the item shown, else it's
172  * hidden.
173  *
174  * @param filter_functor The functor to determine whether an item
175  * should be shown or hidden.
176  */
177  void filter(const tpane::tfilter_functor& filter_functor)
178  {
179  /********************** OUTLINE *******************/
180  pane_->filter(filter_functor);
181  }
182 
183 private:
184  /** See @ref twidget::calculate_best_size. */
185  virtual tpoint calculate_best_size() const override;
186 
187 public:
188  /** See @ref twidget::disable_click_dismiss. */
189  bool disable_click_dismiss() const override;
190 
191  /** See @ref twidget::create_walker. */
192  virtual iterator::twalker_* create_walker() override;
193 
194  /**
195  * Returns a grid in the pane.
196  *
197  * @param id The id of the item whose grid to return. The
198  * id is the value returned by
199  * @ref create_item().
200  *
201  * @returns The wanted grid.
202  * @retval nullptr The id isn't associated with an item.
203  */
204  tgrid* grid(const unsigned id);
205 
206  /**
207  * Returns a grid in the pane.
208  *
209  * @param id The id of the item whose grid to return. The
210  * id is the value returned by
211  * @ref create_item().
212  *
213  * @returns The wanted grid.
214  * @retval nullptr The id isn't associated with an item.
215  */
216  const tgrid* grid(const unsigned id) const;
217 
218 private:
219  /** The grid containing our children. */
221 
222  /**
223  * Contains the pane used for adding new items to the matrix.
224  *
225  * The pane is owned by a grid in the content layer.
226  */
228 
229  /** See @ref tcontrol::get_control_type. */
230  virtual const std::string& get_control_type() const override;
231 };
232 
233 // }---------- DEFINITION ---------{
234 
236 {
237 
238  explicit tmatrix_definition(const config& cfg);
239 
241  {
242  explicit tresolution(const config& cfg);
243 
245  };
246 };
247 
248 // }---------- BUILDER -----------{
249 
250 namespace implementation
251 {
252 
254 {
255  explicit tbuilder_matrix(const config& cfg);
256 
258 
259  twidget* build() const;
260 
263 
266 
269 
271 };
272 
273 } // namespace implementation
274 
275 // }------------ END --------------
276 
277 } // namespace gui2
278 
279 #endif
void filter(const tfilter_functor &filter_functor)
Filters the contents of the pane.
Definition: pane.cpp:222
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
Definition: matrix.cpp:134
virtual void layout_children() override
See twidget::layout_children.
Definition: matrix.cpp:122
virtual bool get_active() const override
See tcontrol::get_active.
Definition: matrix.hpp:86
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: matrix.hpp:80
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
Definition: matrix.cpp:111
Base container class.
Definition: grid.hpp:29
std::function< bool(const titem &, const titem &)> tcompare_functor
Definition: pane.hpp:54
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: matrix.cpp:188
tscrollbar_container::tscrollbar_mode vertical_scrollbar_mode
Definition: matrix.hpp:261
tcontrol_NEW(const implementation::tbuilder_control &builder, const std::string &control_type)
Definition: matrix.hpp:72
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
Definition: matrix.cpp:138
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
Definition: matrix.cpp:175
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
Definition: matrix.cpp:168
friend class tdebug_layout_graph
Definition: matrix.hpp:103
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
Definition: matrix.cpp:149
tstate
Possible states of the widget.
Definition: matrix.hpp:52
Base class of a resolution, contains the common keys for a resolution.
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
unsigned get_state() const
Definition: matrix.cpp:55
bool get_active() const
Definition: matrix.cpp:50
virtual twidget * build() const =0
The matrix class.
Definition: matrix.hpp:101
tscrollbar_mode
The way to handle the showing or hiding of the scrollbar.
virtual void impl_draw_children(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_children.
Definition: matrix.cpp:117
std::function< bool(const titem &)> tfilter_functor
Definition: pane.hpp:56
unsigned create_item(const std::map< std::string, string_map > &item_data, const std::map< std::string, std::string > &tags)
Definition: matrix.cpp:98
tmatrix_definition(const config &cfg)
Definition: matrix.cpp:217
tmatrix(const implementation::tbuilder_matrix &builder)
Definition: matrix.cpp:60
tbuilder_matrix(const config &cfg)
Definition: matrix.cpp:276
void sort(const tpane::tcompare_functor &compare_functor)
Sorts the contents of the pane.
Definition: matrix.hpp:162
Holds a 2D point.
Definition: point.hpp:24
void set_active(const bool active)
Definition: matrix.cpp:43
Base class for all visible items.
Definition: control.hpp:34
GLsizeiptr size
Definition: glew.h:1649
tscrollbar_container::tscrollbar_mode horizontal_scrollbar_mode
Definition: matrix.hpp:262
tgrid content_
The grid containing our children.
Definition: matrix.hpp:220
Base class for all widgets.
Definition: widget.hpp:49
tstate state_
Current state of the widget.
Definition: matrix.hpp:65
void filter(const tpane::tfilter_functor &filter_functor)
Filters the contents of the pane.
Definition: matrix.hpp:177
tpane * pane_
Contains the pane used for adding new items to the matrix.
Definition: matrix.hpp:227
The walker abstract base class.
Definition: walker.hpp:27
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: matrix.hpp:92
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Definition: matrix.cpp:104
static tmatrix * build(const implementation::tbuilder_matrix &builder)
Definition: matrix.cpp:92
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
tgrid * grid(const unsigned id)
Returns a grid in the pane.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
virtual iterator::twalker_ * create_walker() override
See twidget::create_walker.
Definition: matrix.cpp:180
Contains the implementation details for lexical_cast and shouldn't be used directly.
tcontrol_NEW< tstate_default > tbase
Definition: matrix.hpp:98
virtual void child_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack) override
See twidget::child_populate_dirty_list.
Definition: matrix.cpp:127
void sort(const tcompare_functor &compare_functor)
Sorts the contents of the pane.
Definition: pane.cpp:215
tbuilder_widget_ptr builder_main
Definition: matrix.hpp:270