Spinning Topp Logo BlackTopp Studios
inc
gridcontainer.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _uigridcontainer_h
42 #define _uigridcontainer_h
43 
44 #include "UI/pagedcontainer.h"
45 
46 namespace Mezzanine
47 {
48  namespace UI
49  {
50  class HorizontalScrollbar;
51  class VerticalScrollbar;
52  class Spinner;
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @brief Simple class used to represent positions or sizes on a grid.
55  /// @details
56  ///////////////////////////////////////
58  {
59  /// @brief The Cell(s) on the X axis.
61  /// @brief The Cell(s) on the Y axis.
63 
64  ///////////////////////////////////////////////////////////////////////////////
65  // Construction and Destruction
66 
67  /// @brief Blank constructor.
68  GridVector2();
69  /// @brief Descriptive constructor.
70  /// @param x The Cell(s) on the X axis.
71  /// @param y The Cell(s) on the Y axis.
72  GridVector2(const Whole x, const Whole y);
73 
74  ///////////////////////////////////////////////////////////////////////////////
75  // Operators
76 
77  /// @brief Equality comparison operator.
78  /// @param Other The other GridVector2 to compare with.
79  /// @return Returns true if both GridVector2s contain the same values, false otherwise.
80  Boole operator==(const GridVector2& Other);
81  /// @brief Inequality comparison operator.
82  /// @param Other The other GridVector2 to compare with.
83  /// @return Returns true if this GridVector2 contains different values as the other GridVector2, false otherwise.
84  Boole operator!=(const GridVector2& Other);
85  };//GridVector2
86 
87  ///////////////////////////////////////////////////////////////////////////////
88  /// @brief Simple rect used to represent a complete transform on a grid.
89  /// @details
90  ///////////////////////////////////////
92  {
93  /// @brief The Cell position of this rect.
95  /// @brief The Cell size of this rect.
97 
98  ///////////////////////////////////////////////////////////////////////////////
99  // Construction and Destruction
100 
101  /// @brief Blank constructor.
102  GridRect();
103  /// @brief Descriptive constructor.
104  /// @param XPos The Cell position on the X axis.
105  /// @param YPos The Cell position on the Y axis.
106  /// @param XSize The number of cells this rect occupies on the X axis.
107  /// @param YSize The number of cells this rect occupies on the Y axis.
108  GridRect(const Whole XPos, const Whole YPos, const Whole XSize, const Whole YSize);
109 
110  ///////////////////////////////////////////////////////////////////////////////
111  // Utility
112 
113  /// @brief Gets the Left cell of this Rect.
114  /// @return Returns the cell position of the Left of this Rect.
115  Whole GetLeftCell() const;
116  /// @brief Gets the Right cell of this Rect.
117  /// @return Returns the cell position of the Right of this Rect.
118  Whole GetRightCell() const;
119  /// @brief Gets the Top cell of this Rect.
120  /// @return Returns the cell position of the Top of this Rect.
121  Whole GetTopCell() const;
122  /// @brief Gets the Bottom cell of this Rect.
123  /// @return Returns the cell position of the Bottom of this Rect.
124  Whole GetBottomCell() const;
125 
126  /// @brief Gets whether or not this GridRect completely envelopes another GridRect.
127  /// @param Other The other GridRect to compare to.
128  /// @return Returns true if the provided GridRect is completely overlapped by this GridRect, false otherwise.
129  Boole Envelopes(const GridRect& Other);
130 
131  ///////////////////////////////////////////////////////////////////////////////
132  // Serialization
133 
134  /// @brief Convert this class to an XML::Node ready for serialization.
135  /// @param ParentNode The point in the XML hierarchy that all this rect should be appended to.
136  void ProtoSerialize(XML::Node& ParentNode) const;
137  /// @brief Take the data stored in an XML Node and overwrite this object with it.
138  /// @param SelfRoot An XML::Node containing the data to populate this class with.
139  void ProtoDeSerialize(const XML::Node& SelfRoot);
140 
141  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
142  /// @return A string containing the name of this class.
143  static String GetSerializableName();
144 
145  ///////////////////////////////////////////////////////////////////////////////
146  // Operators
147 
148  /// @brief Equality comparison operator.
149  /// @param Other The other GridRect to compare with.
150  /// @return Returns true if both GridRects represent the same transform, false otherwise.
151  Boole operator==(const GridRect& Other);
152  /// @brief Inequality comparison operator.
153  /// @param Other The other GridRect to compare with.
154  /// @return Returns true if this GridRect does not represent the same transform as the other GridRect, false otherwise.
155  Boole operator!=(const GridRect& Other);
156  };//GridRect
157 
158  ///////////////////////////////////////////////////////////////////////////////
159  /// @brief This is a container class for placing child objects on a 2 dimensional grid.
160  /// @details This class does not use a LayoutStrategy.
161  ///////////////////////////////////////
163  {
164  public:
165  /// @brief Convenience typedef for a child of this container and it's grid rect.
166  typedef std::pair<Widget*,GridRect> ChildRectPair;
167  /// @brief Container type for storing GridRects in relation to the children they apply to.
168  typedef std::vector< ChildRectPair > ChildRectContainer;
169  /// @brief Iterator type for GridRects in relation to the children they apply to.
170  typedef ChildRectContainer::iterator ChildRectIterator;
171  /// @brief Const Iterator type for GridRects in relation to the children they apply to.
172  typedef ChildRectContainer::const_iterator ConstChildRectIterator;
173 
174  /// @brief String containing the type name for this class: "GricContainer".
175  static const String TypeName;
176  protected:
178  /// @internal
179  /// @brief Container storing pairs of Grid rects and the children they apply to.
180  ChildRectContainer ChildRects;
181  /// @internal
182  /// @brief The size of each cell in this grid.
184  /// @internal
185  /// @brief The amount of space on each side of each dimension of a given cell which will be considered unusable for the child occupying the cell.
187 
188  /// @copydoc Renderable::ProtoSerializeImpl(XML::Node&) const
189  virtual void ProtoSerializeImpl(XML::Node& SelfRoot) const;
190  /// @copydoc Renderable::ProtoDeSerializeImpl(const XML::Node&)
191  virtual void ProtoDeSerializeImpl(const XML::Node& SelfRoot);
192  /// @copydoc PagedContainer::UpdateContainerDimensionsImpl(const Rect&,const Rect&)
193  virtual void UpdateContainerDimensionsImpl(const Rect& OldSelfRect, const Rect& NewSelfRect);
194  public:
195  /// @brief Blank constructor.
196  /// @param Parent The parent Screen that created this widget.
197  GridContainer(Screen* Parent);
198  /// @brief Standard initialization constructor.
199  /// @param RendName The name to be given to this renderable.
200  /// @param Parent The parent Screen that created this widget.
201  GridContainer(const String& RendName, Screen* Parent);
202  /// @brief Rect constructor.
203  /// @param RendName The name to be given to this renderable.
204  /// @param RendRect The rect describing this widget's transform relative to it's parent.
205  /// @param Parent The parent screen that created this renderable.
206  GridContainer(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
207  /// @brief XML constructor.
208  /// @param XMLNode The node of the xml document to construct from.
209  /// @param Parent The screen the created GridContainer will belong to.
210  GridContainer(const XML::Node& XMLNode, Screen* Parent);
211  /// @brief Class destructor.
212  virtual ~GridContainer();
213  //public:
214  ///////////////////////////////////////////////////////////////////////////////
215  // Utility
216 
217  /// @copydoc PagedContainer::UpdateWorkAreaSize()
218  virtual void UpdateWorkAreaSize();
219  /// @copydoc PagedContainer::QuickUpdateWorkAreaSize(const UnifiedVec2&, Boole)
220  virtual void QuickUpdateWorkAreaSize(const UnifiedVec2& ChildSize, Boole Adding);
221 
222  /// @copydoc Widget::GetTypeName() const
223  virtual const String& GetTypeName() const;
224 
225  /// @copydoc PagedContainer::SetProviders(PageProvider*, PageProvider*)
226  virtual void SetProviders(PageProvider* XProv, PageProvider* YProv);
227  /// @copydoc PagedContainer::SetXProvider(PageProvider*)
228  virtual void SetXProvider(PageProvider* XProv);
229  /// @copydoc PagedContainer::SetYProvider(PageProvider*)
230  virtual void SetYProvider(PageProvider* YProv);
231 
232  /// @brief Gets the area available to a child widget when it's placed in a single cell.
233  /// @return Returns a Vector2 containing the size a child widget would have in this container.
234  virtual UnifiedVec2 GetCellClientArea() const;
235 
236  ///////////////////////////////////////////////////////////////////////////////
237  // GridContainer Properties
238 
239  /// @brief Convenience method that will set the cell size of this grid via the desired number of cells within the viewing area on each axis.
240  /// @param X The number of desired cells in the view area on the X axis.
241  /// @param Y The number of desired cells in the view area on the Y axis.
242  virtual void SetCellSize(const Whole X, const Whole Y);
243  /// @brief Sets the Unified size of a single cell in this container.
244  /// @note Padding still has to be taken into effect after this value is calculated. So depending on the amount of
245  /// padding to be applied, likely this won't be the full size available to a child occupying a cell. @n @n
246  /// Relative portion of the cell size is relative to this containers view size.
247  /// @param Size A @ref UnifiedVec2 containing the size a single cell is to be given.
248  virtual void SetCellSize(const UnifiedVec2& Size);
249  /// @brief Gets the Unified size of a single cell in this container.
250  /// @return Returns a @ref UnifiedVec2 containing the size of each cell in the grid.
251  virtual const UnifiedVec2& GetCellSize() const;
252  /// @brief Sets the Unified padding to be applied on each axis to each cell in this grid.
253  /// @note The padding for each axis is the total for that axis. So the actual padding applied to each edge is (padding * 0.5).
254  /// @param Padding A @ref UnifiedVec2 containing the amount of padding to be applied on each axis for each cell.
255  virtual void SetCellPadding(const UnifiedVec2& Padding);
256  /// @brief Gets the Unified padding to be applied on each axis to each cell in this grid.
257  /// @return Returns a @ref UnifiedVec2 containing the amount of padding to be applied to each cell in the grid.
258  virtual const UnifiedVec2& GetCellPadding() const;
259 
260  ///////////////////////////////////////////////////////////////////////////////
261  // GridContainer Configuration
262 
263  /// @brief Gets the total used size of the Grid based on the current children.
264  /// @return Returns a GridVector2 containing the number of cells in this grid on each axis.
265  virtual GridVector2 GetGridSize() const;
266 
267  /// @brief Sets the grid transform of a child in this container.
268  /// @param Child A pointer to the child that is having it's grid transform updated.
269  /// @param ChildTrans The grid transform to be given to the child.
270  /// @return Returns true if a previous entry was updated, false if a new grid rect entry was inserted.
271  virtual Boole SetChildGridRect(Widget* Child, const GridRect& ChildTrans);
272  /// @brief Gets the grid transform of a child in this container.
273  /// @param Child A pointer to the child to retrieve the grid transform of.
274  /// @return Returns a grid rect representing the specified childs transform on this grid, or an empty rect if the child has no rect for this container.
275  virtual GridRect GetChildGridRect(Widget* Child) const;
276  /// @brief Removes the grid transform of a child from this container.
277  /// @warning Use this method with extreme caution. Removing a childs grid rect from this container can cause it to become invisible.
278  /// @param Child A pointer to the child that is having it's grid transform removed.
279  /// @return Returns true if the grid transform was successfully removed, false if the child had no grid rect in this container.
280  virtual Boole RemoveChildGridRect(Widget* Child);
281 
282  ///////////////////////////////////////////////////////////////////////////////
283  // Child Management
284 
285  /// @copydoc QuadRenderable::AddChild(Widget*)
286  /// @param GridTransform The position and size on the grid this child is to be given.
287  virtual void AddChild(Widget* Child, const GridRect& GridTransform);
288  /// @copydoc QuadRenderable::AddChild(Widget*,const UInt16)
289  /// @param GridTransform The position and size on the grid this child is to be given.
290  virtual void AddChild(Widget* Child, const UInt16 ZOrder, const GridRect& GridTransform);
291  /// @copydoc QuadRenderable::RemoveChild(Widget*)
292  virtual void RemoveChild(Widget* ToBeRemoved);
293  /// @copydoc QuadRenderable::RemoveAllChildren()
294  virtual void RemoveAllChildren();
295  /// @copydoc QuadRenderable::DestroyChild(Widget*)
296  virtual void DestroyChild(Widget* ToBeDestroyed);
297  /// @copydoc QuadRenderable::DestroyAllChildren()
298  virtual void DestroyAllChildren();
299 
300  ///////////////////////////////////////////////////////////////////////////////
301  // Serialization
302 
303  /// @brief Convert the GridRects data of this class to an XML::Node ready for serialization.
304  /// @param SelfRoot The root node containing all the serialized data for this instance.
305  virtual void ProtoSerializeGridRects(XML::Node& SelfRoot) const;
306  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
307  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
308 
309  /// @brief Take the data stored in an XML Node and overwrite the GridRects data of this object with it.
310  /// @param SelfRoot An XML::Node containing the data to populate this class with.
311  virtual void ProtoDeSerializeGridRects(const XML::Node& SelfRoot);
312  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
313  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
314 
315  /// @copydoc Renderable::GetSerializableName()
316  static String GetSerializableName();
317 
318  ///////////////////////////////////////////////////////////////////////////////
319  // Internal Methods
320  };//GridContainer
321 
322  ///////////////////////////////////////////////////////////////////////////////
323  /// @brief This is the factory implementation for GridContainer widgets.
324  /// @details
325  ///////////////////////////////////////
327  {
328  public:
329  /// @brief Class constructor.
331  /// @brief Class destructor.
332  virtual ~GridContainerFactory() { }
333 
334  /// @copydoc WidgetFactory::GetWidgetTypeName() const
335  virtual String GetWidgetTypeName() const;
336 
337  /// @brief Creates a new GridContainer.
338  /// @param RendName The name to be given to the created GridContainer.
339  /// @param Parent The screen the created GridContainer will belong to.
340  /// @return Returns a pointer to the created GridContainer.
341  virtual GridContainer* CreateGridContainer(const String& RendName, Screen* Parent);
342  /// @brief Creates a new GridContainer.
343  /// @param RendName The name to be given to the created GridContainer.
344  /// @param RendRect The dimensions that will be assigned to the created GridContainer.
345  /// @param Parent The screen the created GridContainer will belong to.
346  /// @return Returns a pointer to the created GridContainer.
347  virtual GridContainer* CreateGridContainer(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
348  /// @brief Creates a new GridContainer.
349  /// @param XMLNode The node of the xml document to construct from.
350  /// @param Parent The screen the created GridContainer will belong to.
351  /// @return Returns a pointer to the created GridContainer.
352  virtual GridContainer* CreateGridContainer(const XML::Node& XMLNode, Screen* Parent);
353 
354  /// @copydoc WidgetFactory::CreateWidget(Screen*)
355  virtual Widget* CreateWidget(Screen* Parent);
356  /// @copydoc WidgetFactory::CreateWidget(const String&, const NameValuePairMap&, Screen*)
357  virtual Widget* CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent);
358  /// @copydoc WidgetFactory::CreateWidget(const String&, const UnifiedRect&, const NameValuePairMap&, Screen*)
359  virtual Widget* CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent);
360  /// @copydoc WidgetFactory::CreateWidget(const XML::Node&, Screen*)
361  virtual Widget* CreateWidget(const XML::Node& XMLNode, Screen* Parent);
362  /// @copydoc WidgetFactory::DestroyWidget(Widget*)
363  virtual void DestroyWidget(Widget* ToBeDestroyed);
364  };//GridContainerFactory
365  }//UI
366 }//Mezzanine
367 
368 #endif
This is the base class for containers that have a render area and work area of different sizes...
GridVector2 Size
The Cell size of this rect.
Definition: gridcontainer.h:96
static const String TypeName
String containing the type name for this class: "GricContainer".
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This is the factory implementation for GridContainer widgets.
This is a container class for placing child objects on a 2 dimensional grid.
ChildRectContainer::iterator ChildRectIterator
Iterator type for GridRects in relation to the children they apply to.
GridVector2 Position
The Cell position of this rect.
Definition: gridcontainer.h:94
Simple rect used to represent a complete transform on a grid.
Definition: gridcontainer.h:91
ChildRectContainer ChildRects
Container storing pairs of Grid rects and the children they apply to.
This class represents a box shaped area on the screen.
Definition: rect.h:55
Whole Y
The Cell(s) on the Y axis.
Definition: gridcontainer.h:62
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
ChildRectContainer::const_iterator ConstChildRectIterator
Const Iterator type for GridRects in relation to the children they apply to.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is the base class for all widgets.
Definition: widget.h:126
GridContainerFactory()
Class constructor.
UnifiedVec2 CellSize
The size of each cell in this grid.
Simple class used to represent positions or sizes on a grid.
Definition: gridcontainer.h:57
UnifiedVec2 CellPadding
The amount of space on each side of each dimension of a given cell which will be considered unusable ...
virtual void AddChild(Widget *Child)
Adds a Widget to this as a child of this quad.
std::pair< Widget *, GridRect > ChildRectPair
Convenience typedef for a child of this container and it's grid rect.
virtual ~GridContainerFactory()
Class destructor.
This is the base class for interpretting widget values to page positions.
Definition: pageprovider.h:55
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
This class represents a point in 2D space using UnifiedDim's.
Definition: unifieddim.h:306
Whole X
The Cell(s) on the X axis.
Definition: gridcontainer.h:60
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:209
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
std::vector< ChildRectPair > ChildRectContainer
Container type for storing GridRects in relation to the children they apply to.
This is a base class for factories that construct the widgets available to the UI subsystem...
Definition: widgetfactory.h:61