BsDockManager.h 3.5 KB

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