MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
spinner.h
1 // © Copyright 2010 - 2014 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 Caption;
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @class Spinner
55  /// @headerfile uispinner.h
56  /// @brief This is a simple widget for a numeric variable in a box.
57  /// @details Like the Scrollbar Widget, the size provided will be for the area of all the
58  /// elements of this widget combined. In the case of separate format, if horizontal, the
59  /// width of the increment and decrement buttons will be the same as the height or if vertical
60  /// the height will be the same as the width provided. In either case making the two buttons
61  /// perfectly square in size, with the remaining space going to the display caption. @n
62  /// In the case of the together format, then half of the height is taken and that is used for
63  /// both the width and height, and then they are placed on the appropriate side.
64  ///////////////////////////////////////
65  class MEZZ_LIB Spinner : public PageProvider
66  {
67  /*
68  /// @internal
69  /// @brief A pointer to the PagedContainer this scrollbar is providing page data for.
70  PagedContainer* Container;
71 
72  protected:
73  friend class RenderableFactory;
74  Button* Increment;
75  Button* Decrement;
76  Caption* ValueDisplay;
77  bool DecimalDisplay;
78  bool Editable;
79  bool IncrementLock;
80  bool DecrementLock;
81  int Value;
82  int MaxValue;
83  int MinValue;
84  Whole DecimalPlaces;
85  String EditCache;
86  UI::SpinnerStyle SpinLayout;
87  Vector2 IncrementOffset;
88  Vector2 DecrementOffset;
89  Vector2 ValueDisplayOffset;
90  /// @brief Constructor helper function for creating a horizontally aligned spinner.
91  virtual void CreateHorizontalSpinner(const Vector2& Position, const Vector2& Size, const Real& GlyphHeight);
92  /// @brief Constructor helper function for creating a vertically aligned spinner.
93  virtual void CreateVerticalSpinner(const Vector2& Position, const Vector2& Size, const Real& GlyphHeight);
94  /// @brief Constructor helper function for creating a box shaped spinner with buttons together.
95  virtual void CreateBoxSpinner(const Vector2& Position, const Vector2& Size, const Real& GlyphHeight);
96  /// @brief Calculates the relative offsets for the UI elements that make up this widget.
97  virtual void CalculateOffsets(const Vector2& Size);
98  /// @brief Internal function for setting the location(position) of this widget.
99  virtual void SetLocation(const Vector2& Position);
100  /// @brief Internal function for setting the area(size) of this widget.
101  virtual void SetArea(const Vector2& Size);
102  /// @brief Checks to ensure the value is within it's limits.
103  virtual void CheckValueLimits();
104  /// @brief Gets the current value of this spinner as text, for use with updating the caption.
105  virtual String GetValueAsText();
106  /// @brief Child specific update method.
107  virtual void UpdateImpl(bool Force = false);
108  /// @brief Child specific visibility method.
109  virtual void SetVisibleImpl(bool visible);
110  /// @brief Child specific mouse hover method.
111  virtual bool CheckMouseHoverImpl();
112  /// @brief Processes the captured inputs.
113  virtual void ProcessCapturedInputs();
114  //public:
115  /// @brief Class constructor.
116  /// @param name The Name for the Widget.
117  /// @param RendRect The Rect representing the position and size of the widget.
118  /// @param SStyle The layout of buttons this widget will have. See SpinnerStyle enum or class description for more details.
119  /// @param GlyphHeight The desired relative height of the text you want.
120  /// @param parent The parent screen that created this widget.
121  Spinner(const String& name, const Rect& RendRect, const UI::SpinnerStyle& SStyle, const Real& GlyphHeight, Screen* parent);
122  /// @brief Class destructor.
123  virtual ~Spinner();
124  public:
125  /// @brief Sets the current value of this widget.
126  /// @param ValueToSet The value to be set.
127  virtual void SetSpinnerValue(const int& ValueToSet);
128  /// @brief Gets the current value stored in this spinner.
129  /// @return Returns an int, which is the current value within this spinner.
130  virtual int GetSpinnerValue();
131  /// @brief Sets limits on what the value contained in this widget can be.
132  /// @details Setting a limit of zero for both means no limits will be enforced.
133  /// @param Lower The Minimum allowed limit.
134  /// @param Upper The Maximum allowed limit.
135  virtual void SetValueLimits(const int& Lower, const int& Upper);
136  /// @brief Sets whether or not this widget should be allowed to be edited directly.
137  /// @param Edit Whether or not this widget should be editable.
138  virtual void SetEditable(bool Edit);
139  /// @brief Gets whether or not this widget is currently editable.
140  /// @return Return Returns a bool indicating whether or not this widget is editable.
141  virtual bool GetEditable();
142  /// @brief Enables the display of Reals for the value rather then Wholes.
143  /// @details Internally it is still storing wholes, just they are converted before being displayed.
144  /// @param Enable Whether or not to enable this feature.
145  /// @param DecimalPlaces The number of places passed the decimal you wish to display.
146  virtual void EnableDecimalDisplay(bool Enable, const Whole& Places = 1);
147  /// @brief Sets the relative position of this widget.
148  /// @details The position is relative to the screen size. Values range from 0.0 to 1.0.
149  /// @param Position A vector2 representing the relative position of this widget.
150  virtual void SetPosition(const Vector2& Position);
151  /// @brief Sets the pixel position of this widget.
152  /// @param Position A vector2 representing the pixel position of this widget.
153  virtual void SetActualPosition(const Vector2& Position);
154  /// @brief Sets the relative size of this widget.
155  /// @details The size is relative to the screen size. Values range from 0.0 to 1.0.
156  /// @param Size A vector2 representing the relative size of this widget.
157  virtual void SetSize(const Vector2& Size);
158  /// @brief Sets the pixel size of this widget.
159  /// @param Size A vector2 representing the pixel size of this widget.
160  virtual void SetActualSize(const Vector2& Size);
161  /// @brief Updates the dimensions of this widget to match those of the new screen size.
162  /// @details This function is called automatically when a viewport changes in size, and shouldn't need to be called manually.
163  virtual void UpdateDimensions();
164  /// @brief Gets the increment button of this widget.
165  /// @return Returns a pointer to the increment button.
166  virtual Button* GetIncrement();
167  /// @brief Gets the decrement button of this widget.
168  /// @return Returns a pointer to the decrement button.
169  virtual Button* GetDecrement();
170  /// @brief Gets the value display caption of this widget.
171  /// @return Returns a pointer to the value display caption.
172  virtual Caption* GetValueDisplay();
173 
174  ///////////////////////////////////////////////////////////////////////////////
175  // PageProvider Methods
176 
177  /// @copydoc PageProvider::GetMaxXPages() const
178  virtual Real GetMaxXPages() const;
179  /// @copydoc PageProvider::GetMaxYPages() const
180  virtual Real GetMaxYPages() const;
181 
182  /// @copydoc PageProvider::GetCurrentXPage() const
183  virtual Real GetCurrentXPage() const;
184  /// @copydoc PageProvider::GetCurrentYPage() const
185  virtual Real GetCurrentYPage() const;
186 
187  /// @brief Sets which axis is primary when determining page position.
188  /// @param Order Which axis should be considered first when determining the page.
189  virtual void SetOrdering(const UI::OrderingPriority Order);
190  /// @brief Gets which axis is primary when determining page position.
191  /// @return Returns a OrderingPriority representing which axis is considered primary for determining page order.
192  virtual UI::OrderingPriority GetOrdering() const;
193 
194  ///////////////////////////////////////////////////////////////////////////////
195  // Serialization
196 
197  /// @copydoc PageProvider::ProtoSerializePageData(XML::Node&) const
198  virtual void ProtoSerializePageData(XML::Node& SelfRoot) const;
199  /// @copydoc PageProvider::ProtoDeSerializePageData(const XML::Node&)
200  virtual void ProtoDeSerializePageData(const XML::Node& SelfRoot);
201 
202  ///////////////////////////////////////////////////////////////////////////////
203  // Internal Methods
204 
205  /// @copydoc PageProvider::_SetContainer(PagedContainer*)
206  virtual void _SetContainer(PagedContainer* ToUpdate);
207  /// @copydoc PageProvider::_NotifyContainerUpdated()
208  virtual void _NotifyContainerUpdated();//*/
209  };//spinner
210  }//UI
211 }//Mezzanine
212 
213 #endif