guiRolloutCtrl.h 5.8 KB

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