guiAutoScrollCtrl.h
Engine/source/gui/containers/guiAutoScrollCtrl.h
Classes:
class
A control that automatically scrolls its child control upwards.
Public Typedefs
GuiAutoScrollDirection
Public Functions
Detailed Description
Public Typedefs
typedef GuiAutoScrollCtrl::Direction GuiAutoScrollDirection
Public Functions
DefineEnumType(GuiAutoScrollDirection )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _GUIAUTOSCROLLCTRL_H_ 25#define _GUIAUTOSCROLLCTRL_H_ 26 27#ifndef _GUICONTROL_H_ 28 #include "gui/core/guiControl.h" 29#endif 30#ifndef _GUITICKCTRL_H_ 31 #include "gui/shiny/guiTickCtrl.h" 32#endif 33 34 35/// A control that automatically scrolls its child control upwards. 36class GuiAutoScrollCtrl : public GuiTickCtrl 37{ 38 public: 39 40 typedef GuiTickCtrl Parent; 41 42 /// Scrolling direction. 43 enum Direction 44 { 45 Up, 46 Down, 47 Left, 48 Right 49 }; 50 51 protected: 52 53 enum Phase 54 { 55 PhaseInitial, ///< Waiting to begin scrolling. 56 PhaseScrolling, ///< Currently scrolling. 57 PhaseComplete, ///< Scrolling complete. 58 PhaseWait ///< Wait before starting a new loop. 59 }; 60 61 /// The direction in which to scroll. 62 Direction mDirection; 63 64 /// If true, scrolling will start from the beginning once finished. 65 bool mIsLooping; 66 67 /// Whether to scroll the child control completely out of sight. 68 bool mScrollOutOfSight; 69 70 /// Current phase in the scrolling animation. 71 Phase mCurrentPhase; 72 73 /// The current animation time. 74 F32 mCurrentTime; 75 76 /// The time scrolling was completed. 77 F32 mCompleteTime; 78 79 /// Current scrolling position. This is kept separate from the control's 80 /// current position value since we will receive time updates in increments 81 /// less than a second and thus need to have this value in floating-point. 82 F32 mCurrentPosition; 83 84 /// Seconds to wait before starting to scroll. 85 F32 mStartDelay; 86 87 /// Seconds to wait after scrolling is complete before reseting the control 88 /// to the initial state (only if #mIsLooping is true). 89 F32 mResetDelay; 90 91 /// Border to put around scrolled child control. 92 S32 mChildBorder; 93 94 /// Speed at which to scroll in pixels per second. 95 F32 mScrollSpeed; 96 97 /// @name Callbacks 98 /// @{ 99 100 DECLARE_CALLBACK( void, onTick, () ); 101 DECLARE_CALLBACK( void, onStart, () ); 102 DECLARE_CALLBACK( void, onComplete, () ); 103 DECLARE_CALLBACK( void, onReset, () ); 104 105 /// @} 106 107 void _reset( GuiControl* control ); 108 bool _isScrollComplete() const; 109 110 U32 _getScrollAxis() const 111 { 112 switch( mDirection ) 113 { 114 case Up: return 1; 115 case Down: return 1; 116 case Left: return 0; 117 case Right: return 0; 118 } 119 return 0; 120 } 121 122 F32 _getScrollAmount() const 123 { 124 switch( mDirection ) 125 { 126 case Up: return - mScrollSpeed; 127 case Down: return mScrollSpeed; 128 case Left: return - mScrollSpeed; 129 case Right: return mScrollSpeed; 130 } 131 return 0.f; 132 } 133 134 public: 135 136 GuiAutoScrollCtrl(); 137 138 void reset(); 139 140 virtual bool onWake(); 141 virtual void onSleep(); 142 143 virtual void onChildAdded( GuiControl* control ); 144 virtual void onChildRemoved( GuiControl* control ); 145 virtual bool resize( const Point2I& newPosition, const Point2I& newExtent ); 146 virtual void childResized( GuiControl *child ); 147 148 virtual void processTick(); 149 virtual void advanceTime( F32 timeDelta ); 150 virtual void inspectPostApply(); 151 152 static void initPersistFields(); 153 154 DECLARE_CONOBJECT( GuiAutoScrollCtrl ); 155 DECLARE_CATEGORY( "Gui Containers" ); 156 DECLARE_DESCRIPTION( "A container that automatically scrolls its child control upwards.\n" 157 "Can be used, for example, for credits screens." ); 158}; 159 160typedef GuiAutoScrollCtrl::Direction GuiAutoScrollDirection; 161DefineEnumType( GuiAutoScrollDirection ); 162 163#endif 164