guiFrameCtrl.h 7.1 KB

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