Spinning Topp Logo BlackTopp Studios
inc
radiobutton.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 _uiradiobutton_h
41 #define _uiradiobutton_h
42 
43 #include "UI/checkbox.h"
44 
45 namespace Mezzanine
46 {
47  namespace UI
48  {
49  class RadioButton;
50  ///////////////////////////////////////////////////////////////////////////////
51  /// @brief This is a class designed to facilitate operations across an entire group of RadioButtons.
52  /// @details
53  ///////////////////////////////////////
55  {
56  public:
57  /// @brief Basic container type for RadioButton storage by this class.
58  typedef std::vector<RadioButton*> RadioButtonContainer;
59  /// @brief Iterator type for RadioButton instances stored by this class.
60  typedef RadioButtonContainer::iterator RadioButtonIterator;
61  /// @brief Const Iterator type for RadioButton instances stored by this class.
62  typedef RadioButtonContainer::const_iterator ConstRadioButtonIterator;
63 
64  /// @brief Event name for when the selection among radio buttons has changed.
66  protected:
67  /// @internal
68  /// @brief A container storing all the RadioButtons belonging to this group.
69  RadioButtonContainer GroupButtons;
70  /// @internal
71  /// @brief A pointer to the RadioButton that is the current selection, or NULL if none are selected.
73  public:
74  /// @brief Class constructor.
76  /// @brief Class destructor.
78 
79  ///////////////////////////////////////////////////////////////////////////////
80  // Utility Methods
81 
82  /// @brief Adds a RadioButton to this group.
83  /// @param ToAdd A pointer to the RadioButton to be added to this group.
84  void AddButtonToGroup(RadioButton* ToAdd);
85  /// @brief Gets the number of buttons in this group.
86  /// @return Returns a Whole representing the number of buttons that belong to this group.
87  Whole GetNumButtons() const;
88  /// @brief Removes a RadioButton from this group.
89  /// @param ToRemove A pointer to the RadioButton to be removed from this group.
90  void RemoveButtonFromGroup(RadioButton* ToRemove);
91 
92  /// @brief Makes a RadioButton in this group the selection, deselecting all other RadioButtons in the group.
93  /// @note You can pass in NULL to ensure none of the RadioButtons in this group are selected.
94  /// @param ToSelect A pointer to the RadioButton in this group that will be selected.
95  void SelectButton(RadioButton* ToSelect);
96  /// @brief Deselects all but one (or just all) button(s) in this group
97  /// @note You can pass in NULL to deselect all buttons in this group.
98  /// @param Exclude The Button that will be excluded from forced deselection.
99  void DeselectOtherButtons(RadioButton* Exclude);
100  /// @brief Gets the button that is currently selected among this group of buttons.
101  /// @return Returns a pointer to the currently selected button in this group.
103 
104  /// @brief Gets an iterator to the first RadioButton.
105  /// @return Returns an iterator to the first RadioButton being stored by this renderable.
106  RadioButtonIterator RadioButtonBegin();
107  /// @brief Gets an iterator to one passed the last RadioButton.
108  /// @return Returns an iterator to one passed the last RadioButton being stored by this renderable.
109  RadioButtonIterator RadioButtonEnd();
110  /// @brief Gets a const iterator to the first RadioButton.
111  /// @return Returns a const iterator to the first RadioButton being stored by this renderable.
112  ConstRadioButtonIterator RadioButtonBegin() const;
113  /// @brief Gets an iterator to one passed the last RadioButton.
114  /// @return Returns an iterator to one passed the last RadioButton being stored by this renderable.
115  ConstRadioButtonIterator RadioButtonEnd() const;
116 
117  ///////////////////////////////////////////////////////////////////////////////
118  // Internal Methods
119 
120  /// @internal
121  /// @brief Notifies this group a button has been selected.
122  /// @param Selected The radio button that was selected.
123  void _NotifyButtonSelected(RadioButton* Selected);
124  };//RadioButtonGroup
125 
126  ///////////////////////////////////////////////////////////////////////////////
127  /// @brief This is a simple widget where only one of it's selections can be selected at a time.
128  /// @details This class does not use a LayoutStrategy.
129  ///////////////////////////////////////
130  class RadioButton : public CheckBox
131  {
132  public:
133  /// @brief String containing the type name for this class: "RadioButton".
134  static const String TypeName;
135  protected:
136  /// @internal
137  /// @brief A pointer to the group this RadioButton belongs to.
139 
140  /// @copydoc Renderable::ProtoSerializeImpl(XML::Node&) const
141  virtual void ProtoSerializeImpl(XML::Node& SelfRoot) const;
142  /// @copydoc Renderable::ProtoDeSerializeImpl(const XML::Node&)
143  virtual void ProtoDeSerializeImpl(const XML::Node& SelfRoot);
144  public:
145  /// @brief Blank constructor.
146  /// @param Parent The parent Screen that created this widget.
147  RadioButton(Screen* Parent);
148  /// @brief Standard initialization constructor.
149  /// @param RendName The name to be given to this renderable.
150  /// @param Parent The parent Screen that created this widget.
151  RadioButton(const String& RendName, Screen* Parent);
152  /// @brief Rect constructor.
153  /// @param RendName The name to be given to this renderable.
154  /// @param RendRect The rect describing this widget's transform relative to it's parent.
155  /// @param Parent The parent screen that created this renderable.
156  RadioButton(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
157  /// @brief XML constructor.
158  /// @param XMLNode The node of the xml document to construct from.
159  /// @param Parent The screen the created RadioButton will belong to.
160  RadioButton(const XML::Node& XMLNode, Screen* Parent);
161  /// @brief Class destructor.
162  virtual ~RadioButton();
163  //public:
164  ///////////////////////////////////////////////////////////////////////////////
165  // Utility Methods
166 
167  /// @copydoc Widget::GetTypeName() const
168  virtual const String& GetTypeName() const;
169 
170  ///////////////////////////////////////////////////////////////////////////////
171  // RadioButton Properties
172 
173  ///////////////////////////////////////////////////////////////////////////////
174  // RadioButton Configuration
175 
176  /// @brief Adds this RadioButton to the same RadioButtonGroup as the specified RadioButton.
177  /// @param GroupButton The RadioButton to get the button group from and add this button to.
178  virtual void AddToButtonGroup(RadioButton* GroupButton);
179  /// @brief Removes this RadioButton from the RadioButtonGroup it currently belongs to.
180  virtual void RemoveFromButtonGroup();
181 
182  ///////////////////////////////////////////////////////////////////////////////
183  // Serialization
184 
185  /// @brief Convert the Group Buttons of this class to an XML::Node ready for serialization.
186  /// @param SelfRoot The root node containing all the serialized data for this instance.
187  virtual void ProtoSerializeGroupButtons(XML::Node& SelfRoot) const;
188  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
189  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
190 
191  /// @brief Take the data stored in an XML Node and overwrite the Group Buttons of this object with it.
192  /// @param SelfRoot An XML::Node containing the data to populate this class with.
193  virtual void ProtoDeSerializeGroupButtons(const XML::Node& SelfRoot);
194  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
195  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
196 
197  /// @copydoc Renderable::GetSerializableName()
198  static String GetSerializableName();
199 
200  ///////////////////////////////////////////////////////////////////////////////
201  // Internal Event Methods
202 
203  /// @copydoc CheckBox::_OnSelected()
204  virtual void _OnSelected();
205  /// @copydoc CheckBox::_OnDeselected()
206  virtual void _OnDeselected();
207 
208  ///////////////////////////////////////////////////////////////////////////////
209  // Internal Methods
210 
211  /// @internal
212  /// @brief Gets the RadioButtonGroup this button belongs to.
213  /// @return Returns a pointer to the RadioButtonGroup that this button belongs to, or NULL if it doesn't have a group.
214  virtual RadioButtonGroup* _GetButtonGroup() const;
215  };//RadioButton
216 
217  ///////////////////////////////////////////////////////////////////////////////
218  /// @brief This is the factory implementation for RadioButton widgets.
219  /// @details
220  ///////////////////////////////////////
222  {
223  public:
224  /// @brief Class constructor.
226  /// @brief Class destructor.
227  virtual ~RadioButtonFactory() { }
228 
229  /// @copydoc WidgetFactory::GetWidgetTypeName() const
230  virtual String GetWidgetTypeName() const;
231 
232  /// @brief Creates a new RadioButton.
233  /// @param RendName The name to be given to the created RadioButton.
234  /// @param Parent The screen the created RadioButton will belong to.
235  /// @return Returns a pointer to the created RadioButton.
236  virtual RadioButton* CreateRadioButton(const String& RendName, Screen* Parent);
237  /// @brief Creates a new RadioButton.
238  /// @param RendName The name to be given to the created RadioButton.
239  /// @param RendRect The dimensions that will be assigned to the created RadioButton.
240  /// @param Parent The screen the created RadioButton will belong to.
241  /// @return Returns a pointer to the created RadioButton.
242  virtual RadioButton* CreateRadioButton(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
243  /// @brief Creates a new RadioButton.
244  /// @param XMLNode The node of the xml document to construct from.
245  /// @param Parent The screen the created RadioButton will belong to.
246  /// @return Returns a pointer to the created RadioButton.
247  virtual RadioButton* CreateRadioButton(const XML::Node& XMLNode, Screen* Parent);
248 
249  /// @copydoc WidgetFactory::CreateWidget(Screen*)
250  virtual Widget* CreateWidget(Screen* Parent);
251  /// @copydoc WidgetFactory::CreateWidget(const String&, const NameValuePairMap&, Screen*)
252  virtual Widget* CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent);
253  /// @copydoc WidgetFactory::CreateWidget(const String&, const UnifiedRect&, const NameValuePairMap&, Screen*)
254  virtual Widget* CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent);
255  /// @copydoc WidgetFactory::CreateWidget(const XML::Node&, Screen*)
256  virtual Widget* CreateWidget(const XML::Node& XMLNode, Screen* Parent);
257  /// @copydoc WidgetFactory::DestroyWidget(Widget*)
258  virtual void DestroyWidget(Widget* ToBeDestroyed);
259  };//RadioButtonFactory
260  }//UI
261 }//Mezzanine
262 
263 #endif
RadioButtonContainer::iterator RadioButtonIterator
Iterator type for RadioButton instances stored by this class.
Definition: radiobutton.h:60
static const String EventGroupButtonSelected
Event name for when the selection among radio buttons has changed.
Definition: radiobutton.h:65
std::vector< RadioButton * > RadioButtonContainer
Basic container type for RadioButton storage by this class.
Definition: radiobutton.h:58
RadioButtonIterator RadioButtonBegin()
Gets an iterator to the first RadioButton.
virtual void ProtoSerializeGroupButtons(XML::Node &SelfRoot) const
Convert the Group Buttons of this class to an XML::Node ready for serialization.
RadioButtonFactory()
Class constructor.
Definition: radiobutton.h:225
virtual ~RadioButtonFactory()
Class destructor.
Definition: radiobutton.h:227
~RadioButtonGroup()
Class destructor.
Definition: radiobutton.cpp:68
virtual void RemoveFromButtonGroup()
Removes this RadioButton from the RadioButtonGroup it currently belongs to.
void RemoveButtonFromGroup(RadioButton *ToRemove)
Removes a RadioButton from this group.
Definition: radiobutton.cpp:87
static const String TypeName
String containing the type name for this class: "RadioButton".
Definition: radiobutton.h:134
RadioButtonGroup * ButtonGroup
A pointer to the group this RadioButton belongs to.
Definition: radiobutton.h:138
void DeselectOtherButtons(RadioButton *Exclude)
Deselects all but one (or just all) button(s) in this group.
This is the base class for any class that generates and publishes events to subscribers.
This is the factory implementation for RadioButton widgets.
Definition: radiobutton.h:221
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
void AddButtonToGroup(RadioButton *ToAdd)
Adds a RadioButton to this group.
Definition: radiobutton.cpp:74
virtual RadioButtonGroup * _GetButtonGroup() const
Gets the RadioButtonGroup this button belongs to.
RadioButtonGroup()
Class constructor.
Definition: radiobutton.cpp:64
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
This is the base class for all widgets.
Definition: widget.h:126
RadioButtonContainer GroupButtons
A container storing all the RadioButtons belonging to this group.
Definition: radiobutton.h:69
RadioButton * CurrentSelection
A pointer to the RadioButton that is the current selection, or NULL if none are selected.
Definition: radiobutton.h:72
RadioButtonContainer::const_iterator ConstRadioButtonIterator
Const Iterator type for RadioButton instances stored by this class.
Definition: radiobutton.h:62
virtual void ProtoDeSerializeGroupButtons(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the Group Buttons of this object with it...
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
virtual ~RadioButton()
Class destructor.
virtual void AddToButtonGroup(RadioButton *GroupButton)
Adds this RadioButton to the same RadioButtonGroup as the specified RadioButton.
RadioButton * GetCurrentSelection() const
Gets the button that is currently selected among this group of buttons.
void SelectButton(RadioButton *ToSelect)
Makes a RadioButton in this group the selection, deselecting all other RadioButtons in the group...
Definition: radiobutton.cpp:95
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
RadioButton(Screen *Parent)
Blank constructor.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
This is a class designed to facilitate operations across an entire group of RadioButtons.
Definition: radiobutton.h:54
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
RadioButtonIterator RadioButtonEnd()
Gets an iterator to one passed the last RadioButton.
virtual const String & GetTypeName() const
Gets the type of widget this is.
virtual void _OnDeselected()
Self logic to be executed when this checkbox is deselected.
This is a simple widget for storing a bool value.
Definition: checkbox.h:55
This is a simple widget where only one of it's selections can be selected at a time.
Definition: radiobutton.h:130
void _NotifyButtonSelected(RadioButton *Selected)
Notifies this group a button has been selected.
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
virtual void _OnSelected()
Self logic to be executed when this checkbox is selected.
This is a base class for factories that construct the widgets available to the UI subsystem...
Definition: widgetfactory.h:61
Whole GetNumButtons() const
Gets the number of buttons in this group.
Definition: radiobutton.cpp:82