Spinning Topp Logo BlackTopp Studios
inc
scrollbar.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 _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  ///////////////////////////////////////////////////////////////////////////////
60  // Public Data Members
61 
62  /// @brief The pre-update value of the calling scrollbar.
64  /// @brief The post-update value of the calling scrollbar.
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  // Construction and Destruction
69 
70  /// @brief Class constructor.
71  /// @param Name The name of the event being fired.
72  /// @param Source The identification of the widget firing this event.
73  /// @param OldValue The pre-update value of the calling scrollbar.
74  /// @param NewValue The post-update value of the calling scrollbar.
75  ScrollbarValueChangedArguments(const String& Name, const String& Source, const Real& OldValue, const Real& NewValue) :
76  WidgetEventArguments(Name,Source), OldScrollerValue(OldValue), NewScrollerValue(NewValue) { }
77  /// @brief Class destructor.
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // CountedPtr Functionality
82 
83  /// @copydoc EventArguments::GetMostDerived()
85  { return this; }
86  };//ScrollbarValueChangedArguments
87  }//UI
88 
89  ///////////////////////////////////////////////////////////////////////////////
90  /// @brief This is a metaprogramming traits class used by ScrollbarValueChangedArguments.
91  /// @details This is need for an intrusive CountedPtr implementation. Should a working external reference count be made this
92  /// could be dropped in favor of a leaner implementation.
93  ///////////////////////////////////////
94  template <>
95  class ReferenceCountTraits<UI::ScrollbarValueChangedArguments>
96  {
97  public:
98  /// @brief Typedef communicating the reference count type to be used.
100 
101  /// @brief Method responsible for creating a reference count for a CountedPtr of the templated type.
102  /// @param Target A pointer to the target class that is to be reference counted.
103  /// @return Returns a pointer to a new reference counter for the templated type.
104  static RefCountType* ConstructionPointer(RefCountType* Target)
105  { return Target; }
106 
107  /// @brief Enum used to decide the type of casting to be used by a reference counter of the templated type.
108  enum { IsCastable = CastStatic };
109  };//ReferenceCountTraits<ScrollbarValueChangedArguments>
110 
111  namespace UI
112  {
113  /// @brief Convenience typedef for passing around ScrollbarValueChangedArguments.
115 
116  ///////////////////////////////////////////////////////////////////////////////
117  /// @brief This is the scrollbar base class.
118  /// @details If you want to have buttons to accompany your scrollbar they'll automatically
119  /// have their height match the width of the scrollbar if it's vertical, or their width
120  /// match their height of the scrollbar if it's horizontal, based on the dimensions provided. @n @n
121  /// Scrollbars can come in a few styles. Separate is the typical way to present them with the Up
122  /// or Left button being located at the top of left side of the scroller respectively. Together
123  /// is where both scroll buttons are next to each other instead of on opposite sides of the
124  /// scroller.
125  ///////////////////////////////////////
127  {
128  public:
129  /// @brief String containing the type name for this class: "Scrollbar".
130  static const String TypeName;
131  /// @brief Event name for when this scrollbar has his scrollvalue updated.
133  protected:
134  /// @internal
135  /// @brief The manipulatable widget that represents the current position on the scrollbar/slider.
137  /// @internal
138  /// @brief The background around that can be clicked on and represents the valid bounds for the scroller.
140  /// @internal
141  /// @brief The Up/Left button that when clicked will move the scroller in that respective direction.
142  /// @remarks Depending on the button configuration this can be NULL for the lifetime of the widget.
144  /// @internal
145  /// @brief The Down/Right button that when clicked will move the scroller in that respective direction.
146  /// @remarks Depending on the button configuration this can be NULL for the lifetime of the widget.
148  /// @internal
149  /// @brief This is a pointer to the specific child that is locked and being manipulated.
151  /// @internal
152  /// @brief The distance the scroller is to be moved when the up, left, down, or right buttons are clicked.
154  /// @internal
155  /// @brief The size of the scroller on the appropriate axis relative to the ScrollBack.
157  /// @internal
158  /// @brief Stores whether or not this scrollbar should hide when there is 1 page or less of list items. Only used when this is set as a PageProvider.
160 
161  /// @copydoc Widget::HandleInputImpl(const Input::MetaCode&)
162  virtual Boole HandleInputImpl(const Input::MetaCode& Code);
163  /// @internal
164  /// @brief Subscribes to all the events of this scrollbars children we care about. Used only on construction.
165  virtual void SubscribeToChildEvents();
166  /// @internal
167  /// @brief Gets the range on which the scroller can be placed.
168  /// @return Returns the UpperScrollLimit minus the LowerScrollLimit.
169  virtual Real GetScrollRange() const;
170  /// @internal
171  /// @brief Gets the pixel position of the upper limit the scroller can be placed on.
172  /// @return Returns a Real representing the scrollers upper limit.
173  virtual Real GetUpperScrollLimit() const = 0;
174  /// @internal
175  /// @brief Gets the pixel position of the lower limit the scroller can be placed on.
176  /// @return Returns a Real representing the scrollers limit limit.
177  virtual Real GetLowerScrollLimit() const = 0;
178  public:
179  /// @brief Blank constructor.
180  /// @param Parent The parent screen that created this scrollbar.
181  Scrollbar(Screen* Parent);
182  /// @brief Standard initialization constructor.
183  /// @param RendName The name to be given to this scrollbar.
184  /// @param Parent The parent screen that created this scrollbar.
185  Scrollbar(const String& RendName, Screen* Parent);
186  /// @brief Rect constructor.
187  /// @param RendName The name to be given to this scrollbar.
188  /// @param RendRect The rect describing this widget's transform relative to it's parent.
189  /// @param Parent The parent screen that created this scrollbar.
190  Scrollbar(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
191  /// @brief Standard class destructor.
192  virtual ~Scrollbar();
193 
194  ///////////////////////////////////////////////////////////////////////////////
195  // Utility Methods
196 
197  /// @brief Sets the value of this scrollbar and warps the scroller to that respective position.
198  /// @param Value The value to be set for this scrollbar. Range: 0.0 to 1.0.
199  virtual void SetScrollerValue(const Real& Value) = 0;
200  /// @brief Get the currnent scroll position represented by a value between 0 and 1.
201  /// @details For example, if the scroller is halfway down the limits it's allowed, this will return 0.5. @n
202  /// Like other values, the top and left represent origin(0) values.
203  /// @return Returns the stored scroll position.
204  virtual Real GetScrollerValue() const = 0;
205 
206  /// @brief Sets the length(or height) of the scroller based on the relative size of it's background.
207  /// @param Size The relative size you with to set the scroller to. Range: 0.0 to 1.0
208  virtual void SetScrollerSize(const Real& Size) = 0;
209  /// @brief Gets the size of the scroller relative to the ScrollBack.
210  /// @return Returns a Real representing size of the scroller on the relevant axis relative to the ScrollBack.
211  virtual Real GetScrollerSize() const = 0;
212 
213  /// @brief Sets the relative distance the scroller will move when the up/left or down/right buttons are pressed.
214  /// @remarks Default: 0.1.
215  /// @param IncDist A real representing the amount to increment. Can be negative.
216  virtual void SetIncrementDistance(const Real& IncDist);
217  /// @brief Gets the relative distance the scroller will move on a button press.
218  /// @return Returns a Real representing the relative distance to be moved on a button press.
219  virtual Real GetIncrementDistance() const;
220 
221  /// @brief Sets whether or not this scrollbar will hide when it's set page container has less than one page to display.
222  /// @param AutoHide True to make this hide when this scrollbars page container doesn't have more than one page to display, false to make this always visible.
223  virtual void SetAutoHide(Boole AutoHide);
224  /// @brief Gets whether or not this scrollbar will hide when it's set page container has less than one page to display.
225  /// @return Returns true if this scrollbar is hiding when it's page container has less then one page to display, false if it's always visible.
226  virtual Boole GetAutoHide() const;
227 
228  ///////////////////////////////////////////////////////////////////////////////
229  // Fetch Methods
230 
231  /// @brief Gets the Scroller button within this widget.
232  /// @return Returns a pointer to the Scroller button within this widget.
233  virtual Button* GetScroller() const;
234  /// @brief Gets the UpLeft button within this widget, if it was initialized.
235  /// @return Returns a pointer to the UpLeft button within this widget, or NULL if none.
236  virtual Button* GetUpLeftButton() const;
237  /// @brief Gets the DownRight button within this widget, if it was initialized.
238  /// @return Returns a pointer to the DownRight button within this widget, or NULL if none.
239  virtual Button* GetDownRightButton() const;
240  /// @brief Gets the Scroller background within this widget.
241  /// @return Returns a pointer to the Scroller background within this widget.
242  virtual Button* GetScrollBack() const;
243 
244  ///////////////////////////////////////////////////////////////////////////////
245  // Serialization
246 
247  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
248  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
249  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
250  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
251 
252  /// @copydoc Renderable::GetSerializableName()
253  static String GetSerializableName();
254 
255  ///////////////////////////////////////////////////////////////////////////////
256  // Internal Event Methods
257 
258  /// @brief Self logic to be executed when this scrollbar changes it's scrollvalue.
259  /// @param OldValue The previous value of this scrollbar.
260  /// @param NewValue The updated value of this scrollbar.
261  virtual void _OnScrollValueChanged(const Real OldValue, const Real NewValue);
262 
263  ///////////////////////////////////////////////////////////////////////////////
264  // Internal Methods
265 
266  /// @copydoc EventSubscriber::_NotifyEvent(EventArgumentsPtr Args)
267  virtual void _NotifyEvent(EventArgumentsPtr Args);
268  /// @internal
269  /// @brief Performs the operations for when the scroller is directly manipulated by the mouse.
270  /// @param MouseDelta The amount in pixels the mouse has moved since the last frame.
271  /// @return Returns true if the scroller was successfully moved, false otherwise.
272  virtual Boole _MouseScroll(const Vector2& MouseDelta) = 0;
273  /// @internal
274  /// @brief Performs the operations for when the scroller is manipulated by the mouse wheel.
275  /// @param Direction The direction of the mouse wheel spin. Usually this will be a casted Input::DirectionalMotionState value.
276  /// @return Returns true if the scroller was successfully moved, false otherwise.
277  virtual Boole _MouseWheelScroll(const Integer Direction) = 0;
278  /// @internal
279  /// @brief Performs the operations for when the scrollback is clicked on to manipulate the scroller.
280  /// @param HitPosition The location on the scroll back where the mouse was clicked (in screen coordinates).
281  /// @return Returns true if the scroller was successfully moved, false otherwise.
282  virtual Boole _ScrollBackScroll(const Vector2& HitPosition) = 0;
283  /// @internal
284  /// @brief Performs the operations for when one of the buttons is pressed to manipulate the scroller.
285  /// @param TheButton The button that was activated (or to simulate an activation for).
286  /// @return Returns true if the scroller was successfully moved, false otherwise.
287  virtual Boole _ButtonScroll(Button* TheButton) = 0;
288  };//Scrollbar
289  }//UI
290 }//Mezzanine
291 
292 #endif
293 
virtual ~ScrollbarValueChangedArguments()
Class destructor.
Definition: scrollbar.h:78
static RefCountType * ConstructionPointer(RefCountType *Target)
Method responsible for creating a reference count for a CountedPtr of the templated type...
Definition: scrollbar.h:104
Button * ScrollBack
The background around that can be clicked on and represents the valid bounds for the scroller...
Definition: scrollbar.h:139
Button * Scroller
The manipulatable widget that represents the current position on the scrollbar/slider.
Definition: scrollbar.h:136
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual ScrollbarValueChangedArguments * GetMostDerived()
Get a pointer to the most Derived type of this instance.
Definition: scrollbar.h:84
CountedPtr< ScrollbarValueChangedArguments > ScrollbarValueChangedArgumentsPtr
Convenience typedef for passing around ScrollbarValueChangedArguments.
Definition: scrollbar.h:114
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
A simple reference counting pointer.
Definition: countedptr.h:70
Real ScrollerSize
The size of the scroller on the appropriate axis relative to the ScrollBack.
Definition: scrollbar.h:156
const Real NewScrollerValue
The post-update value of the calling scrollbar.
Definition: scrollbar.h:65
This is the EventArguments class for when the scrollvalue of a scrollbar is updated.
Definition: scrollbar.h:56
static const String TypeName
String containing the type name for this class: "Scrollbar".
Definition: scrollbar.h:130
Button * DownRightButton
The Down/Right button that when clicked will move the scroller in that respective direction...
Definition: scrollbar.h:147
ScrollbarValueChangedArguments(const String &Name, const String &Source, const Real &OldValue, const Real &NewValue)
Class constructor.
Definition: scrollbar.h:75
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
This is the scrollbar base class.
Definition: scrollbar.h:126
static const String EventScrollValueChanged
Event name for when this scrollbar has his scrollvalue updated.
Definition: scrollbar.h:132
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 used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
const Real OldScrollerValue
The pre-update value of the calling scrollbar.
Definition: scrollbar.h:63
A static cast from the pointer as provided with no attempt to calls functions on the pointer target...
Definition: countedptr.h:63
UI::ScrollbarValueChangedArguments RefCountType
Typedef communicating the reference count type to be used.
Definition: scrollbar.h:99
This Determines the kind of user input.
Definition: metacode.h:93
This is the base class for interpretting widget values to page positions.
Definition: pageprovider.h:55
Real IncrementDistance
The distance the scroller is to be moved when the up, left, down, or right buttons are clicked...
Definition: scrollbar.h:153
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
Boole AutoHideScroll
Stores whether or not this scrollbar should hide when there is 1 page or less of list items...
Definition: scrollbar.h:159
Button * UpLeftButton
The Up/Left button that when clicked will move the scroller in that respective direction.
Definition: scrollbar.h:143
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
This class is a helper class, specifically for use as a button.
Definition: button.h:66
Button * ChildLock
This is a pointer to the specific child that is locked and being manipulated.
Definition: scrollbar.h:150
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 the base class for widget specific event arguments.
Definition: widget.h:60