MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pagedcontainer.h
1 //© Copyright 2010 - 2012 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 _uipagedcontainer_h
42 #define _uipagedcontainer_h
43 
44 #include "UI/widget.h"
45 
46 namespace Mezzanine
47 {
48  namespace UI
49  {
50  class PageProvider;
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class WidgetEventArguments
53  /// @headerfile widget.h
54  /// @brief This is the base class for widget specific event arguments.
55  /// @details
56  ///////////////////////////////////////
58  {
59  public:
60  /// @brief The identification of the source firing this event.
62 
63  /// @brief Class constructor.
64  /// @param Name The name of the event being fired.
65  /// @param Source The identification of the widget firing this event.
66  /// @param Child The name of the child that has gained focus.
67  ChildFocusEventArguments(const String& Name, const String& Source, const String& Child) :
68  WidgetEventArguments(Name,Source), ChildName(Child) { }
69  /// @brief Class destructor.
71  };//ChildFocusEventArguments
72 
73  ///////////////////////////////////////////////////////////////////////////////
74  /// @brief This is the base class for containers that have a render area and work area of different sizes.
75  /// @details The central premise of all PagedLayoutContainers is that their render dimensions does not
76  /// accurately express their total dimensions, or "work area" where widgets can be placed. The work area
77  /// of a PagedLayoutContainer can be nagivated via a small selection of specific widgets.
78  ///////////////////////////////////////
80  {
81  public:
82  /// @brief Basic container type for Visible @ref QuadRenderable storage by this class.
83  typedef std::vector<QuadRenderable*> VisibleChildContainer;
84  /// @brief Iterator type for Visible @ref QuadRenderable instances stored by this class.
85  typedef VisibleChildContainer::iterator VisibleChildIterator;
86  /// @brief Const Iterator type for Visible @ref QuadRenderable instances stored by this class.
87  typedef VisibleChildContainer::const_iterator ConstVisibleChildIterator;
88 
89  /// @enum ProviderMode
90  /// @brief An enum describing how the providers for this container are configured and being used.
91  /// @details Depending on the method returning the values, these values can mean slightly different things.
92  /// The documentation provided below describes the meaning when querying the overall configuration first, and
93  /// the second description describes what it means when an individual provider is queried on a given container.
95  {
96  PM_Error = 0, ///< The PageProvider configuration is invalid, or the queried PageProvider isn't in use by the container.
97  PM_Single_X = 1, ///< There is only one PageProvider providing pages for the X axis of this container, or the queried provider is being used only for the X axis by the container.
98  PM_Single_Y = 2, ///< There is only one PageProvider providing pages for the Y axis of this container, or the queried provider is being used only for the Y axis by the container.
99  PM_Single_XY = 3, ///< There is only one PageProvider providing pages for both the X and Y axes of this container, or the queried provider is being used for both the X and Y axes be the container.
100  PM_Dual_XY = 4 ///< There are two different PageProviders each providing pages for their respective axis. This value isn't returned by a provider query.
101  };
102 
103  /// @brief String containing the type name for this class: "PagedContainer".
104  static const String TypeName;
105  /// @brief Event name for when a child of this widget gains focus.
107  protected:
108  /// @internal
109  /// @brief Unified rect storing the size alloted for children of this container.
111  /// @internal
112  /// @brief A container of children that meet the criteria for rendering in this container.
114  /// @internal
115  /// @brief A pointer to the last child widget that was focused by this container.
117  /// @internal
118  /// @brief A pointer to the X axis provider.
120  /// @internal
121  /// @brief A pointer to the Y axis provider.
123 
124  /// @copydoc Renderable::ProtoSerializeImpl(XML::Node&) const
125  virtual void ProtoSerializeImpl(XML::Node& SelfRoot) const;
126  /// @copydoc Renderable::ProtoDeSerializeImpl(const XML::Node&)
127  virtual void ProtoDeSerializeImpl(const XML::Node& SelfRoot);
128  /// @internal
129  /// @brief The container specific logic for updating it's dimensions.
130  virtual void UpdateContainerDimensionsImpl(const Rect& OldSelfRect, const Rect& NewSelfRect) = 0;
131  public:
132  /// @brief Blank constructor.
133  /// @param Parent The parent Screen that created this widget.
134  PagedContainer(Screen* Parent);
135  /// @brief Standard initialization constructor.
136  /// @param RendName The name to be given to this renderable.
137  /// @param Parent The parent Screen that created this widget.
138  PagedContainer(const String& RendName, Screen* Parent);
139  /// @brief Rect constructor.
140  /// @param RendName The name to be given to this renderable.
141  /// @param RendRect The rect describing this widget's transform relative to it's parent.
142  /// @param Parent The parent screen that created this renderable.
143  PagedContainer(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
144  /// @brief Class destructor.
145  virtual ~PagedContainer();
146 
147  ///////////////////////////////////////////////////////////////////////////////
148  // Utility
149 
150  /// @brief Sets the size of this containers work area.
151  /// @note The relative portion of the Unified dimensions passed in are relative to the containers parent, just like the
152  /// containers own dimensions. This can be larger than the containers dimensions, and in fact should be larger to justify
153  /// using this class or more derived child classes.
154  /// @param Area The new size for this containers work area.
155  virtual void SetWorkAreaSize(const UnifiedVec2& Area);
156  /// @brief Gets the size of this containers work area.
157  /// @return Returns a const reference to this containers work area size.
158  virtual const UnifiedVec2& GetWorkAreaSize() const;
159  /// @brief Gets the size of this containers work area in pixels.
160  /// @return Returns a Vector2 containing the actual pixel size of this containers work area.
161  virtual Vector2 GetActualWorkAreaSize() const;
162 
163  /// @copydoc QuadRenderable::UpdateDimensions(const Rect&, const Rect&)
164  virtual void UpdateDimensions(const Rect& OldSelfRect, const Rect& NewSelfRect);
165 
166  /// @brief Gets a pointer to the last focused child widget in this container.
167  /// @return Returns a pointer to the child widget that last gained focus.
168  virtual Widget* GetLastFocusedWidget() const;
169 
170  /// @brief Gets the current provider configuration of this container.
171  /// @return Returns an enum describing the the provider configuration for this container.
172  virtual ProviderMode GetProviderConfig() const;
173  /// @brief Gets the role of the specified PageProvider in this container.
174  /// @param Prov The PageProvider to check this container for.
175  /// @return Returns a ProviderMode enum value representing how the specified PageProvider is providing for this container.
176  virtual ProviderMode GetProviderConfig(const PageProvider* Prov) const;
177 
178  /// @brief Sets the page providers for both axes.
179  /// @param XProv The PageProvider controlling the current horizontal page.
180  /// @param YProv The PageProvider controlling the current vertical page.
181  virtual void SetProviders(PageProvider* XProv, PageProvider* YProv) = 0;
182  /// @brief Sets the PageProvider for the X axis.
183  /// @param XProv The PageProvider controlling the current horizontal page.
184  virtual void SetXProvider(PageProvider* XProv) = 0;
185  /// @brief Sets the PageProvider for the Y axis.
186  /// @param YProv The PageProvider controlling the current vertical page.
187  virtual void SetYProvider(PageProvider* YProv) = 0;
188 
189  /// @brief Gets the PageProvider for the X axis.
190  /// @return Returns a pointer to the PageProvider for the X axis of this container.
191  virtual PageProvider* GetXProvider() const;
192  /// @brief Gets the PageProvider for the Y axis.
193  /// @return Returns a pointer to the PageProvider for the Y axis of this container.
194  virtual PageProvider* GetYProvider() const;
195 
196  /// @brief Unbinds a provider being used by this container.
197  /// @param Prov A pointer to the PageProvider to be unbound if it is used by this container.
198  virtual void UnbindProvider(PageProvider* Prov);
199 
200  ///////////////////////////////////////////////////////////////////////////////
201  // Child Management
202 
203  /// @copydoc QuadRenderable::AddChild(Widget*)
204  virtual void AddChild(Widget* Child);
205  /// @copydoc QuadRenderable::RemoveChild(Widget*)
206  virtual void RemoveChild(Widget* Child);
207  /// @copydoc QuadRenderable::RemoveAllChildren()
208  virtual void RemoveAllChildren();
209 
210  ///////////////////////////////////////////////////////////////////////////////
211  // Serialization
212 
213  /// @brief Convert the PageProvider data of this class to an XML::Node ready for serialization.
214  /// @param SelfRoot The root node containing all the serialized data for this instance.
215  virtual void ProtoSerializePageData(XML::Node& SelfRoot) const;
216  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
217  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
218 
219  /// @brief Take the data stored in an XML Node and overwrite the PageProvider data of this object with it.
220  /// @param SelfRoo tAn XML::Node containing the data to populate this class with.
221  virtual void ProtoDeSerializePageData(const XML::Node& SelfRoot);
222  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
223  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
224 
225  /// @copydoc Renderable::GetSerializableName()
226  static String GetSerializableName();
227 
228  ///////////////////////////////////////////////////////////////////////////////
229  // Internal Event Methods
230 
231  /// @brief Self logic to be executed when focus is given to a child of this widget.
232  /// @param ChildName The name of the child that has gained focus.
233  virtual void _OnChildFocusGained(const String& ChildName);
234 
235  ///////////////////////////////////////////////////////////////////////////////
236  // Internal Methods
237 
238  /// @copydoc EventSubscriber::_NotifyEvent(const EventArguments& Args)
239  virtual void _NotifyEvent(const EventArguments& Args);
240  /// @copydoc QuadRenderable::_AppendRenderDataCascading(ScreenRenderData&)
241  virtual void _AppendRenderDataCascading(ScreenRenderData& RenderData);
242  };//PagedContainer
243  }//UI
244 }//Mezzanine
245 
246 #endif