The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
placer.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 /**
16  * @file
17  * Base class for the placement helper.
18  *
19  * Some items can create new child items and these items are placed in some way
20  * this code contains helpers for the placement by calculating the positions
21  * for the items and the best size for the children.
22  */
23 
24 #ifndef GUI_AUXILIARY_PLACER_HPP_INCLUDED
25 #define GUI_AUXILIARY_PLACER_HPP_INCLUDED
26 
27 #include "global.hpp"
28 #include "utils/make_enum.hpp"
29 
30 namespace gui2
31 {
32 
33 struct tpoint;
34 
35 /**
36  * Base class for the placement helper.
37  *
38  * The normal operation for the usage of the class is:
39  * * Call @ref initialise().
40  * * For every visible child item call @ref add_item() with the wanted size of
41  * the widget.
42  * Once this is done the required size for all children can be retrieved with
43  * @ref get_size(). It is also possible to place all children now. In order to
44  * do so loop again over all children in the same order as @ref add_item() and
45  * call @ref get_origin(). The @p index parameter is an increasing counter.
46  *
47  * @note The origins can only be retrieved after all items are added since the
48  * adding of a later item may influence a previous item. E.g. in a vertical
49  * list with two columns the position of the second column depends on the width
50  * of the first and a later row may have a wider column 1 as an earlier row.
51  */
52 class tplacer_
53 {
54 public:
55  /***** ***** Types. ***** *****/
56 
57  /** The direction the placer should grow towards. */
58  MAKE_ENUM(tgrow_direction,
59  (horizontal, "horizontal")
60  (vertical, "vertical")
61  )
62 
63 
64  /***** ***** Constructor, destructor, assignment. ***** *****/
65 
66 public:
67  /**
68  * Builder function.
69  *
70  * @pre @p parallel_items > 0
71  *
72  * @param grow_direction The direction in which the items will be
73  * added.
74  * @param parallel_items The direction perpendicular towards the grow
75  * direction has a fixed number of items. This
76  * value sets that limit. For a list containing
77  * only horizontally or vertically placed items
78  * the value should be 1.
79  */
80  static tplacer_* build(const tgrow_direction grow_direction,
81  const unsigned parallel_items);
82 
83  virtual ~tplacer_();
84 
85 
86  /***** ***** Operations. ***** *****/
87 
88  /**
89  * Initialises the placer.
90  *
91  * When the placement needs to be calculated the state often needs to be
92  * reset, items are placed, removed or changed visibility causing the old
93  * placement to be invalid.
94  */
95  virtual void initialise() = 0;
96 
97  /**
98  * Adds a item to be placed.
99  *
100  * @param size The required size for the item.
101  */
102  virtual void add_item(const tpoint& size) = 0;
103 
104  /**
105  * Gets the required size of all items.
106  *
107  * @returns The required size.
108  */
109  virtual tpoint get_size() const = 0;
110 
111  /**
112  * Gets the origin for an item.
113  *
114  * @param index The index of the item whose origin to return.
115  * The index is the index of the call to
116  * @ref add_item().
117  *
118  * @returns The origin where to place the widget.
119  */
120  virtual tpoint get_origin(const unsigned index) const = 0;
121 };
122 
123 } // namespace gui2
124 
125 #endif
virtual MAKE_ENUM(tgrow_direction,(horizontal,"horizontal")(vertical,"vertical")) public ~tplacer_()
The direction the placer should grow towards.
Definition: placer.cpp:40
virtual void initialise()=0
Initialises the placer.
twindow * build(CVideo &video, const twindow_builder::tresolution *definition)
Builds a window.
#define MAKE_ENUM(NAME, CONTENT)
Definition: make_enum.hpp:157
Base class for the placement helper.
Definition: placer.hpp:52
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
virtual tpoint get_origin(const unsigned index) const =0
Gets the origin for an item.
GLuint index
Definition: glew.h:1782
virtual void add_item(const tpoint &size)=0
Adds a item to be placed.
Holds a 2D point.
Definition: point.hpp:24
GLsizeiptr size
Definition: glew.h:1649
virtual tpoint get_size() const =0
Gets the required size of all items.
Defines the MAKE_ENUM macro.