guiStackCtrl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 _GUISTACKCTRL_H_
  23. #define _GUISTACKCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. #include "gfx/gfxDevice.h"
  28. #include "console/console.h"
  29. #include "console/consoleTypes.h"
  30. /// A stack of GUI controls.
  31. ///
  32. /// This maintains a horizontal or vertical stack of GUI controls. If one is deleted, or
  33. /// resized, then the stack is resized to fit. The order of the stack is
  34. /// determined by the internal order of the children (ie, order of addition).
  35. class GuiStackControl : public GuiControl
  36. {
  37. protected:
  38. typedef GuiControl Parent;
  39. bool mResizing;
  40. S32 mPadding;
  41. S32 mStackHorizSizing; ///< Set from horizSizingOptions.
  42. S32 mStackVertSizing; ///< Set from vertSizingOptions.
  43. S32 mStackingType;
  44. bool mDynamicSize; ///< Resize this control along the stack axis to fit the summed extent of the children (width or height depends on the stack type)
  45. bool mDynamicNonStackExtent; ///< Resize this control along the non-stack axis to fit the max extent of the children (width or height depends on the stack type)
  46. bool mDynamicPos; ///< Reposition this control along the stack axis when it is resized (by mDynamicSize) (left or up depends on the stack type)
  47. bool mChangeChildSizeToFit; ///< Does the child resize to fit i.e. should a horizontal stack resize its children's height to fit?
  48. bool mChangeChildPosition; ///< Do we reset the child's position in the opposite direction we are stacking?
  49. public:
  50. GuiStackControl();
  51. enum StackingType
  52. {
  53. stackingTypeVert, ///< Always stack vertically
  54. stackingTypeHoriz, ///< Always stack horizontally
  55. stackingTypeDyn ///< Dynamically switch based on width/height
  56. };
  57. enum HorizontalType
  58. {
  59. horizStackLeft = 0,///< Stack from left to right when horizontal
  60. horizStackRight, ///< Stack from right to left when horizontal
  61. };
  62. enum VerticalType
  63. {
  64. vertStackTop, ///< Stack from top to bottom when vertical
  65. vertStackBottom, ///< Stack from bottom to top when vertical
  66. };
  67. bool resize(const Point2I &newPosition, const Point2I &newExtent);
  68. void childResized(GuiControl *child);
  69. bool isFrozen() { return mResizing; };
  70. /// prevent resizing. useful when adding many items.
  71. void freeze(bool);
  72. bool onWake();
  73. void onSleep();
  74. void updatePanes();
  75. virtual void stackVertical(bool fromTop);
  76. virtual void stackHorizontal(bool fromLeft);
  77. S32 getCount() { return size(); }; /// Returns the number of children in the stack
  78. void addObject(SimObject *obj);
  79. void removeObject(SimObject *obj);
  80. bool reOrder(SimObject* obj, SimObject* target = 0);
  81. static void initPersistFields();
  82. DECLARE_CONOBJECT(GuiStackControl);
  83. DECLARE_CATEGORY( "Gui Containers" );
  84. DECLARE_DESCRIPTION( "A container that stacks its children horizontally or vertically." );
  85. };
  86. typedef GuiStackControl::StackingType GuiStackingType;
  87. typedef GuiStackControl::HorizontalType GuiHorizontalStackingType;
  88. typedef GuiStackControl::VerticalType GuiVerticalStackingType;
  89. DefineEnumType( GuiStackingType );
  90. DefineEnumType( GuiHorizontalStackingType );
  91. DefineEnumType( GuiVerticalStackingType );
  92. #endif