Torque3D Documentation / _generateds / guiRolloutCtrl.h

guiRolloutCtrl.h

Engine/source/gui/containers/guiRolloutCtrl.h

More...

Classes:

class

A container with an optional header that allows its child control to be collapsed using an animated effet.

Detailed Description

  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#ifndef _GUI_ROLLOUTCTRL_H_
 24#define _GUI_ROLLOUTCTRL_H_
 25
 26#ifndef _GUICONTROL_H_
 27   #include "gui/core/guiControl.h"
 28#endif
 29#ifndef _GUISTACKCTRL_H_
 30   #include "gui/containers/guiStackCtrl.h"
 31#endif
 32#ifndef _H_GUIDEFAULTCONTROLRENDER_
 33   #include "gui/core/guiDefaultControlRender.h"
 34#endif
 35#ifndef _GUITICKCTRL_H_
 36   #include "gui/shiny/guiTickCtrl.h"
 37#endif
 38
 39
 40/// A container with an optional header that allows its child control to
 41/// be collapsed using an animated effet.
 42class GuiRolloutCtrl : public GuiTickCtrl
 43{
 44   public:
 45   
 46      typedef GuiControl Parent;
 47
 48      // Theme Support
 49      enum
 50      {
 51         CollapsedLeft = 0,
 52         CollapsedCenter,
 53         CollapsedRight,
 54         TopLeftHeader,
 55         TopMidHeader,      
 56         TopRightHeader,  
 57         MidPageLeft,
 58         MidPageCenter,
 59         MidPageRight,
 60         BottomLeftHeader, 
 61         BottomMidHeader,   
 62         BottomRightHeader,   
 63         NumBitmaps           ///< Number of bitmaps in this array
 64      };
 65
 66   protected:
 67
 68      /// Label to display on rollout header.
 69      String mCaption;
 70      
 71      RectI mHeader;
 72      RectI mExpanded;
 73      RectI mChildRect;
 74      RectI mMargin;
 75      bool mIsExpanded;
 76      bool mIsAnimating;
 77      bool mCollapsing;
 78      S32 mAnimateDestHeight;
 79      S32 mAnimateStep;
 80      S32 mDefaultHeight;
 81      
 82      /// Whether the rollout can be collapsed.
 83      bool mCanCollapse;
 84      
 85      /// Whether to hide the rollout header.
 86      bool mHideHeader;
 87      
 88      /// Whether to automatically collapse sibling rollouts when this one
 89      /// is expanded.
 90      bool mAutoCollapseSiblings;
 91
 92      GuiCursor*  mDefaultCursor;
 93      GuiCursor*  mVertSizingCursor;
 94
 95      /// Indicates whether we have a texture to render the tabs with.
 96      bool mHasTexture;
 97      
 98      /// Array of rectangles identifying textures for rollout.
 99      RectI *mBitmapBounds;
100
101      // Property - "Expanded"
102      static bool setExpanded( void *object, const char *index, const char *data )  
103      { 
104         bool expand = dAtob( data );
105         if( expand )
106            static_cast<GuiRolloutCtrl*>(object)->instantExpand();         
107         else
108            static_cast<GuiRolloutCtrl*>(object)->instantCollapse();         
109         return false; 
110      };
111      
112      bool _onMouseUp( const GuiEvent& event, bool lockedMouse );
113      
114      /// @name Callbacks
115      /// @{
116      DECLARE_CALLBACK( void, onHeaderRightClick, () );
117
118      DECLARE_CALLBACK( void, onExpanded, () );
119
120      DECLARE_CALLBACK( void, onCollapsed, () );
121      /// @}
122      virtual void processTick();
123
124   public:
125   
126      GuiRolloutCtrl();
127      ~GuiRolloutCtrl();
128
129      DECLARE_CONOBJECT(GuiRolloutCtrl);
130      DECLARE_CATEGORY( "Gui Containers" );
131      DECLARE_DESCRIPTION( "A container that displays a header with a caption on top of its child control\n"
132         "that when clicked collapses/expands the control to/from just the header." );
133
134      // Persistence
135      static void initPersistFields();
136
137      // Control Events
138      bool onWake();
139      void addObject(SimObject *obj);
140      void removeObject(SimObject *obj);
141      virtual void childResized(GuiControl *child);
142
143      // Mouse Events
144      virtual void onMouseDown( const GuiEvent& event );
145      virtual void onMouseUp( const GuiEvent& event );
146      virtual void onRightMouseUp( const GuiEvent& event );
147      virtual bool onMouseUpEditor( const GuiEvent& event, Point2I offset );
148
149      // Sizing Helpers
150      virtual void calculateHeights();
151      virtual bool resize( const Point2I &newPosition, const Point2I &newExtent );
152      virtual void sizeToContents();
153      inline bool isExpanded() const { return mIsExpanded; }
154
155      // Sizing Animation Functions
156      void animateTo( S32 height );
157
158      void collapse() { animateTo( mHeader.extent.y ); }
159      void expand() { animateTo( mExpanded.extent.y ); }
160      void instantCollapse();
161      void instantExpand();
162      void toggleExpanded( bool instant );
163
164      const String& getCaption() const { return mCaption; }
165      bool isHeaderHidden() const { return mHideHeader; }
166      bool canCollapse() const { return mCanCollapse; }
167
168      void setCaption( const String& str ) { mCaption = str; }
169      void setMargin( const RectI& rect ) { mMargin = rect; }
170      void setMargin( S32 left, S32 top, S32 right, S32 bottom ) { setMargin( RectI( left, top, right, bottom ) ); }
171      
172      void setHeaderHidden( bool value ) { mHideHeader = value; }
173      void setCanCollapse( bool value ) { mCanCollapse = value; }
174
175      // Control Rendering
176      virtual void onRender(Point2I offset, const RectI &updateRect);
177      bool onAdd();
178};
179
180#endif // _GUI_ROLLOUTCTRL_H_
181