guiGridCtrl.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef _GUIGRIDCTRL_H_
  2. #define _GUIGRIDCTRL_H_
  3. #ifndef _GUICONTROL_H_
  4. #include "gui/guiControl.h"
  5. #endif
  6. #ifndef _VECTOR2_H_
  7. #include "2d/core/Vector2.h"
  8. #endif
  9. #include "graphics/dgl.h"
  10. #include "console/console.h"
  11. #include "console/consoleTypes.h"
  12. class GuiGridCtrl : public GuiControl
  13. {
  14. private:
  15. typedef GuiControl Parent;
  16. Point2I mCalcCellExt;
  17. Point2I mCalcCellSpace;
  18. U16 mCalcChainLength;
  19. U32 mRunningChainHeight;
  20. U32 mCurrentChainHeight;
  21. U8 mChainNumber;
  22. bool mResizeGuard;
  23. public:
  24. enum CellMode
  25. {
  26. Absolute,
  27. Variable,
  28. Percent
  29. };
  30. CellMode mCellModeX, mCellModeY;
  31. F32 mCellSizeX, mCellSizeY;
  32. F32 mCellSpacingX, mCellSpacingY;
  33. S32 mMaxColCount, mMaxRowCount;
  34. //LRTB means Left to Right, Top to Bottom (the normal way we read english)
  35. enum OrderMode
  36. {
  37. LRTB,
  38. RLTB,
  39. TBLR,
  40. TBRL,
  41. LRBT,
  42. RLBT,
  43. BTLR,
  44. BTRL
  45. };
  46. OrderMode mOrderMode;
  47. bool mIsExtentDynamic;
  48. private:
  49. void AdjustGrid(const Point2I& innerExtent);
  50. Point2F GetGridItemWidth(const S32 totalArea, const S32 maxChainLength, const F32 itemSize, const F32 spaceSize, const CellMode cellMode);
  51. Point2F GetGridItemHeight(const S32 totalArea, const S32 maxChainLength, const F32 itemSize, const F32 spaceSize, const CellMode cellMode);
  52. Point2I getCellPosition(U16 num, const Point2I &innerExtent, GuiControl *ctrl);
  53. Point2I getCellExtent(GuiControl *ctrl);
  54. inline bool IsVertical() { return mOrderMode == LRTB || mOrderMode == RLTB || mOrderMode == LRBT || mOrderMode == RLBT; }
  55. inline bool HasVariableChainHeight() { return (mCellModeX == Variable && !IsVertical()) || (mCellModeY == Variable && IsVertical()); }
  56. public:
  57. GuiGridCtrl();
  58. void resize(const Point2I &newPosition, const Point2I &newExtent);
  59. //void childResized(GuiControl *child);
  60. void inspectPostApply();
  61. bool onWake();
  62. void onSleep();
  63. void onChildAdded(GuiControl* child);
  64. void onChildRemoved(GuiControl* child);
  65. void childResized(GuiControl* child);
  66. void childMoved(GuiControl* child);
  67. void childrenReordered();
  68. void setCellSize(F32 width, F32 height);
  69. inline Vector2 getCellSize(void) const { return Vector2(mCellSizeX, mCellSizeY); }
  70. void setCellSpacing(F32 x, F32 y);
  71. inline Vector2 getCellSpacing(void) const { return Vector2(mCellSpacingX, mCellSpacingY); }
  72. void setCellModeX(const CellMode mode);
  73. void setCellModeY(const CellMode mode);
  74. inline CellMode getCellModeX(void) const { return mCellModeX; }
  75. inline CellMode getCellModeY(void) const { return mCellModeY; }
  76. static CellMode getCellModeEnum(const char* label);
  77. static const char* getCellModeDescription(const CellMode mode);
  78. inline void setMaxColCount(S32 max) { mMaxColCount = max; resize(getPosition(), getExtent()); }
  79. inline void setMaxRowCount(S32 max) { mMaxRowCount = max; resize(getPosition(), getExtent()); }
  80. inline S32 getMaxColCount(void) const { return mMaxColCount; }
  81. inline S32 getMaxRowCount(void) const { return mMaxRowCount; }
  82. inline OrderMode getOrderMode(void) const { return mOrderMode; }
  83. static const char* getOrderModeDescription(const OrderMode mode);
  84. inline bool getIsExtentDynamic(void) { return mIsExtentDynamic; }
  85. static void initPersistFields();
  86. DECLARE_CONOBJECT(GuiGridCtrl);
  87. };
  88. #endif // _GUIGRIDCTRL_H_