MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
layoutstrategy.h
1 //© Copyright 2010 - 2013 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 #ifndef _uilayoutstrategy_h
41 #define _uilayoutstrategy_h
42 
43 #include "UI/rect.h"
44 
45 namespace Mezzanine
46 {
47  namespace UI
48  {
49  class Widget;
50  class QuadRenderable;
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @brief This is a base class for the algorithms used by QuadRenderables to determine how they should update their dimensions.
53  /// @details This class has default and implementations for the algorithms that handle the sizing, positioning, as well as how and when
54  /// those methods are called. These methods can be overridden or expanded upon as neccessary to achieve any specific effect a particular
55  /// @ref Widget or @ref QuadRenderable may need. @n @n
56  /// It is important to note that the base LayoutStrategy class does not contain any support for expanding widgets that use the "SR_Fill_Available"
57  /// size rule.
58  ///////////////////////////////////////
60  {
61  public:
62  /// @brief Basic container type for @ref QuadRenderable storage by this class.
63  typedef std::list<Widget*> ChildContainer;
64  /// @brief Iterator type for @ref QuadRenderable instances stored by this class.
65  typedef ChildContainer::iterator ChildIterator;
66  /// @brief Const Iterator type for @ref QuadRenderable instances stored by this class.
67  typedef ChildContainer::const_iterator ConstChildIterator;
68 
69  ///////////////////////////////////////////////////////////////////////////////
70  // Construction and Destruction
71 
72  /// @brief Class constructor.
74  /// @brief Class destructor.
75  virtual ~LayoutStrategy();
76 
77  ///////////////////////////////////////////////////////////////////////////////
78  // Primary Methods
79 
80  /// @brief Updates the dimensions of a collection of QuadRenderables
81  /// @param OldSelfRect The pre-update dimensions of the calling quad.
82  /// @param NewSelfRect The post-update dimensions of the calling quad.
83  /// @param ChildQuads A container of all the Quads to be updated by this strategy.
84  virtual void Layout(const Rect& OldSelfRect, const Rect& NewSelfRect, const ChildContainer& ChildQuads);
85 
86  ///////////////////////////////////////////////////////////////////////////////
87  // Sub-task Methods
88 
89  /// @brief Handles the positioning of a child that needs it's dimensions updated.
90  /// @param OldSelfRect The previous dimensions of the calling quad prior to it's dimensions being updated.
91  /// @param NewSelfRect The updated and current dimensions of the calling quad.
92  /// @param NewChildSize The post-update size of the child being updated.
93  /// @param Child The child to update.
94  /// @return Returns the childs updated position.
95  virtual Vector2 HandleChildPositioning(const Rect& OldSelfRect, const Rect& NewSelfRect, const Vector2& NewChildSize, QuadRenderable* Child);
96  /// @brief Handles the positioning of a child on the X axis.
97  /// @param OldSelfRect The previous dimensions of the calling quad prior to it's dimensions being updated.
98  /// @param NewSelfRect The updated and current dimensions of the calling quad.
99  /// @param NewChildSize The post-update size of the child being updated.
100  /// @param Child The child to update.
101  /// @return Returns the childs updated position on the X axis.
102  virtual Real HandleChildHorizontalPositioning(const Rect& OldSelfRect, const Rect& NewSelfRect, const Vector2& NewChildSize, QuadRenderable* Child);
103  /// @brief Handles the positioning of a child on the Y axis.
104  /// @param OldSelfRect The previous dimensions of the calling quad prior to it's dimensions being updated.
105  /// @param NewSelfRect The updated and current dimensions of the calling quad.
106  /// @param NewChildSize The post-update size of the child being updated.
107  /// @param Child The child to update.
108  /// @return Returns the childs updated position on the Y axis.
109  virtual Real HandleChildVerticalPositioning(const Rect& OldSelfRect, const Rect& NewSelfRect, const Vector2& NewChildSize, QuadRenderable* Child);
110  /// @brief Handles the sizing of a child that needs it's dimensions updated.
111  /// @param OldSelfRect The previous dimensions of the calling quad prior to it's dimensions being updated.
112  /// @param NewSelfRect The updated and current dimensions of the calling quad.
113  /// @param Child The child to update.
114  /// @return Returns the childs updated size.
115  virtual Vector2 HandleChildSizing(const Rect& OldSelfRect, const Rect& NewSelfRect, QuadRenderable* Child);
116  /// @brief Handles the sizing of a child on the X axis.
117  /// @param OldSelfRect The previous dimensions of the calling quad prior to it's dimensions being updated.
118  /// @param NewSelfRect The updated and current dimensions of the calling quad.
119  /// @param PrevAxisResult The result of the previous axis, in case the settings require it.
120  /// @param Child The child to update.
121  /// @return Returns the childs updated size on the X axis.
122  virtual Real HandleChildHorizontalSizing(const Rect& OldSelfRect, const Rect& NewSelfRect, const Real PrevAxisResult, QuadRenderable* Child);
123  /// @brief Handles the sizing of a child on the Y axis.
124  /// @param OldSelfRect The previous dimensions of the calling quad prior to it's dimensions being updated.
125  /// @param NewSelfRect The updated and current dimensions of the calling quad.
126  /// @param PrevAxisResult The result of the previous axis, in case the settings require it.
127  /// @param Child The child to update.
128  /// @return Returns the childs updated size on the Y axis.
129  virtual Real HandleChildVerticalSizing(const Rect& OldSelfRect, const Rect& NewSelfRect, const Real PrevAxisResult, QuadRenderable* Child);
130  /// @brief Preserves a child's aspect ratio if it is configured to do so.
131  /// @param OldChildSize The previous size of the child prior to the dimension update.
132  /// @param NewChildSize The updated and current dimensions of the calling quad.
133  /// @param Child The child to update.
134  virtual void CheckChildAspectRatio(const Vector2& OldChildSize, Vector2& NewChildSize, QuadRenderable* Child);
135  /// @brief Clamps the updated size to the set minimum size for the child quad.
136  /// @param NewSelfRect The updated and current dimensions of the calling quad.
137  /// @param NewChildSize The updated size to clamp to the set minimum size for the child.
138  /// @param Child The child to update.
139  virtual void ClampChildToMinSize(const Rect& NewSelfRect, Vector2& NewChildSize, QuadRenderable* Child);
140  /// @brief Clamps the updated size to the set maximum size for the child quad.
141  /// @param NewSelfRect The updated and current dimensions of the calling quad.
142  /// @param NewChildSize The updated size to clamp to the set maximum size for the child.
143  /// @param Child The child to update.
144  virtual void ClampChildToMaxSize(const Rect& NewSelfRect, Vector2& NewChildSize, QuadRenderable* Child);
145  };//LayoutStrategy
146  }//UI
147 }//Mezzanine
148 
149 #endif