guiFrameCtrl.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 _GUIFRAMECTRL_H_
  23. #define _GUIFRAMECTRL_H_
  24. #ifndef _GUICONTAINER_H_
  25. #include "gui/containers/guiContainer.h"
  26. #endif
  27. // for debugging porpoises...
  28. #define GUI_FRAME_DEBUG
  29. // ...save the porpoises
  30. /// A gui control allowing a window to be subdivided into panes,
  31. /// each of which displays a gui control child of the
  32. /// GuiFrameSetCtrl. Each gui control child will have an associated
  33. /// FrameDetail through which frame-specific details can be
  34. /// assigned. Frame-specific values override the values specified
  35. /// for the entire frameset.
  36. ///
  37. /// Note that it is possible to have more children than frames,
  38. /// or more frames than children. In the former case, the extra
  39. /// children will not be visible (they are moved beyond the
  40. /// visible extent of the frameset). In the latter case, frames
  41. /// will be empty.
  42. ///
  43. /// If a frameset had two columns and two rows but only three
  44. /// gui control children they would be assigned to frames as
  45. /// follows:
  46. /// 1 | 2
  47. /// -----
  48. /// 3 |
  49. ///
  50. /// The last frame would be blank.
  51. ///
  52. class GuiFrameSetCtrl : public GuiContainer
  53. {
  54. private:
  55. typedef GuiContainer Parent;
  56. public:
  57. enum FrameState
  58. {
  59. FRAME_STATE_ON, // ON overrides OFF
  60. FRAME_STATE_OFF, // OFF overrides AUTO
  61. FRAME_STATE_AUTO, // AUTO == ON, unless overridden
  62. NO_HIT = -1,
  63. DEFAULT_BORDER_WIDTH = 4,
  64. DEFAULT_COLUMNS = 1,
  65. DEFAULT_ROWS = 1,
  66. DEFAULT_MIN_FRAME_EXTENT = 64
  67. };
  68. enum Region
  69. {
  70. VERTICAL_DIVIDER,
  71. HORIZONTAL_DIVIDER,
  72. DIVIDER_INTERSECTION,
  73. NONE
  74. };
  75. struct FrameDetail
  76. {
  77. U32 mBorderWidth;
  78. ColorI mBorderColor;
  79. S32 mBorderEnable;
  80. S32 mBorderMovable;
  81. Point2I mMinExtent;
  82. RectSpacingI mPadding;
  83. FrameDetail() { mBorderWidth = DEFAULT_BORDER_WIDTH; mBorderEnable = FRAME_STATE_AUTO; mBorderMovable = FRAME_STATE_AUTO; mMinExtent.set(DEFAULT_MIN_FRAME_EXTENT, DEFAULT_MIN_FRAME_EXTENT); mPadding.setAll( 0 ); }
  84. };
  85. DECLARE_CONOBJECT(GuiFrameSetCtrl);
  86. DECLARE_DESCRIPTION( "A container that allows to subdivide its space into rows and columns.\n"
  87. "Child controls are assigned to the cells row by row." );
  88. static void initPersistFields();
  89. GuiFrameSetCtrl();
  90. GuiFrameSetCtrl(U32 columns, U32 rows, const U32 columnOffsets[] = NULL, const U32 rowOffsets[] = NULL);
  91. virtual ~GuiFrameSetCtrl();
  92. void addObject(SimObject *obj);
  93. void removeObject(SimObject *obj);
  94. virtual bool resize(const Point2I &newPosition, const Point2I &newExtent);
  95. virtual void onMouseDown(const GuiEvent &event);
  96. virtual void onMouseUp(const GuiEvent &event);
  97. virtual void onMouseDragged(const GuiEvent &event);
  98. bool onAdd();
  99. void onRender(Point2I offset, const RectI &updateRect );
  100. protected:
  101. /* member variables */
  102. Vector<S32> mColumnOffsets;
  103. Vector<S32> mRowOffsets;
  104. FrameDetail mFramesetDetails;
  105. VectorPtr<FrameDetail *> mFrameDetails;
  106. bool mAutoBalance;
  107. S32 mFudgeFactor;
  108. /* divider activation member variables */
  109. Region mCurHitRegion;
  110. Point2I mLocOnDivider;
  111. S32 mCurVerticalHit;
  112. S32 mCurHorizontalHit;
  113. bool init(U32 columns, U32 rows, const U32 columnOffsets[], const U32 rowOffsets[]);
  114. Region findHitRegion(const Point2I &point);
  115. Region pointInAnyRegion(const Point2I &point);
  116. S32 findResizableFrames(S32 indexes[]);
  117. bool hitVerticalDivider(S32 x, const Point2I &point);
  118. bool hitHorizontalDivider(S32 y, const Point2I &point);
  119. virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  120. void rebalance(const Point2I &newExtent);
  121. void computeSizes(bool balanceFrames = false);
  122. void computeMovableRange(Region hitRegion, S32 vertHit, S32 horzHit, S32 numIndexes, const S32 indexes[], S32 ranges[]);
  123. void drawDividers(const Point2I &offset);
  124. public:
  125. U32 columns() const { return(mColumnOffsets.size()); }
  126. U32 rows() const { return(mRowOffsets.size()); }
  127. U32 borderWidth() const { return(mFramesetDetails.mBorderWidth); }
  128. Vector<S32>* columnOffsets() { return(&mColumnOffsets); }
  129. Vector<S32>* rowOffsets() { return(&mRowOffsets); }
  130. FrameDetail* framesetDetails() { return(&mFramesetDetails); }
  131. bool findFrameContents(S32 index, GuiControl **gc, FrameDetail **fd);
  132. void frameBorderEnable(S32 index, const char *state = NULL);
  133. void frameBorderMovable(S32 index, const char *state = NULL);
  134. void frameMinExtent(S32 index, const Point2I &extent);
  135. void framePadding(S32 index, const RectSpacingI &padding);
  136. RectSpacingI getFramePadding(S32 index);
  137. void balanceFrames() { computeSizes(true); }
  138. void updateSizes() { computeSizes(); }
  139. bool onWake();
  140. private:
  141. GuiFrameSetCtrl(const GuiFrameSetCtrl &);
  142. GuiFrameSetCtrl& operator=(const GuiFrameSetCtrl &);
  143. };
  144. typedef GuiFrameSetCtrl::FrameState GuiFrameState;
  145. DefineEnumType( GuiFrameState );
  146. //-----------------------------------------------------------------------------
  147. // x is the first value inside the next column, so the divider x-coords
  148. // precede x.
  149. inline bool GuiFrameSetCtrl::hitVerticalDivider(S32 x, const Point2I &point)
  150. {
  151. return((point.x >= S32(x - mFramesetDetails.mBorderWidth)) && (point.x < x) && (point.y >= 0) && (point.y < S32(getHeight())));
  152. }
  153. //-----------------------------------------------------------------------------
  154. // y is the first value inside the next row, so the divider y-coords precede y.
  155. inline bool GuiFrameSetCtrl::hitHorizontalDivider(S32 y, const Point2I &point)
  156. {
  157. return((point.x >= 0) && (point.x < S32(getWidth())) && (point.y >= S32(y - mFramesetDetails.mBorderWidth)) && (point.y < y));
  158. }
  159. #endif // _GUI_FRAME_CTRL_H