BsDockManager.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. protected:
  76. ~DockManager();
  77. void updateClippedBounds();
  78. private:
  79. DockManager(RenderWindow* parentWindow, const GUILayoutOptions& layoutOptions);
  80. static const Color TINT_COLOR;
  81. static const Color HIGHLIGHT_COLOR;
  82. RenderWindow* mParentWindow;
  83. DockContainer mRootContainer;
  84. RectI mArea;
  85. HMesh mDropOverlayMesh;
  86. HMaterial mDropOverlayMat;
  87. RectI mLastOverlayBounds;
  88. DockContainer* mMouseOverContainer;
  89. DockLocation mHighlightedDropLoc;
  90. bool mShowOverlay;
  91. Vector2* mTopDropPolygon;
  92. Vector2* mBotDropPolygon;
  93. Vector2* mLeftDropPolygon;
  94. Vector2* mRightDropPolygon;
  95. bool mAddedRenderCallback;
  96. void updateDropOverlay(INT32 x, INT32 y, UINT32 width, UINT32 height);
  97. bool mouseEvent(const GUIMouseEvent& event);
  98. bool insidePolygon(Vector2* polyPoints, UINT32 numPoints, Vector2 point) const;
  99. void _changeParentWidget(GUIWidget* widget);
  100. };
  101. }