Spinning Topp Logo BlackTopp Studios
inc
pagedcontainer.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 _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  /// @brief This is the EventArguments class for when a child of a paged container is selected.
53  /// @details
54  ///////////////////////////////////////
56  {
57  public:
58  ///////////////////////////////////////////////////////////////////////////////
59  // Public Data Members
60 
61  /// @brief The identification of the source firing this event.
63  /// @brief Boole storing whether or not the named child is gaining or losing focus.
64  const Boole Selected;
65 
66  ///////////////////////////////////////////////////////////////////////////////
67  // Construction and Destruction
68 
69  /// @brief Class constructor.
70  /// @param Name The name of the event being fired.
71  /// @param Source The identification of the widget firing this event.
72  /// @param Child The name of the child that has gained focus.
73  /// @param Select True if the child is becoming the current selection in it's parent container, or false if it is losing the current selection in it's parent container.
74  ChildSelectedArguments(const String& Name, const String& Source, const String& Child, const Boole Select) :
75  WidgetEventArguments(Name,Source), ChildName(Child), Selected(Select) { }
76  /// @brief Class destructor.
78 
79  ///////////////////////////////////////////////////////////////////////////////
80  // CountedPtr Functionality
81 
82  /// @copydoc EventArguments::GetMostDerived()
84  { return this; }
85  };//ChildSelectedArguments
86  }//UI
87 
88  ///////////////////////////////////////////////////////////////////////////////
89  /// @brief This is a metaprogramming traits class used by ChildFocusEventArguments.
90  /// @details This is need for an intrusive CountedPtr implementation. Should a working external reference count be made this
91  /// could be dropped in favor of a leaner implementation.
92  ///////////////////////////////////////
93  template <>
94  class ReferenceCountTraits<UI::ChildSelectedArguments>
95  {
96  public:
97  /// @brief Typedef communicating the reference count type to be used.
99 
100  /// @brief Method responsible for creating a reference count for a CountedPtr of the templated type.
101  /// @param Target A pointer to the target class that is to be reference counted.
102  /// @return Returns a pointer to a new reference counter for the templated type.
103  static RefCountType* ConstructionPointer(RefCountType* Target)
104  { return Target; }
105 
106  /// @brief Enum used to decide the type of casting to be used by a reference counter of the templated type.
107  enum { IsCastable = CastStatic };
108  };//ReferenceCountTraits<ChildSelectedArguments>
109 
110  namespace UI
111  {
112  /// @brief Convenience typedef for passing around ChildSelectedArguments.
114 
115  ///////////////////////////////////////////////////////////////////////////////
116  /// @brief This is the base class for containers that have a render area and work area of different sizes.
117  /// @details The central premise of all PagedLayoutContainers is that their render dimensions does not
118  /// accurately express their total dimensions, or "work area" where widgets can be placed. The work area
119  /// of a PagedLayoutContainer can be nagivated via a small selection of specific widgets.
120  ///////////////////////////////////////
122  {
123  public:
124  /// @brief Basic container type for Visible @ref Widget storage by this class.
125  typedef std::vector<Widget*> VisibleChildContainer;
126  /// @brief Iterator type for Visible @ref Widget instances stored by this class.
127  typedef VisibleChildContainer::iterator VisibleChildIterator;
128  /// @brief Const Iterator type for Visible @ref Widget instances stored by this class.
129  typedef VisibleChildContainer::const_iterator ConstVisibleChildIterator;
130 
131  /// @brief An enum describing how the providers for this container are configured and being used.
132  /// @details Depending on the method returning the values, these values can mean slightly different things.
133  /// The documentation provided below describes the meaning when querying the overall configuration first, and
134  /// the second description describes what it means when an individual provider is queried on a given container.
136  {
137  PM_Error = 0, ///< The PageProvider configuration is invalid, or the queried PageProvider isn't in use by the container.
138  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.
139  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.
140  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.
141  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.
142  };
143 
144  /// @brief String containing the type name for this class: "PagedContainer".
145  static const String TypeName;
146  /// @brief Event name for when a child of this widget gets selected.
148  protected:
149  /// @internal
150  /// @brief A container of children that meet the criteria for rendering in this container.
151  VisibleChildContainer VisibleChildren;
152  /// @internal
153  /// @brief Vector2 storing the size for all pages of this container.
155  /// @internal
156  /// @brief A pointer to the last child widget that was selected within this container.
158  /// @internal
159  /// @brief A pointer to the X axis provider.
161  /// @internal
162  /// @brief A pointer to the Y axis provider.
164 
165  /// @copydoc Renderable::ProtoSerializeImpl(XML::Node&) const
166  virtual void ProtoSerializeImpl(XML::Node& SelfRoot) const;
167  /// @copydoc Renderable::ProtoDeSerializeImpl(const XML::Node&)
168  virtual void ProtoDeSerializeImpl(const XML::Node& SelfRoot);
169  /// @copydoc Widget::HandleChildStateChangeImpl(Widget*,const UInt32&,const UInt32&)
170  virtual void HandleChildStateChangeImpl(Widget* Child, const UInt32& OldState, const UInt32& NewState);
171  /// @internal
172  /// @brief The container specific logic for updating it's dimensions.
173  /// @param OldSelfRect The pre-update size of this widget.
174  /// @param NewSelfRect The post-update size of this widget.
175  virtual void UpdateContainerDimensionsImpl(const Rect& OldSelfRect, const Rect& NewSelfRect) = 0;
176  public:
177  /// @brief Blank constructor.
178  /// @param Parent The parent Screen that created this widget.
179  PagedContainer(Screen* Parent);
180  /// @brief Standard initialization constructor.
181  /// @param RendName The name to be given to this renderable.
182  /// @param Parent The parent Screen that created this widget.
183  PagedContainer(const String& RendName, Screen* Parent);
184  /// @brief Rect constructor.
185  /// @param RendName The name to be given to this renderable.
186  /// @param RendRect The rect describing this widget's transform relative to it's parent.
187  /// @param Parent The parent screen that created this renderable.
188  PagedContainer(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
189  /// @brief Class destructor.
190  virtual ~PagedContainer();
191 
192  ///////////////////////////////////////////////////////////////////////////////
193  // Utility
194 
195  /// @brief Checks the size of every child in this container and updates the work area to match the size needed.
196  /// @note The work area size is automatically updated when a child is added or removed from a container. You should
197  /// only need to call this method manually if a childs size isn't determined yet when it is added to the container.
198  virtual void UpdateWorkAreaSize() = 0;
199  /// @brief Quickly updates the work area size based on a single childs' dimensions.
200  /// @note The work area size is automatically updated when a child is added or removed from a container. You should
201  /// only need to call this method manually if a childs size isn't determined yet when it is added to the container.
202  /// @param ChildSize The Unified dimensions describing the childs size.
203  /// @param Adding Should be true if the child in question is being added to the container, false if it is being removed.
204  virtual void QuickUpdateWorkAreaSize(const UnifiedVec2& ChildSize, Boole Adding) = 0;
205  /// @brief Gets the size of this containers work area.
206  /// @return Returns a const reference to a Vector2 containing this containers work area size in pixels.
207  virtual const Vector2& GetWorkAreaSize() const;
208 
209  /// @copydoc QuadRenderable::UpdateDimensions(const Rect&, const Rect&)
210  virtual void UpdateDimensions(const Rect& OldSelfRect, const Rect& NewSelfRect);
211  /// @brief Forces an update of the visible children in this container.
212  virtual void UpdateVisibleChildren();
213 
214  /// @brief Gets a pointer to the last selected child widget in this container.
215  /// @return Returns a pointer to the child widget that was selected last.
216  virtual Widget* GetLastSelectedChild() const;
217  /// @brief Forces the currently selected child to become deselected.
218  virtual void ClearSelectedChild();
219 
220  /// @brief Gets the current provider configuration of this container.
221  /// @return Returns an enum describing the the provider configuration for this container.
222  virtual ProviderMode GetProviderConfig() const;
223  /// @brief Gets the role of the specified PageProvider in this container.
224  /// @param Prov The PageProvider to check this container for.
225  /// @return Returns a ProviderMode enum value representing how the specified PageProvider is providing for this container.
226  virtual ProviderMode GetProviderConfig(const PageProvider* Prov) const;
227 
228  ///////////////////////////////////////////////////////////////////////////////
229  // Visibility and Priority Methods
230 
231  /// @copydoc Renderable::SetVisible(Boole)
232  virtual void SetVisible(Boole CanSee);
233  /// @copydoc Renderable::GetVisible() const
234  virtual Boole GetVisible() const;
235  /// @copydoc Renderable::IsVisible() const
236  virtual Boole IsVisible() const;
237  /// @copydoc Renderable::Show()
238  virtual void Show();
239  /// @copydoc Renderable::Hide()
240  virtual void Hide();
241 
242  ///////////////////////////////////////////////////////////////////////////////
243  // PagedContainer Configuration
244 
245  /// @brief Sets the page providers for both axes.
246  /// @param XProv The PageProvider controlling the current horizontal page.
247  /// @param YProv The PageProvider controlling the current vertical page.
248  virtual void SetProviders(PageProvider* XProv, PageProvider* YProv) = 0;
249  /// @brief Sets the PageProvider for the X axis.
250  /// @param XProv The PageProvider controlling the current horizontal page.
251  virtual void SetXProvider(PageProvider* XProv) = 0;
252  /// @brief Sets the PageProvider for the Y axis.
253  /// @param YProv The PageProvider controlling the current vertical page.
254  virtual void SetYProvider(PageProvider* YProv) = 0;
255  /// @brief Sets a single PageProvider as the provider for both the X and Y axis.
256  /// @param Prov The PageProvider to be set for the X and Y axes.
257  virtual void SetXYProvider(PageProvider* Prov);
258 
259  /// @brief Gets the PageProvider for the X axis.
260  /// @return Returns a pointer to the PageProvider for the X axis of this container.
261  virtual PageProvider* GetXProvider() const;
262  /// @brief Gets the PageProvider for the Y axis.
263  /// @return Returns a pointer to the PageProvider for the Y axis of this container.
264  virtual PageProvider* GetYProvider() const;
265 
266  /// @brief Unbinds a provider being used by this container.
267  /// @param Prov A pointer to the PageProvider to be unbound if it is used by this container.
268  virtual void UnbindProvider(PageProvider* Prov);
269 
270  ///////////////////////////////////////////////////////////////////////////////
271  // Child Management
272 
273  /// @copydoc QuadRenderable::AddChild(Widget*)
274  virtual void AddChild(Widget* Child);
275  /// @copydoc QuadRenderable::AddChild(Widget*,const UInt16)
276  virtual void AddChild(Widget* Child, const UInt16 ZOrder);
277  /// @copydoc QuadRenderable::RemoveChild(Widget*)
278  virtual void RemoveChild(Widget* ToBeRemoved);
279  /// @copydoc QuadRenderable::RemoveAllChildren()
280  virtual void RemoveAllChildren();
281  /// @copydoc QuadRenderable::DestroyChild(Widget*)
282  virtual void DestroyChild(Widget* ToBeDestroyed);
283  /// @copydoc QuadRenderable::DestroyAllChildren()
284  virtual void DestroyAllChildren();
285 
286  ///////////////////////////////////////////////////////////////////////////////
287  // Serialization
288 
289  /// @brief Convert the PageProvider data of this class to an XML::Node ready for serialization.
290  /// @param SelfRoot The root node containing all the serialized data for this instance.
291  virtual void ProtoSerializePageData(XML::Node& SelfRoot) const;
292  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
293  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
294 
295  /// @brief Take the data stored in an XML Node and overwrite the PageProvider data of this object with it.
296  /// @param SelfRoot An XML::Node containing the data to populate this class with.
297  virtual void ProtoDeSerializePageData(const XML::Node& SelfRoot);
298  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
299  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
300 
301  /// @copydoc Renderable::GetSerializableName()
302  static String GetSerializableName();
303 
304  ///////////////////////////////////////////////////////////////////////////////
305  // Internal Event Methods
306 
307  /// @brief Self logic to be executed when focus is given to a child of this widget.
308  /// @param ChildName The name of the child that has gained focus.
309  /// @param Selected A Boole indicating whether the child is being selected or deselected.
310  virtual void _OnChildSelected(const String& ChildName, const Boole Selected);
311 
312  ///////////////////////////////////////////////////////////////////////////////
313  // Internal Methods
314 
315  /// @copydoc QuadRenderable::_AppendRenderDataCascading(ScreenRenderData&)
316  virtual void _AppendRenderDataCascading(ScreenRenderData& RenderData);
317  };//PagedContainer
318  }//UI
319 }//Mezzanine
320 
321 #endif
This is the base class for containers that have a render area and work area of different sizes...
Widget * LastSelectedChild
A pointer to the last child widget that was selected within this container.
const Boole Selected
Boole storing whether or not the named child is gaining or losing focus.
VisibleChildContainer::const_iterator ConstVisibleChildIterator
Const Iterator type for Visible Widget instances stored by this class.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
const String ChildName
The identification of the source firing this event.
static const String TypeName
String containing the type name for this class: "PagedContainer".
VisibleChildContainer::iterator VisibleChildIterator
Iterator type for Visible Widget instances stored by this class.
virtual ChildSelectedArguments * GetMostDerived()
Get a pointer to the most Derived type of this instance.
A simple reference counting pointer.
Definition: countedptr.h:70
This class represents a box shaped area on the screen.
Definition: rect.h:55
ChildSelectedArguments(const String &Name, const String &Source, const String &Child, const Boole Select)
Class constructor.
PageProvider * XProvider
A pointer to the X axis provider.
static const String EventChildSelected
Event name for when a child of this widget gets selected.
virtual ~ChildSelectedArguments()
Class destructor.
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
This is used to deduce at compile if a specific class has built-in reference counting or needs an ext...
Definition: countedptr.h:87
This is the EventArguments class for when a child of a paged container is selected.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
UI::ChildSelectedArguments RefCountType
Typedef communicating the reference count type to be used.
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
This is the base class for all widgets.
Definition: widget.h:126
A static cast from the pointer as provided with no attempt to calls functions on the pointer target...
Definition: countedptr.h:63
PageProvider * YProvider
A pointer to the Y axis provider.
This is the base class for interpretting widget values to page positions.
Definition: pageprovider.h:55
static RefCountType * ConstructionPointer(RefCountType *Target)
Method responsible for creating a reference count for a CountedPtr of the templated type...
Vector2 WorkAreaSize
Vector2 storing the size for all pages of this container.
#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
This class stores all vertices pertaining to a layer sorted by their priority for rendering...
Definition: screen.h:115
This class represents a point in 2D space using UnifiedDim's.
Definition: unifieddim.h:306
ProviderMode
An enum describing how the providers for this container are configured and being used.
VisibleChildContainer VisibleChildren
A container of children that meet the criteria for rendering in this container.
std::vector< Widget * > VisibleChildContainer
Basic container type for Visible Widget storage by this class.
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
CountedPtr< ChildSelectedArguments > ChildSelectedArgumentsPtr
Convenience typedef for passing around ChildSelectedArguments.
This is the base class for widget specific event arguments.
Definition: widget.h:60