guiContainer.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUICONTAINER_H_
  23. #define _GUICONTAINER_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. /// Base class for controls that act as containers to other controls.
  28. ///
  29. /// @addtogroup gui_container_group Containers
  30. ///
  31. /// @ingroup gui_group Gui System
  32. /// @{
  33. class GuiContainer : public GuiControl
  34. {
  35. public:
  36. typedef GuiControl Parent;
  37. enum
  38. {
  39. updateSelf = BIT(1),
  40. updateParent = BIT(2),
  41. updateNone = 0
  42. };
  43. protected:
  44. S32 mUpdateLayout; ///< Layout Update Mask
  45. ControlSizing mSizingOptions; ///< Control Sizing Options
  46. S32 mValidDockingMask;
  47. public:
  48. DECLARE_CONOBJECT(GuiContainer);
  49. DECLARE_CATEGORY( "Gui Containers" );
  50. GuiContainer();
  51. virtual ~GuiContainer();
  52. static void initPersistFields();
  53. /// @name Container Sizing
  54. /// @{
  55. /// Returns the Mask of valid docking modes supported by this container
  56. inline S32 getValidDockingMask() { return mValidDockingMask; };
  57. /// Docking Accessors
  58. inline S32 getDocking() { return mSizingOptions.mDocking; };
  59. virtual void setDocking( S32 docking );
  60. /// Docking Protected Field Setter
  61. static bool setDockingField( void *object, const char *index, const char *data )
  62. {
  63. GuiContainer *pContainer = static_cast<GuiContainer*>(object);
  64. pContainer->setUpdateLayout( updateParent );
  65. return true;
  66. }
  67. inline bool getAnchorTop() const { return mSizingOptions.mAnchorTop; }
  68. inline bool getAnchorBottom() const { return mSizingOptions.mAnchorBottom; }
  69. inline bool getAnchorLeft() const { return mSizingOptions.mAnchorLeft; }
  70. inline bool getAnchorRight() const { return mSizingOptions.mAnchorRight; }
  71. inline void setAnchorTop(bool val) { mSizingOptions.mAnchorTop = val; }
  72. inline void setAnchorBottom(bool val) { mSizingOptions.mAnchorBottom = val; }
  73. inline void setAnchorLeft(bool val) { mSizingOptions.mAnchorLeft = val; }
  74. inline void setAnchorRight(bool val) { mSizingOptions.mAnchorRight = val; }
  75. ControlSizing getSizingOptions() const { return mSizingOptions; }
  76. void setSizingOptions(const ControlSizing& val) { mSizingOptions = val; }
  77. /// @}
  78. /// @name Sizing Constraints
  79. /// @{
  80. virtual const RectI getClientRect();
  81. /// @}
  82. /// @name Control Layout Methods
  83. /// @{
  84. /// Called when the Layout for a Container needs to be updated because of a resize call or a call to setUpdateLayout
  85. /// @param clientRect The Client Rectangle that is available for this Container to layout it's children in
  86. virtual bool layoutControls( RectI &clientRect );
  87. /// Set the layout flag to Dirty on a Container, triggering an update to it's layout on the next onPreRender call.
  88. /// @attention This can be called without regard to whether the flag is already set, as setting it
  89. /// does not actually cause an update, but rather tells the container it should update the next
  90. /// chance it gets
  91. /// @param updateType A Mask that indicates how the layout should be updated.
  92. inline void setUpdateLayout( S32 updateType = updateSelf ) { mUpdateLayout |= updateType; };
  93. /// @}
  94. /// @name Container Sizing Methods
  95. /// @{
  96. /// Dock a Control with the given docking mode inside the given client rect.
  97. /// @attention The clientRect passed in will be modified by the docking of
  98. /// the control. It will return the rect that remains after the docking operation.
  99. virtual bool dockControl( GuiContainer *control, S32 dockingMode, RectI &clientRect );
  100. /// Update a Controls Anchor based on a delta sizing of it's parents extent
  101. /// This function should return true if the control was changed in size or position at all
  102. virtual bool anchorControl( GuiControl *control, const Point2I &deltaParentExtent );
  103. /// @}
  104. /// @name GuiControl Inherited
  105. /// @{
  106. virtual void onChildAdded(GuiControl* control);
  107. virtual void onChildRemoved(GuiControl* control);
  108. virtual bool resize( const Point2I &newPosition, const Point2I &newExtent );
  109. virtual void childResized(GuiControl *child);
  110. virtual void addObject(SimObject *obj);
  111. virtual void removeObject(SimObject *obj);
  112. virtual bool reOrder(SimObject* obj, SimObject* target);
  113. virtual void onPreRender();
  114. /// GuiContainer deals with parentResized calls differently than GuiControl. It will
  115. /// update the layout for all of it's non-docked child controls. parentResized calls
  116. /// on the child controls will be handled by their default functions, but for our
  117. /// purposes we want at least our immediate children to use the anchors that they have
  118. /// set on themselves. - JDD [9/20/2006]
  119. virtual void parentResized(const RectI &oldParentRect, const RectI &newParentRect);
  120. /// @}
  121. };
  122. /// @}
  123. #endif