BsDockManager.h 3.5 KB

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