guiGridCtrl.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. public:
  23. enum CellMode
  24. {
  25. Absolute,
  26. Variable,
  27. Percent
  28. };
  29. CellMode mCellModeX, mCellModeY;
  30. F32 mCellSizeX, mCellSizeY;
  31. F32 mCellSpacingX, mCellSpacingY;
  32. S32 mMaxColCount, mMaxRowCount;
  33. //LRTB means Left to Right, Top to Bottom (the normal way we read english)
  34. enum OrderMode
  35. {
  36. LRTB,
  37. RLTB,
  38. TBLR,
  39. TBRL,
  40. LRBT,
  41. RLBT,
  42. BTLR,
  43. BTRL
  44. };
  45. OrderMode mOrderMode;
  46. bool mIsExtentDynamic;
  47. private:
  48. void AdjustGrid(const Point2I& innerExtent);
  49. Point2F GetGridItemWidth(const S32 totalArea, const S32 maxChainLength, const F32 itemSize, const F32 spaceSize, const CellMode cellMode);
  50. Point2F GetGridItemHeight(const S32 totalArea, const S32 maxChainLength, const F32 itemSize, const F32 spaceSize, const CellMode cellMode);
  51. Point2I getCellPosition(U16 num, const Point2I &innerExtent, GuiControl *ctrl);
  52. Point2I getCellExtent(GuiControl *ctrl);
  53. inline bool IsVertical() { return mOrderMode == LRTB || mOrderMode == RLTB || mOrderMode == LRBT || mOrderMode == RLBT; }
  54. inline bool HasVariableChainHeight() { return (mCellModeX == Variable && !IsVertical()) || (mCellModeY == Variable && IsVertical()); }
  55. public:
  56. GuiGridCtrl();
  57. void resize(const Point2I &newPosition, const Point2I &newExtent);
  58. //void childResized(GuiControl *child);
  59. void inspectPostApply();
  60. bool onWake();
  61. void onSleep();
  62. void onChildAdded(GuiControl *child);
  63. void onChildRemoved(SimObject *child);
  64. void setCellSize(F32 width, F32 height);
  65. inline Vector2 getCellSize(void) const { return Vector2(mCellSizeX, mCellSizeY); }
  66. void setCellSpacing(F32 x, F32 y);
  67. inline Vector2 getCellSpacing(void) const { return Vector2(mCellSpacingX, mCellSpacingY); }
  68. void setCellModeX(const CellMode mode);
  69. void setCellModeY(const CellMode mode);
  70. inline CellMode getCellModeX(void) const { return mCellModeX; }
  71. inline CellMode getCellModeY(void) const { return mCellModeY; }
  72. static CellMode getCellModeEnum(const char* label);
  73. static const char* getCellModeDescription(const CellMode mode);
  74. inline void setMaxColCount(S32 max) { mMaxColCount = max; resize(getPosition(), getExtent()); }
  75. inline void setMaxRowCount(S32 max) { mMaxRowCount = max; resize(getPosition(), getExtent()); }
  76. inline S32 getMaxColCount(void) const { return mMaxColCount; }
  77. inline S32 getMaxRowCount(void) const { return mMaxRowCount; }
  78. inline OrderMode getOrderMode(void) const { return mOrderMode; }
  79. static const char* getOrderModeDescription(const OrderMode mode);
  80. inline bool getIsExtentDynamic(void) { return mIsExtentDynamic; }
  81. static void initPersistFields();
  82. DECLARE_CONOBJECT(GuiGridCtrl);
  83. };
  84. #endif // _GUIGRIDCTRL_H_