guiContainer.h

Engine/source/gui/containers/guiContainer.h

More...

Classes:

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
 24#ifndef _GUICONTAINER_H_
 25#define _GUICONTAINER_H_
 26
 27#ifndef _GUICONTROL_H_
 28   #include "gui/core/guiControl.h"
 29#endif
 30
 31
 32/// Base class for controls that act as containers to other controls.
 33///
 34/// @addtogroup gui_container_group Containers
 35///
 36/// @ingroup gui_group Gui System
 37/// @{
 38class  GuiContainer : public GuiControl
 39{
 40   public:
 41   
 42      typedef GuiControl Parent;
 43   
 44      enum 
 45      {
 46         updateSelf = BIT(1),
 47         updateParent = BIT(2),
 48         updateNone = 0
 49      };
 50
 51   protected:
 52
 53      S32 mUpdateLayout; ///< Layout Update Mask
 54      ControlSizing mSizingOptions; ///< Control Sizing Options
 55      S32 mValidDockingMask;
 56      
 57   public:
 58   
 59      DECLARE_CONOBJECT(GuiContainer);
 60      DECLARE_CATEGORY( "Gui Containers" );
 61
 62      GuiContainer();
 63      virtual ~GuiContainer();
 64
 65      static void initPersistFields();
 66
 67      /// @name Container Sizing
 68      /// @{
 69
 70      /// Returns the Mask of valid docking modes supported by this container
 71      inline S32 getValidDockingMask() { return mValidDockingMask; };
 72
 73      /// Docking Accessors
 74      inline S32 getDocking() { return mSizingOptions.mDocking; };
 75      virtual void setDocking( S32 docking );
 76
 77      /// Docking Protected Field Setter
 78      static bool setDockingField( void *object, const char *index, const char *data )
 79      {
 80         GuiContainer *pContainer = static_cast<GuiContainer*>(object);
 81         pContainer->setUpdateLayout( updateParent );
 82         return true;
 83      }
 84
 85      inline bool getAnchorTop() const { return mSizingOptions.mAnchorTop; }
 86      inline bool getAnchorBottom() const { return mSizingOptions.mAnchorBottom; }
 87      inline bool getAnchorLeft() const { return mSizingOptions.mAnchorLeft; }
 88      inline bool getAnchorRight() const { return mSizingOptions.mAnchorRight; }
 89      inline void setAnchorTop(bool val) { mSizingOptions.mAnchorTop = val; }
 90      inline void setAnchorBottom(bool val) { mSizingOptions.mAnchorBottom = val; }
 91      inline void setAnchorLeft(bool val) { mSizingOptions.mAnchorLeft = val; }
 92      inline void setAnchorRight(bool val) { mSizingOptions.mAnchorRight = val; }
 93
 94      ControlSizing getSizingOptions() const { return mSizingOptions; }
 95      void setSizingOptions(const ControlSizing& val) { mSizingOptions = val; }
 96
 97      /// @}   
 98
 99      /// @name Sizing Constraints
100      /// @{
101      virtual const RectI getClientRect();
102      /// @}
103
104      /// @name Control Layout Methods
105      /// @{
106
107      /// Called when the Layout for a Container needs to be updated because of a resize call or a call to setUpdateLayout
108      /// @param   clientRect The Client Rectangle that is available for this Container to layout it's children in
109      virtual bool layoutControls( RectI &clientRect );
110
111      /// Set the layout flag to Dirty on a Container, triggering an update to it's layout on the next onPreRender call.
112      ///  @attention This can be called without regard to whether the flag is already set, as setting it
113      ///    does not actually cause an update, but rather tells the container it should update the next
114      ///    chance it gets
115      /// @param   updateType   A Mask that indicates how the layout should be updated.
116      inline void setUpdateLayout( S32 updateType = updateSelf ) { mUpdateLayout |= updateType; };
117
118      /// @}
119
120      /// @name Container Sizing Methods
121      /// @{
122
123      /// Dock a Control with the given docking mode inside the given client rect.
124      /// @attention The clientRect passed in will be modified by the docking of 
125      ///    the control.  It will return the rect that remains after the docking operation.
126      virtual bool dockControl( GuiContainer *control, S32 dockingMode, RectI &clientRect );
127      
128      /// Update a Controls Anchor based on a delta sizing of it's parents extent
129      /// This function should return true if the control was changed in size or position at all
130      virtual bool anchorControl( GuiControl *control, const Point2I &deltaParentExtent );
131      
132      /// @}
133
134      /// @name GuiControl Inherited
135      /// @{
136      
137      virtual void onChildAdded(GuiControl* control);
138      virtual void onChildRemoved(GuiControl* control);
139      virtual bool resize( const Point2I &newPosition, const Point2I &newExtent );
140      virtual void childResized(GuiControl *child);
141      virtual void addObject(SimObject *obj);
142      virtual void removeObject(SimObject *obj);
143      virtual bool reOrder(SimObject* obj, SimObject* target);
144      virtual void onPreRender();
145      
146      /// GuiContainer deals with parentResized calls differently than GuiControl.  It will
147      /// update the layout for all of it's non-docked child controls.  parentResized calls
148      /// on the child controls will be handled by their default functions, but for our
149      /// purposes we want at least our immediate children to use the anchors that they have
150      /// set on themselves. - JDD [9/20/2006]
151      virtual void parentResized(const RectI &oldParentRect, const RectI &newParentRect);
152      
153      /// @}
154};
155/// @}
156#endif
157