The Battle for Wesnoth  1.15.1+dev
matrix.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
18 #include "gui/widgets/pane.hpp"
20 
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 namespace implementation
30 {
31 struct builder_matrix;
32 }
33 
35 {
36 public:
37  state_default();
38 
39  void set_active(const bool active);
40 
41  bool get_active() const;
42 
43  unsigned get_state() const;
44 
45 protected:
46  /**
47  * Possible states of the widget.
48  *
49  * Note the order of the states must be the same as defined in settings.hpp.
50  */
51  enum state_t {
54  };
55 
56 private:
57  /**
58  * Current state of the widget.
59  *
60  * The state of the widget determines what to render and how the widget
61  * reacts to certain 'events'.
62  */
64 };
65 
66 template <class STATE>
67 class control_NEW : public styled_widget, public STATE
68 {
69 public:
71  const std::string& control_type)
72  : styled_widget(builder, control_type)
73 
74  {
75  }
76 
77  /** See @ref styled_widget::set_active. */
78  virtual void set_active(const bool active) override
79  {
80  STATE::set_active(active);
81  }
82 
83  /** See @ref styled_widget::get_active. */
84  virtual bool get_active() const override
85  {
86  return STATE::get_active();
87  }
88 
89  /** See @ref styled_widget::get_state. */
90  virtual unsigned get_state() const override
91  {
92  return STATE::get_state();
93  }
94 };
95 
97 
98 /** The matrix class. */
99 class matrix : public tbase
100 {
101  friend class debug_layout_graph;
102 
103 private:
104  explicit matrix(const implementation::builder_matrix& builder);
105 
106 public:
107  static matrix* build(const implementation::builder_matrix& builder);
108 
109  /***** ***** ***** ***** Item handling. ***** ***** ****** *****/
110 
111  unsigned create_item(const std::map<std::string, string_map>& item_data,
112  const std::map<std::string, std::string>& tags);
113 
114 
115  /***** ***** ***** ***** Inherited operations. ***** ***** ****** *****/
116 
117  /** See @ref widget::place. */
118  virtual void place(const point& origin, const point& size) override;
119 
120  /** See @ref widget::layout_initialize. */
121  virtual void layout_initialize(const bool full_initialization) override;
122 
123  /** See @ref widget::impl_draw_children. */
124  virtual void impl_draw_children(surface& frame_buffer,
125  int x_offset,
126  int y_offset) override;
127 
128  /** See @ref widget::layout_children. */
129  virtual void layout_children() override;
130 
131  /** See @ref widget::child_populate_dirty_list. */
132  virtual void
133  child_populate_dirty_list(window& caller,
134  const std::vector<widget*>& call_stack) override;
135 
136  /** See @ref widget::request_reduce_width. */
137  virtual void request_reduce_width(const unsigned maximum_width) override;
138 
139  /** See @ref widget::find_at. */
140  virtual widget* find_at(const point& coordinate,
141  const bool must_be_active) override;
142 
143  /** See @ref widget::find_at. */
144  virtual const widget* find_at(const point& coordinate,
145  const bool must_be_active) const override;
146 
147  /** See @ref widget::find. */
148  widget* find(const std::string& id, const bool must_be_active) override;
149 
150  /** See @ref widget::find. */
151  const widget* find(const std::string& id,
152  const bool must_be_active) const override;
153 
154  /***** ***** ***** ***** Forwarded to pane_. ***** ***** ****** *****/
155  /**
156  * Sorts the contents of the pane.
157  *
158  * @param compare_functor The functor to use to sort the items.
159  */
160  void sort(const pane::compare_functor_t& compare_functor)
161  {
162  /********************** OUTLINE *******************/
163  pane_->sort(compare_functor);
164  }
165 
166  /**
167  * Filters the contents of the pane.
168  *
169  * if the @p filter_functor returns @c true the item shown, else it's
170  * hidden.
171  *
172  * @param filter_functor The functor to determine whether an item
173  * should be shown or hidden.
174  */
175  void filter(const pane::filter_functor_t& filter_functor)
176  {
177  /********************** OUTLINE *******************/
178  pane_->filter(filter_functor);
179  }
180 
181 private:
182  /** See @ref widget::calculate_best_size. */
183  virtual point calculate_best_size() const override;
184 
185 public:
186  /** See @ref widget::disable_click_dismiss. */
187  bool disable_click_dismiss() const override;
188 
189  /** See @ref widget::create_walker. */
190  virtual iteration::walker_base* create_walker() override;
191 
192  /**
193  * Returns a grid in the pane.
194  *
195  * @param id The id of the item whose grid to return. The
196  * id is the value returned by
197  * @ref create_item().
198  *
199  * @returns The wanted grid.
200  * @retval nullptr The id isn't associated with an item.
201  */
202  grid* get_grid(const unsigned id);
203 
204  /**
205  * Returns a grid in the pane.
206  *
207  * @param id The id of the item whose grid to return. The
208  * id is the value returned by
209  * @ref create_item().
210  *
211  * @returns The wanted grid.
212  * @retval nullptr The id isn't associated with an item.
213  */
214  const grid* get_grid(const unsigned id) const;
215 
216 private:
217  /** The grid containing our children. */
219 
220  /**
221  * Contains the pane used for adding new items to the matrix.
222  *
223  * The pane is owned by a grid in the content layer.
224  */
226 
227 public:
228  /** Static type getter that does not rely on the widget being constructed. */
229  static const std::string& type();
230 
231 private:
232  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
233  virtual const std::string& get_control_type() const override;
234 };
235 
236 // }---------- DEFINITION ---------{
237 
239 {
240 
241  explicit matrix_definition(const config& cfg);
242 
244  {
245  explicit resolution(const config& cfg);
246 
248  };
249 };
250 
251 // }---------- BUILDER -----------{
252 
253 namespace implementation
254 {
255 
257 {
258  explicit builder_matrix(const config& cfg);
259 
261 
262  widget* build() const;
263 
266 
269 
272 
274 };
275 
276 } // namespace implementation
277 
278 // }------------ END --------------
279 
280 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
The matrix class.
Definition: matrix.hpp:99
Base class for all widgets.
Definition: widget.hpp:47
void sort(const pane::compare_functor_t &compare_functor)
Sorts the contents of the pane.
Definition: matrix.hpp:160
grid content_
The grid containing our children.
Definition: matrix.hpp:218
std::function< bool(const item &)> filter_functor_t
Definition: pane.hpp:53
void filter(const pane::filter_functor_t &filter_functor)
Filters the contents of the pane.
Definition: matrix.hpp:175
std::shared_ptr< builder_widget > builder_widget_ptr
Generic file dialog.
Definition: field-fwd.hpp:22
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: matrix.hpp:90
Base container class.
Definition: grid.hpp:30
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
control_NEW(const implementation::builder_styled_widget &builder, const std::string &control_type)
Definition: matrix.hpp:70
The walker abstract base class.
Definition: walker.hpp:26
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: matrix.hpp:78
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
Definition: matrix.hpp:264
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
Definition: matrix.hpp:265
control_NEW< state_default > tbase
Definition: matrix.hpp:96
virtual bool get_active() const override
See styled_widget::get_active.
Definition: matrix.hpp:84
state_t state_
Current state of the widget.
Definition: matrix.hpp:63
window * build(const builder_window::window_resolution *definition)
Builds a window.
Holds a 2D point.
Definition: point.hpp:23
Base class for all visible items.
std::function< bool(const item &, const item &)> compare_functor_t
Definition: pane.hpp:51
scrollbar_mode
The way to handle the showing or hiding of the scrollbar.
builder_widget_ptr builder_main
Definition: matrix.hpp:273
state_t
Possible states of the widget.
Definition: matrix.hpp:51
bool find(E event, F functor)
Tests whether an event handler is available.
pane * pane_
Contains the pane used for adding new items to the matrix.
Definition: matrix.hpp:225
point resolution()
Definition: general.cpp:373
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63
std::shared_ptr< builder_grid > builder_grid_ptr
static std::deque< std::string > call_stack
Definition: function.cpp:39
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.