guiRolloutCtrl.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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/guiControl.h"
  26. #endif
  27. #ifndef _H_GUIDEFAULTCONTROLRENDER_
  28. #include "gui/guiDefaultControlRender.h"
  29. #endif
  30. class GuiRolloutCtrl : public GuiControl
  31. {
  32. private:
  33. typedef GuiControl Parent;
  34. public:
  35. // Members
  36. StringTableEntry mCaption;
  37. RectI mHeader;
  38. RectI mExpanded;
  39. RectI mChildRect;
  40. Point2I mMargin;
  41. bool mIsExpanded;
  42. bool mIsAnimating;
  43. bool mCollapsing;
  44. S32 mAnimateDestHeight;
  45. S32 mAnimateStep;
  46. S32 mDefaultHeight;
  47. bool mCanCollapse;
  48. GuiCursor* mDefaultCursor;
  49. GuiCursor* mVertSizingCursor;
  50. // Theme Support
  51. enum
  52. {
  53. CollapsedLeft = 0,
  54. CollapsedCenter,
  55. CollapsedRight,
  56. TopLeftHeader,
  57. TopMidHeader,
  58. TopRightHeader,
  59. MidPageLeft,
  60. MidPageCenter,
  61. MidPageRight,
  62. BottomLeftHeader,
  63. BottomMidHeader,
  64. BottomRightHeader,
  65. NumBitmaps ///< Number of bitmaps in this array
  66. };
  67. bool mHasTexture; ///< Indicates whether we have a texture to render the tabs with
  68. RectI *mBitmapBounds;///< Array of rectangles identifying textures for tab book
  69. // Constructor/Destructor/Conobject Declaration
  70. GuiRolloutCtrl();
  71. ~GuiRolloutCtrl();
  72. DECLARE_CONOBJECT(GuiRolloutCtrl);
  73. // Persistence
  74. static void initPersistFields();
  75. // Control Events
  76. bool onWake();
  77. void addObject(SimObject *obj);
  78. void removeObject(SimObject *obj);
  79. virtual void childResized(GuiControl *child);
  80. // Mouse Events
  81. virtual void onTouchDown( const GuiEvent &event );
  82. virtual void onTouchUp( const GuiEvent &event );
  83. // Sizing Helpers
  84. virtual void calculateHeights();
  85. void resize( const Point2I &newPosition, const Point2I &newExtent );
  86. virtual void sizeToContents();
  87. inline bool isExpanded(){ return mIsExpanded; };
  88. // Sizing Animation Functions
  89. void animateTo( S32 height );
  90. virtual void processTick();
  91. void collapse() { animateTo( mHeader.extent.y ); };
  92. void expand() { animateTo( mExpanded.extent.y ); };
  93. void instantCollapse();
  94. void instantExpand();
  95. // Property - "Collapsed"
  96. static bool setCollapsed(void* obj, const char* data)
  97. {
  98. bool bCollapsed = dAtob( data );
  99. if( bCollapsed )
  100. static_cast<GuiRolloutCtrl*>(obj)->instantCollapse();
  101. else
  102. static_cast<GuiRolloutCtrl*>(obj)->instantExpand();
  103. return false;
  104. };
  105. // Control Rendering
  106. virtual void onRender(Point2I offset, const RectI &updateRect);
  107. bool onAdd();
  108. };
  109. #endif