MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
menuentry.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 _uimenuentry_h
41 #define _uimenuentry_h
42 
43 #include "UI/stackedcontainer.h"
44 
45 namespace Mezzanine
46 {
47  namespace UI
48  {
49  class MenuButton;
50  class MenuEntryStack;
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @brief This is a class designed to help MenuEntrys keep track of the Menu tree they belong to.
53  /// @details
54  ///////////////////////////////////////
56  {
57  protected:
58  public:
59  MenuStack();
60  ~MenuStack();
61 
62 
63  };//MenuStack
64 
65  ///////////////////////////////////////////////////////////////////////////////
66  /// @brief This class is an entry for a single window/widget in a menu.
67  /// @details This class can be used to represent a single window/widget in a heirarchy
68  /// that will change visibility as one would expect in a game menu.
69  ///////////////////////////////////////
71  {
72  public:
73  /// @brief Basic container type for child MenuEntry storage by this class.
74  typedef std::vector<MenuEntry*> MenuEntryContainer;
75  /// @brief Iterator type for child MenuEntry instances stored by this class.
76  typedef MenuEntryContainer::iterator MenuEntryIterator;
77  /// @brief Const Iterator type for child MenuEntry instances stored by this class.
78  typedef MenuEntryContainer::const_iterator ConstMenuEntryIterator;
79 
80  /// @enum ButtonConfig
81  /// @brief An enum describing how the MenuButton for this MenuEntry is configured and being used.
83  {
84  BC_Error = 0, ///< Error condition or queried button isn't bound to this MenuEntry.
85  BC_PushButton = 1, ///< Queried button is being used as the entry push button.
86  BC_PopButton = 2, ///< Queried button is being used as the entry pop button.
87  BC_ToggleButton = 3 ///< Queried button is being used as both the push and pop button, aka toggle button.
88  };
89 
90  /// @brief String containing the type name for this class: "MenuEntry".
91  static const String TypeName;
92  protected:
93  friend class MenuEntryFactory;
94  /// @internal
95  /// @brief A pointer to the active stack of MenuEntries.
97  /// @internal
98  /// @brief A pointer to the button that will push this entry on the menu stack.
100  /// @internal
101  /// @brief A pointer to the button that will pop this entry from the menu stack.
103  /// @internal
104  /// @brief Stores whether or not this Entry will automatically be hidden when another entry is pushed onto the stack after it.
105  Boolean AutoHideEntry;
106 
107  /// @internal
108  /// @brief Pushes this MenuEntry onto the stack if one is available.
109  /// @return Returns true if this MenuEntry was successfully pushed onto the stack, false otherwise.
110  virtual Boolean PushOntoStack();
111  /// @internal
112  /// @brief Pops this MenuEntry from the stack if one is available.
113  /// @return Returns true if this MenuEntry was successfully popped from the stack, false otherwise.
114  virtual Boolean PopFromStack();
115  //public:
116  /// @brief Blank constructor.
117  /// @param Parent The parent Screen that created this widget.
118  MenuEntry(Screen* Parent);
119  /// @brief Standard initialization constructor.
120  /// @param RendName The name to be given to this renderable.
121  /// @param Parent The parent Screen that created this widget.
122  MenuEntry(const String& RendName, Screen* Parent);
123  /// @brief Rect constructor.
124  /// @param RendName The name to be given to this renderable.
125  /// @param RendRect The rect describing this widget's transform relative to it's parent.
126  /// @param Parent The parent screen that created this renderable.
127  MenuEntry(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
128  /// @brief XML constructor.
129  /// @param XMLNode The node of the xml document to construct from.
130  /// @param Parent The screen the created MenuEntry will belong to.
131  MenuEntry(const XML::Node& XMLNode, Screen* Parent);
132  /// @brief Class destructor.
133  virtual ~MenuEntry();
134  public:
135  ///////////////////////////////////////////////////////////////////////////////
136  // Utility Methods
137 
138  /// @brief Gets whether or not this is the Root of the MenuEntry hierarchy.
139  /// @return Returns true if this MenuEntry has no parent entry, false otherwise.
140  virtual Boolean IsRootEntry() const;
141  /// @brief Gets the role of the specified MenuButton for this MenuEntry.
142  /// @param EntryButton The button to check this MenuEntry for.
143  /// @return Returns a ButtonConfig enum value representing how the specified MenuButton is being used by this MenuEntry.
144  virtual ButtonConfig GetButtonConfig(const MenuButton* EntryButton) const;
145 
146  /// @brief Finds a MenuEntry in the menu stack and hides all Entries above it in the menu stack.
147  /// @note This can return zero if the provided entry isn't on the stack or if it is the last entry on the stack.
148  /// @param RollBackTo A pointer to the MenuEntry to roll the menu stack back to.
149  /// @return Returns the number of MenuEntrys that were hidden by this method.
150  virtual Whole RollBackToEntry(MenuEntry* RollBackTo);
151 
152  ///////////////////////////////////////////////////////////////////////////////
153  // Visibility and Priority Methods
154 
155  /// @copydoc Renderable::SetVisible(Bool)
156  virtual void SetVisible(Boolean CanSee);
157  /// @copydoc Renderable::Show()
158  virtual void Show();
159  /// @copydoc Renderable::Hide()
160  virtual void Hide();
161 
162  ///////////////////////////////////////////////////////////////////////////////
163  // MenuEntry Properties
164 
165  /// @brief Sets whether or not thie window should auto hide when another window is added to the menu stack.
166  /// @param AutoHide whether or not to enable auto hiding for this menu window.
167  virtual void SetAutoHide(Boolean AutoHide);
168  /// @brief Gets wether or not this window is set to auto hide when another window is added to the menu stack.
169  /// @return Returns a bool indicating whether or not AutoHide is enabled on this menu window.
170  virtual Boolean GetAutoHide() const;
171 
172  ///////////////////////////////////////////////////////////////////////////////
173  // Menu Configuration
174 
175  /// @brief Sets the button that will push(add) this entry on the menu stack, making it visible.
176  /// @param Push A pointer to the button that will make this entry visible.
177  virtual void SetPushButton(MenuButton* Push);
178  /// @brief Gets a pointer to the button that will add this entry to the menu stack.
179  /// @return Returns a pointer to the button that will make this entry visible.
180  virtual MenuButton* GetPushButton() const;
181  /// @brief Sets the button that will pop(remove) this entry from the menu stack, hiding it.
182  /// @param Pop A pointer to the button that will make this entry hide.
183  virtual void SetPopButton(MenuButton* Pop);
184  /// @brief Gets a pointer to the button that will remove this entry from the menu stack.
185  /// @return Returns a pointer to the button that will make this entry hide.
186  virtual MenuButton* GetPopButton() const;
187  /// @brief Sets the button that will both push(add) and pop(remove) the entry from the menu stack, based on the current state of the entry.
188  /// @param Toggle A pointer to the button that will toggle this MenuEntrys visibility.
189  virtual void SetToggleButton(MenuButton* Toggle);
190 
191  ///////////////////////////////////////////////////////////////////////////////
192  // Serialization
193 
194  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
195  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
196  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
197  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
198 
199  /// @copydoc Renderable::GetSerializableName()
200  static String GetSerializableName();
201 
202  ///////////////////////////////////////////////////////////////////////////////
203  // Internal Event Methods
204 
205 
206 
207  ///////////////////////////////////////////////////////////////////////////////
208  // Internal Methods
209 
210  /// @internal
211  /// @brief Gets the MenuStack this Entry belongs to.
212  /// @return Returns a pointer to the MenuEntryContainer being used as the menu stack.
213  MenuEntryContainer* _GetMenuStack() const;
214  /// @internal
215  /// @brief Notifies this MenuEntry and all if it's Entry children a new MenuStack is being applied to the menu tree.
216  /// @param NewStack the new stack to be applied. Can be NULL to remove the stack from all children.
217  virtual void _NotifyStack(MenuEntryContainer* NewStack);
218  /// @copydoc EventSubscriber::_NotifyEvent(const EventArguments&)
219  virtual void _NotifyEvent(const EventArguments& Args);
220  /// @copydoc QuadRenderable::_NotifyParenthood(QuadRenderable*)
221  virtual void _NotifyParenthood(QuadRenderable* NewParent);
222  /// @copydoc QuadRenderable::_HasAvailableRenderData() const
223  virtual Boolean _HasAvailableRenderData() const;
224  };//MenuEntry
225 
226  ///////////////////////////////////////////////////////////////////////////////
227  /// @brief This is the factory implementation for MenuEntry widgets.
228  /// @details
229  ///////////////////////////////////////
231  {
232  public:
233  /// @brief Class constructor.
235  /// @brief Class destructor.
236  virtual ~MenuEntryFactory() { }
237 
238  /// @copydoc WidgetFactory::GetWidgetTypeName() const
239  virtual String GetWidgetTypeName() const;
240 
241  /// @brief Creates a new MenuEntry.
242  /// @param RendName The name to be given to the created MenuEntry.
243  /// @param Parent The screen the created MenuEntry will belong to.
244  /// @return Returns a pointer to the created MenuEntry.
245  virtual MenuEntry* CreateMenuEntry(const String& RendName, Screen* Parent);
246  /// @brief Creates a new MenuEntry.
247  /// @param RendName The name to be given to the created MenuEntry.
248  /// @param RendRect The dimensions that will be assigned to the created MenuEntry.
249  /// @param Parent The screen the created MenuEntry will belong to.
250  /// @return Returns a pointer to the created MenuEntry.
251  virtual MenuEntry* CreateMenuEntry(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
252  /// @brief Creates a new MenuEntry.
253  /// @param XMLNode The node of the xml document to construct from.
254  /// @param Parent The screen the created MenuEntry will belong to.
255  /// @return Returns a pointer to the created MenuEntry.
256  virtual MenuEntry* CreateMenuEntry(const XML::Node& XMLNode, Screen* Parent);
257 
258  /// @copydoc WidgetFactory::CreateWidget(Screen*)
259  virtual Widget* CreateWidget(Screen* Parent);
260  /// @copydoc WidgetFactory::CreateWidget(const String&, const NameValuePairMap&, Screen*)
261  virtual Widget* CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent);
262  /// @copydoc WidgetFactory::CreateWidget(const String&, const UnifiedRect&, const NameValuePairMap&, Screen*)
263  virtual Widget* CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent);
264  /// @copydoc WidgetFactory::CreateWidget(const XML::Node&, Screen*)
265  virtual Widget* CreateWidget(const XML::Node& XMLNode, Screen* Parent);
266  /// @copydoc WidgetFactory::DestroyWidget(Widget*)
267  virtual void DestroyWidget(Widget* ToBeDestroyed);
268  };//MenuEntryFactory
269  }//UI
270 }//Mezzanine
271 
272 #endif