MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scrollbar.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 _uiscrollbar_h
41 #define _uiscrollbar_h
42 
43 #include "uienumerations.h"
44 #include "UI/pageprovider.h"
45 #include "UI/widgetfactory.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  class Button;
52  ///////////////////////////////////////////////////////////////////////////////
53  /// @brief This is the EventArguments class for when the scrollvalue of a scrollbar is updated.
54  /// @details
55  ///////////////////////////////////////
57  {
58  public:
59  /// @brief The pre-update value of the calling scrollbar.
61  /// @brief The post-update value of the calling scrollbar.
63 
64  /// @brief Class constructor.
65  /// @param Name The name of the event being fired.
66  /// @param Source The identification of the widget firing this event.
67  /// @param OldValue The pre-update value of the calling scrollbar.
68  /// @param NewValue The post-update value of the calling scrollbar.
69  ScrollbarValueChangedArguments(const String& Name, const String& Source, const Real& OldValue, const Real& NewValue)
70  : WidgetEventArguments(Name,Source), OldScrollerValue(OldValue), NewScrollerValue(NewValue) { }
71  /// @brief Class destructor.
73  };//ScrollbarValueChangedArguments
74 
75  ///////////////////////////////////////////////////////////////////////////////
76  /// @brief This is the scrollbar base class.
77  /// @details If you want to have buttons to accompany your scrollbar they'll automatically
78  /// have their height match the width of the scrollbar if it's vertical, or their width
79  /// match their height of the scrollbar if it's horizontal, based on the dimensions provided. @n @n
80  /// Scrollbars can come in a few styles. Separate is the typical way to present them with the Up
81  /// or Left button being located at the top of left side of the scroller respectively. Together
82  /// is where both scroll buttons are next to each other instead of on opposite sides of the
83  /// scroller.
84  ///////////////////////////////////////
86  {
87  public:
88  /// @brief String containing the type name for this class: "Scrollbar".
89  static const String TypeName;
90  /// @brief Event name for when this scrollbar has his scrollvalue updated.
92  protected:
93  /// @internal
94  /// @brief The manipulatable widget that represents the current position on the scrollbar/slider.
96  /// @internal
97  /// @brief The background around that can be clicked on and represents the valid bounds for the scroller.
99  /// @internal
100  /// @brief The Up/Left button that when clicked will move the scroller in that respective direction.
101  /// @remarks Depending on the button configuration this can be NULL for the lifetime of the widget.
103  /// @internal
104  /// @brief The Down/Right button that when clicked will move the scroller in that respective direction.
105  /// @remarks Depending on the button configuration this can be NULL for the lifetime of the widget.
107  /// @internal
108  /// @brief This is a pointer to the specific child that is locked and being manipulated.
110  /// @internal
111  /// @brief The distance the scroller is to be moved when the up, left, down, or right buttons are clicked.
113 
114  /// @copydoc Widget::HandleInputImpl(const Input::MetaCode&)
115  virtual bool HandleInputImpl(const Input::MetaCode& Code);
116  /// @internal
117  /// @brief Subscribes to all the events of this scrollbars children we care about. Used only on construction.
118  virtual void SubscribeToChildEvents();
119  /// @internal
120  /// @brief Gets the range on which the scroller can be placed.
121  /// @return Returns the UpperScrollLimit minus the LowerScrollLimit.
122  virtual Real GetScrollRange() const;
123  /// @internal
124  /// @brief Gets the pixel position of the upper limit the scroller can be placed on.
125  /// @return Returns a Real representing the scrollers upper limit.
126  virtual Real GetUpperScrollLimit() const = 0;
127  /// @internal
128  /// @brief Gets the pixel position of the lower limit the scroller can be placed on.
129  /// @return Returns a Real representing the scrollers limit limit.
130  virtual Real GetLowerScrollLimit() const = 0;
131  /// @internal
132  /// @brief Performs the operations for when the scroller is directly manipulated by the mouse.
133  /// @return Returns true if the scroller was successfully moved, false otherwise.
134  virtual bool MouseScroll(const Vector2& MouseDelta) = 0;
135  /// @internal
136  /// @brief Performs the operations for when the scrollback is clicked on to manipulate the scroller.
137  /// @param HitPosition The location on the scroll back where the mouse was clicked (in screen coordinates).
138  /// @return Returns true if the scroller was successfully moved, false otherwise.
139  virtual bool ScrollBackScroll(const Vector2& HitPosition) = 0;
140  /// @internal
141  /// @brief Performs the operations for when one of the buttons is pressed to manipulate the scroller.
142  /// @return Returns true if the scroller was successfully moved, false otherwise.
143  virtual bool ButtonScroll(Button* TheButton) = 0;
144  //public:
145  /// @brief Blank constructor.
146  /// @param Parent The parent screen that created this scrollbar.
147  Scrollbar(Screen* Parent);
148  /// @brief Standard initialization constructor.
149  /// @param RendName The name to be given to this scrollbar.
150  /// @param Parent The parent screen that created this scrollbar.
151  Scrollbar(const String& RendName, Screen* Parent);
152  /// @brief Rect constructor.
153  /// @param RendName The name to be given to this scrollbar.
154  /// @param RendRect The rect describing this widget's transform relative to it's parent.
155  /// @param Parent The parent screen that created this scrollbar.
156  Scrollbar(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
157  /// @brief Standard class destructor.
158  virtual ~Scrollbar();
159  public:
160  ///////////////////////////////////////////////////////////////////////////////
161  // Utility Methods
162 
163  /// @brief Sets the value of this scrollbar and warps the scroller to that respective position.
164  /// @param Value The value to be set for this scrollbar. Range: 0.0 to 1.0.
165  virtual void SetScrollerValue(const Real& Value) = 0;
166  /// @brief Get the currnent scroll position represented by a value between 0 and 1.
167  /// @details For example, if the scroller is halfway down the limits it's allowed, this will return 0.5. @n
168  /// Like other values, the top and left represent origin(0) values.
169  /// @return Returns the stored scroll position.
170  virtual Real GetScrollerValue() const = 0;
171  /// @brief Sets the length(or height) of the scroller based on the relative size of it's background.
172  /// @param Size The relative size you with to set the scroller to. Range: 0.0 to 1.0
173  virtual void SetScrollerSize(const Real& Size) = 0;
174  /// @brief Gets the size of the scroller relative to the ScrollBack.
175  /// @return Returns a Real representing size of the scroller on the relevant axis relative to the ScrollBack.
176  virtual Real GetScrollerSize() const = 0;
177  /// @brief Sets the relative distance the scroller will move when the up/left or down/right buttons are pressed.
178  /// @remarks Default: 0.1.
179  /// @param IncDist A real representing the amount to increment. Can be negative.
180  virtual void SetIncrementDistance(const Real& IncDist);
181  /// @brief Gets the relative distance the scroller will move on a button press.
182  /// @return Returns a Real representing the relative distance to be moved on a button press.
183  virtual Real GetIncrementDistance() const;
184 
185  ///////////////////////////////////////////////////////////////////////////////
186  // Fetch Methods
187 
188  /// @brief Gets the Scroller button within this widget.
189  /// @return Returns a pointer to the Scroller button within this widget.
190  virtual Button* GetScroller() const;
191  /// @brief Gets the UpLeft button within this widget, if it was initialized.
192  /// @return Returns a pointer to the UpLeft button within this widget, or NULL if none.
193  virtual Button* GetUpLeftButton() const;
194  /// @brief Gets the DownRight button within this widget, if it was initialized.
195  /// @return Returns a pointer to the DownRight button within this widget, or NULL if none.
196  virtual Button* GetDownRightButton() const;
197  /// @brief Gets the Scroller background within this widget.
198  /// @return Returns a pointer to the Scroller background within this widget.
199  virtual Button* GetScrollBack() const;
200 
201  ///////////////////////////////////////////////////////////////////////////////
202  // Serialization
203 
204  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
205  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
206  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
207  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
208 
209  /// @copydoc Renderable::GetSerializableName()
210  static String GetSerializableName();
211 
212  ///////////////////////////////////////////////////////////////////////////////
213  // Internal Event Methods
214 
215  /// @brief Self logic to be executed when this scrollbar changes it's scrollvalue is.
216  /// @param OldValue The previous value of this scrollbar.
217  /// @param NewValue The updated value of this scrollbar.
218  virtual void _OnScrollValueChanged(const Real OldValue, const Real NewValue);
219 
220  ///////////////////////////////////////////////////////////////////////////////
221  // Internal Methods
222 
223  /// @copydoc EventSubscriber::_NotifyEvent(const EventArguments& Args)
224  virtual void _NotifyEvent(const EventArguments& Args);
225  };//Scrollbar
226  }//UI
227 }//Mezzanine
228 
229 #endif
230