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