Spinning Topp Logo BlackTopp Studios
inc
spinner.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 _uispinner_h
41 #define _uispinner_h
42 
43 #include "UI/pageprovider.h"
44 #include "UI/widgetfactory.h"
45 #include "UI/uienumerations.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  class Button;
52  class EditBox;
53  class FontData;
54  ///////////////////////////////////////////////////////////////////////////////
55  /// @brief This is the EventArguments class for when the spinvalue of a Spinner is updated.
56  /// @details
57  ///////////////////////////////////////
59  {
60  public:
61  ///////////////////////////////////////////////////////////////////////////////
62  // Public Data Members
63 
64  /// @brief The pre-update value of the calling Spinner.
66  /// @brief The post-update value of the calling Spinner.
68 
69  ///////////////////////////////////////////////////////////////////////////////
70  // Construction and Destruction
71 
72  /// @brief Class constructor.
73  /// @param Name The name of the event being fired.
74  /// @param Source The identification of the widget firing this event.
75  /// @param OldValue The pre-update value of the calling Spinner.
76  /// @param NewValue The post-update value of the calling Spinner.
77  SpinnerValueChangedArguments(const String& Name, const String& Source, const Real& OldValue, const Real& NewValue) :
78  WidgetEventArguments(Name,Source), OldSpinValue(OldValue), NewSpinValue(NewValue) { }
79  /// @brief Class destructor.
81 
82  ///////////////////////////////////////////////////////////////////////////////
83  // CountedPtr Functionality
84 
85  /// @copydoc EventArguments::GetMostDerived()
87  { return this; }
88  };//SpinnerValueChangedArguments
89  }//UI
90 
91  ///////////////////////////////////////////////////////////////////////////////
92  /// @brief This is a metaprogramming traits class used by SpinnerValueChangedArguments.
93  /// @details This is need for an intrusive CountedPtr implementation. Should a working external reference count be made this
94  /// could be dropped in favor of a leaner implementation.
95  ///////////////////////////////////////
96  template <>
97  class ReferenceCountTraits<UI::SpinnerValueChangedArguments>
98  {
99  public:
100  /// @brief Typedef communicating the reference count type to be used.
102 
103  /// @brief Method responsible for creating a reference count for a CountedPtr of the templated type.
104  /// @param Target A pointer to the target class that is to be reference counted.
105  /// @return Returns a pointer to a new reference counter for the templated type.
106  static RefCountType* ConstructionPointer(RefCountType* Target)
107  { return Target; }
108 
109  /// @brief Enum used to decide the type of casting to be used by a reference counter of the templated type.
110  enum { IsCastable = CastStatic };
111  };//ReferenceCountTraits<SpinnerValueChangedArguments>
112 
113  namespace UI
114  {
115  /// @brief Convenience typedef for passing around SpinnerValueChangedArguments.
117 
118  ///////////////////////////////////////////////////////////////////////////////
119  /// @brief This is a simple widget for a numeric variable in a box.
120  /// @details Like the Scrollbar Widget, the size provided will be for the area of all the
121  /// elements of this widget combined. In the case of separate format, if horizontal, the
122  /// width of the increment and decrement buttons will be the same as the height or if vertical
123  /// the height will be the same as the width provided. In either case making the two buttons
124  /// perfectly square in size, with the remaining space going to the display caption. @n
125  /// In the case of the together format, then half of the height is taken and that is used for
126  /// both the width and height, and then they are placed on the appropriate side. @n @n
127  /// This class can use either a HorizontalLayoutStrategy, VerticalLayoutStrategy, or the
128  /// LayoutStrategy base class depeding on the set button layout/SpinStyle.
129  ///////////////////////////////////////
131  {
132  public:
133  /// @brief String containing the type name for this class: "Spinner".
134  static const String TypeName;
135  /// @brief Event name for when the value in this Spinner is updated.
137  protected:
138  /// @internal
139  /// @brief A pointer to the button that will increment the spin value.
141  /// @internal
142  /// @brief A pointer to the button that will decrement the spin value.
144  /// @internal
145  /// @brief A pointer to the EditBox that will display the spin value.
147  /// @internal
148  /// @brief The current spin value of this Spinner.
150  /// @internal
151  /// @brief The amount to increase or decrease by when the spin value is altered via buttons.
153  /// @internal
154  /// @brief The minimum value allowed to be expressed by this Spinner.
156  /// @internal
157  /// @brief The maximum value allowed to be expressed by this Spinner.
159  /// @internal
160  /// @brief Which axis is primary when determining the current X or Y page.
162 
163  /// @internal
164  /// @brief Contains all the common necessary startup initializations for this class.
165  /// @param SpinStyle The layout of buttons this Spinner will have.
166  /// @param EditFont A pointer to the font to be used by the child EditBox.
167  virtual void ConstructSpinner(const SpinnerStyle SpinStyle, FontData* EditFont);
168  /// @internal
169  /// @brief Ensures the provided value is within the configured limits.
170  /// @param Value The value to verify.
171  virtual void ClampToLimits(Real& Value);
172  public:
173  /// @brief Blank constructor.
174  /// @param Parent The parent Screen that created this widget.
175  Spinner(Screen* Parent);
176  /// @brief Standard initialization constructor.
177  /// @param RendName The name to be given to this renderable.
178  /// @param SpinStyle The layout of buttons this Spinner will have.
179  /// @param EditFont A pointer to the font to be used by the child EditBox.
180  /// @param Parent The parent Screen that created this widget.
181  Spinner(const String& RendName, const SpinnerStyle SpinStyle, FontData* EditFont, Screen* Parent);
182  /// @brief Standard initialization constructor.
183  /// @param RendName The name to be given to this renderable.
184  /// @param SpinStyle The layout of buttons this Spinner will have.
185  /// @param EditFontName The name of the font to be used by the child EditBox.
186  /// @param Parent The parent Screen that created this widget.
187  Spinner(const String& RendName, const SpinnerStyle SpinStyle, const String& EditFontName, Screen* Parent);
188  /// @brief Rect constructor.
189  /// @param RendName The name to be given to this renderable.
190  /// @param RendRect The rect describing this widget's transform relative to it's parent.
191  /// @param SpinStyle The layout of buttons this Spinner will have.
192  /// @param EditFont A pointer to the font to be used by the child EditBox.
193  /// @param Parent The parent screen that created this renderable.
194  Spinner(const String& RendName, const UnifiedRect& RendRect, const SpinnerStyle SpinStyle, FontData* EditFont, Screen* Parent);
195  /// @brief Rect constructor.
196  /// @param RendName The name to be given to this renderable.
197  /// @param RendRect The rect describing this widget's transform relative to it's parent.
198  /// @param SpinStyle The layout of buttons this Spinner will have.
199  /// @param EditFontName The name of the font to be used by the child EditBox.
200  /// @param Parent The parent screen that created this renderable.
201  Spinner(const String& RendName, const UnifiedRect& RendRect, const SpinnerStyle SpinStyle, const String& EditFontName, Screen* Parent);
202  /// @brief XML constructor.
203  /// @param XMLNode The node of the xml document to construct from.
204  /// @param Parent The screen the created Spinner will belong to.
205  Spinner(const XML::Node& XMLNode, Screen* Parent);
206  /// @brief Class destructor.
207  virtual ~Spinner();
208  //public:
209  ///////////////////////////////////////////////////////////////////////////////
210  // Utility Methods
211 
212  /// @copydoc Widget::GetTypeName() const
213  virtual const String& GetTypeName() const;
214 
215  ///////////////////////////////////////////////////////////////////////////////
216  // Spinner Properties
217 
218  /// @brief Sets the value of this Spinner.
219  /// @param Value A Real containing the new value of this Spinner.
220  virtual void SetSpinValue(Real Value);
221  /// @brief Gets the value of this Spinner.
222  /// @return Returns a Real containing the current value of this spinner.
223  virtual Real GetSpinValue() const;
224  /// @brief Sets the amount to increase or decrease by when the spinner value is altered by child buttons.
225  /// @param Value A Real containing the amount to increase the spin value when incrememnted, or decrease the spin value when decremented.
226  virtual void SetIncrementValue(const Real Value);
227  /// @brief Gets the amount to increase or decrease by when the spinner value is altered by child buttons.
228  /// @return Returns a Real containing the amount the spin value will go up or down when the child buttons are clicked.
229  virtual Real GetIncrementValue() const;
230 
231  /// @brief Sets the minimum and maximum limits for the value this Spinner can have.
232  /// @note Both of these values default to 0.0 after construction.
233  /// @param Min The minumum value this Spinner can have.
234  /// @param Max The maximum value this Spinner can have.
235  virtual void SetSpinValueLimits(const Real Min, const Real Max);
236  /// @brief Sets the minimum limit for the value this Spinner can have.
237  /// @param Value The minumum value this Spinner can have.
238  virtual void SetMinSpinValue(const Real Value);
239  /// @brief Gets the minimum limit for the value this Spinner can have.
240  /// @return Returns a Real containing the minimum allowed value of this Spinner.
241  virtual Real GetMinSpinValue() const;
242  /// @brief Sets the maximum limit for the value this spinner can have.
243  /// @param Value The maximum value this Spinner can have.
244  virtual void SetMaxSpinValue(const Real Value);
245  /// @brief Gets the maximum limit for the value this spinner can have.
246  /// @return Returns a Real containing the maximum allowed value of this Spinner.
247  virtual Real GetMaxSpinValue() const;
248 
249  /// @brief Sets which axis will be considered first when converting the current value to an X or Y page.
250  /// @note This value is only used when this spinner is configured as both the X and Y provider of a paged container.
251  /// @param Order An OrderingPriority enum value representing which axis is to be considered primary when determining the current page on a given axis.
252  virtual void SetOrderingPriority(const UI::OrderingPriority Order);
253  /// @brief Gets which axis will be considered first when converting the current value to an X or Y page.
254  /// @return Returns an OrderingPriority enum value representing which axis is considered primary when determining the current page on a given axis.
255  virtual UI::OrderingPriority GetOrderingPriority() const;
256 
257  ///////////////////////////////////////////////////////////////////////////////
258  // Spinner Configuration
259 
260  /// @brief Sets the sizing and positioning policies of the children in this spinner to match the provided layout.
261  /// @param Style A SpinnerStyle value representing how the children of this spinner should be layed out.
262  virtual void SetButtonLayout(const SpinnerStyle Style);
263 
264  /// @brief Gets the increment Button of this Spinner.
265  /// @return Returns a pointer to the increment Button.
266  virtual Button* GetIncrement() const;
267  /// @brief Gets the decrement Button of this Spinner.
268  /// @return Returns a pointer to the decrement Button.
269  virtual Button* GetDecrement() const;
270  /// @brief Gets the EditBox displaying the value of this Spinner.
271  /// @return Returns a pointer to the value display EditBox.
272  virtual EditBox* GetValueDisplay() const;
273 
274  ///////////////////////////////////////////////////////////////////////////////
275  // PageProvider Methods
276 
277  /// @copydoc PageProvider::GetMaxXPages() const
278  virtual Real GetMaxXPages() const;
279  /// @copydoc PageProvider::GetMaxYPages() const
280  virtual Real GetMaxYPages() const;
281 
282  /// @copydoc PageProvider::GetCurrentXPage() const
283  virtual Real GetCurrentXPage() const;
284  /// @copydoc PageProvider::GetCurrentYPage() const
285  virtual Real GetCurrentYPage() const;
286 
287  ///////////////////////////////////////////////////////////////////////////////
288  // Serialization
289 
290  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
291  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
292  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
293  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
294 
295  /// @copydoc Renderable::GetSerializableName()
296  static String GetSerializableName();
297 
298  ///////////////////////////////////////////////////////////////////////////////
299  // Internal Event Methods
300 
301  /// @brief Self logic to be executed when this Spinner has it's spin value updated.
302  /// @param OldValue The previous value of this Spinner.
303  /// @param NewValue The updated value of this Spinner.
304  virtual void _OnSpinValueChanged(const Real OldValue, const Real NewValue);
305 
306  ///////////////////////////////////////////////////////////////////////////////
307  // Internal Methods
308 
309  /// @copydoc EventSubscriber::_NotifyEvent(EventArgumentsPtr Args)
310  virtual void _NotifyEvent(EventArgumentsPtr Args);
311  /// @copydoc PageProvider::_NotifyContainerUpdated()
312  virtual void _NotifyContainerUpdated();
313  };//Spinner
314 
315  ///////////////////////////////////////////////////////////////////////////////
316  /// @brief This is the factory implementation for Spinner widgets.
317  /// @details
318  ///////////////////////////////////////
320  {
321  public:
322  /// @brief Class constructor.
324  /// @brief Class destructor.
325  virtual ~SpinnerFactory() { }
326 
327  /// @copydoc WidgetFactory::GetWidgetTypeName() const
328  virtual String GetWidgetTypeName() const;
329 
330  /// @brief Creates a new Spinner.
331  /// @param RendName The name to be given to the created Spinner.
332  /// @param SpinStyle The layout of buttons this Spinner will have.
333  /// @param EditFont A pointer to the font to be used by the edit layer.
334  /// @param Parent The screen the created Spinner will belong to.
335  /// @return Returns a pointer to the created Spinner.
336  virtual Spinner* CreateSpinner(const String& RendName, const SpinnerStyle SpinStyle, FontData* EditFont, Screen* Parent);
337  /// @brief Creates a new Spinner.
338  /// @param RendName The name to be given to the created Spinner.
339  /// @param SpinStyle The layout of buttons this Spinner will have.
340  /// @param EditFontName The name of the font to be used by the edit layer.
341  /// @param Parent The screen the created Spinner will belong to.
342  /// @return Returns a pointer to the created Spinner.
343  virtual Spinner* CreateSpinner(const String& RendName, const SpinnerStyle SpinStyle, const String& EditFontName, Screen* Parent);
344  /// @brief Creates a new Spinner.
345  /// @param RendName The name to be given to the created Spinner.
346  /// @param RendRect The dimensions that will be assigned to the created Spinner.
347  /// @param SpinStyle The layout of buttons this Spinner will have.
348  /// @param EditFont A pointer to the font to be used by the edit layer.
349  /// @param Parent The screen the created Spinner will belong to.
350  /// @return Returns a pointer to the created Spinner.
351  virtual Spinner* CreateSpinner(const String& RendName, const UnifiedRect& RendRect, const SpinnerStyle SpinStyle, FontData* EditFont, Screen* Parent);
352  /// @brief Creates a new Spinner.
353  /// @param RendName The name to be given to the created Spinner.
354  /// @param RendRect The dimensions that will be assigned to the created Spinner.
355  /// @param SpinStyle The layout of buttons this Spinner will have.
356  /// @param EditFontName The name of the font to be used by the edit layer.
357  /// @param Parent The screen the created Spinner will belong to.
358  /// @return Returns a pointer to the created Spinner.
359  virtual Spinner* CreateSpinner(const String& RendName, const UnifiedRect& RendRect, const SpinnerStyle SpinStyle, const String& EditFontName, Screen* Parent);
360  /// @brief Creates a new Spinner.
361  /// @param XMLNode The node of the xml document to construct from.
362  /// @param Parent The screen the created Spinner will belong to.
363  /// @return Returns a pointer to the created Spinner.
364  virtual Spinner* CreateSpinner(const XML::Node& XMLNode, Screen* Parent);
365 
366  /// @copydoc WidgetFactory::CreateWidget(Screen*)
367  virtual Widget* CreateWidget(Screen* Parent);
368  /// @copydoc WidgetFactory::CreateWidget(const String&, const NameValuePairMap&, Screen*)
369  virtual Widget* CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent);
370  /// @copydoc WidgetFactory::CreateWidget(const String&, const UnifiedRect&, const NameValuePairMap&, Screen*)
371  virtual Widget* CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent);
372  /// @copydoc WidgetFactory::CreateWidget(const XML::Node&, Screen*)
373  virtual Widget* CreateWidget(const XML::Node& XMLNode, Screen* Parent);
374  /// @copydoc WidgetFactory::DestroyWidget(Widget*)
375  virtual void DestroyWidget(Widget* ToBeDestroyed);
376  };//SpinnerFactory
377  }//UI
378 }//Mezzanine
379 
380 #endif
const Real NewSpinValue
The post-update value of the calling Spinner.
Definition: spinner.h:67
Button * DecrementSpin
A pointer to the button that will decrement the spin value.
Definition: spinner.h:143
This class represents a collection of Glyphs in a common visual style.
Definition: font.h:55
virtual ~SpinnerValueChangedArguments()
Class destructor.
Definition: spinner.h:80
static const String EventSpinValueChanged
Event name for when the value in this Spinner is updated.
Definition: spinner.h:136
UI::OrderingPriority OrderPriority
Which axis is primary when determining the current X or Y page.
Definition: spinner.h:161
SpinnerStyle
Used by the spinner class to determine what styling should be used for the spinner.
virtual ~SpinnerFactory()
Class destructor.
Definition: spinner.h:325
A simple reference counting pointer.
Definition: countedptr.h:70
CountedPtr< SpinnerValueChangedArguments > SpinnerValueChangedArgumentsPtr
Convenience typedef for passing around SpinnerValueChangedArguments.
Definition: spinner.h:116
virtual SpinnerValueChangedArguments * GetMostDerived()
Get a pointer to the most Derived type of this instance.
Definition: spinner.h:86
OrderingPriority
Used by container widgets to determine which axis is considered primary for children/pages.
This is a simple widget for a numeric variable in a box.
Definition: spinner.h:130
static RefCountType * ConstructionPointer(RefCountType *Target)
Method responsible for creating a reference count for a CountedPtr of the templated type...
Definition: spinner.h:106
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
EditBox * ValueDisplay
A pointer to the EditBox that will display the spin value.
Definition: spinner.h:146
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
This is used to deduce at compile if a specific class has built-in reference counting or needs an ext...
Definition: countedptr.h:87
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is the base class for all widgets.
Definition: widget.h:126
Real MinValue
The minimum value allowed to be expressed by this Spinner.
Definition: spinner.h:155
Button * IncrementSpin
A pointer to the button that will increment the spin value.
Definition: spinner.h:140
This is the EventArguments class for when the spinvalue of a Spinner is updated.
Definition: spinner.h:58
A static cast from the pointer as provided with no attempt to calls functions on the pointer target...
Definition: countedptr.h:63
UI::SpinnerValueChangedArguments RefCountType
Typedef communicating the reference count type to be used.
Definition: spinner.h:101
This is the factory implementation for Spinner widgets.
Definition: spinner.h:319
This is the base class for interpretting widget values to page positions.
Definition: pageprovider.h:55
SpinnerFactory()
Class constructor.
Definition: spinner.h:323
#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
Real SpinValue
The current spin value of this Spinner.
Definition: spinner.h:149
This class is a helper class, specifically for use as a button.
Definition: button.h:66
Real MaxValue
The maximum value allowed to be expressed by this Spinner.
Definition: spinner.h:158
Real IncrementValue
The amount to increase or decrease by when the spin value is altered via buttons. ...
Definition: spinner.h:152
static const String TypeName
String containing the type name for this class: "Spinner".
Definition: spinner.h:134
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
This is a base class for factories that construct the widgets available to the UI subsystem...
Definition: widgetfactory.h:61
SpinnerValueChangedArguments(const String &Name, const String &Source, const Real &OldValue, const Real &NewValue)
Class constructor.
Definition: spinner.h:77
const Real OldSpinValue
The pre-update value of the calling Spinner.
Definition: spinner.h:65
This is the base class for widget specific event arguments.
Definition: widget.h:60
Widget for handling the input and manipulation of text.
Definition: editbox.h:60