BsDockManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsRect2I.h"
  5. namespace BansheeEngine
  6. {
  7. enum class DockLocation
  8. {
  9. Left, Right, Top, Bottom, Center
  10. };
  11. class DockManager : public GUIElementContainer
  12. {
  13. public:
  14. class DockContainer
  15. {
  16. public:
  17. DockContainer(DockManager* manager);
  18. DockContainer(DockManager* manager, DockContainer* parent);
  19. ~DockContainer();
  20. void setArea(INT32 x, INT32 y, UINT32 width, UINT32 height);
  21. void makeLeaf(GUIWidget* widgetParent, EditorWindowBase* parentWindow);
  22. void makeLeaf(EditorWidgetContainer* existingContainer);
  23. void splitContainer(bool horizontal, bool newChildIsFirst, float splitPosition = 0.5f);
  24. void makeSplit(GUIWidget* widgetParent, DockManager::DockContainer* first, DockManager::DockContainer* second, bool horizontal, float splitPosition);
  25. void addLeft(EditorWidgetBase* widget);
  26. void addRight(EditorWidgetBase* widget);
  27. void addTop(EditorWidgetBase* widget);
  28. void addBottom(EditorWidgetBase* widget);
  29. void addWidget(EditorWidgetBase* widget);
  30. void addWidget(const String& name);
  31. void update();
  32. DockContainer* find(EditorWidgetContainer* widgetContainer);
  33. /**
  34. * @brief Searches for a DockContainer at the specified position.
  35. *
  36. * @param pos Position in the same space as DockContainer.
  37. *
  38. * @return null if it fails, else the found DockContainer at position.
  39. */
  40. DockContainer* findAtPos(const Vector2I& pos);
  41. Rect2I getContentBounds() const;
  42. bool mIsLeaf;
  43. DockContainer* mChildren[2];
  44. DockContainer* mParent;
  45. DockManager* mManager;
  46. EditorWidgetContainer* mWidgets;
  47. GUIDockSlider* mSlider;
  48. Rect2I mArea;
  49. float mSplitPosition;
  50. bool mIsHorizontal;
  51. static const UINT32 SLIDER_SIZE;
  52. static const UINT32 MIN_CHILD_SIZE;
  53. private:
  54. void updateChildAreas();
  55. void sliderDragged(const Vector2I& delta);
  56. void widgetRemoved();
  57. };
  58. enum class DockLocation
  59. {
  60. Top,
  61. Bottom,
  62. Left,
  63. Right,
  64. None
  65. };
  66. public:
  67. static DockManager* create(EditorWindowBase* parentWindow);
  68. /**
  69. * @brief Internal method. Called once every frame.
  70. */
  71. void update();
  72. void render(const Viewport* viewport, DrawList& renderQueue);
  73. void insert(EditorWidgetContainer* relativeTo, EditorWidgetBase* widgetToInsert, DockLocation location);
  74. DockManagerLayoutPtr getLayout() const;
  75. void setLayout(const DockManagerLayoutPtr& layout);
  76. void setArea(INT32 x, INT32 y, UINT32 width, UINT32 height);
  77. void closeAll();
  78. protected:
  79. ~DockManager();
  80. void updateClippedBounds();
  81. private:
  82. DockManager(EditorWindowBase* parentWindow, const GUILayoutOptions& layoutOptions);
  83. static const Color TINT_COLOR;
  84. static const Color HIGHLIGHT_COLOR;
  85. EditorWindowBase* mParentWindow;
  86. DockContainer mRootContainer;
  87. Rect2I mArea;
  88. HMesh mDropOverlayMesh;
  89. HMaterial mDropOverlayMat;
  90. Rect2I mLastOverlayBounds;
  91. DockContainer* mMouseOverContainer;
  92. DockLocation mHighlightedDropLoc;
  93. bool mShowOverlay;
  94. Vector2* mTopDropPolygon;
  95. Vector2* mBotDropPolygon;
  96. Vector2* mLeftDropPolygon;
  97. Vector2* mRightDropPolygon;
  98. HEvent mRenderCallback;
  99. void updateDropOverlay(INT32 x, INT32 y, UINT32 width, UINT32 height);
  100. bool mouseEvent(const GUIMouseEvent& event);
  101. bool insidePolygon(Vector2* polyPoints, UINT32 numPoints, Vector2 point) const;
  102. };
  103. }