BsDockManager.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "CmRectI.h"
  5. namespace BansheeEditor
  6. {
  7. enum class DockLocation
  8. {
  9. Left, Right, Top, Bottom, Center
  10. };
  11. class DockManager : public BS::GUIElementContainer
  12. {
  13. public:
  14. class DockContainer
  15. {
  16. public:
  17. DockContainer();
  18. DockContainer(DockContainer* parent);
  19. ~DockContainer();
  20. void setArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
  21. void makeLeaf(BS::GUIWidget* widgetParent, CM::RenderWindow* parentWindow);
  22. void makeLeaf(EditorWidgetContainer* existingContainer);
  23. void splitContainer(BS::GUIWidget* widgetParent, CM::RenderWindow* parentWindow, bool horizontal, bool newChildIsFirst, float splitPosition = 0.5f);
  24. void addLeft(BS::GUIWidget* widgetParent, CM::RenderWindow* parentWindow, EditorWidgetBase* widget);
  25. void addRight(BS::GUIWidget* widgetParent, CM::RenderWindow* parentWindow, EditorWidgetBase* widget);
  26. void addTop(BS::GUIWidget* widgetParent, CM::RenderWindow* parentWindow, EditorWidgetBase* widget);
  27. void addBottom(BS::GUIWidget* widgetParent, CM::RenderWindow* parentWindow, EditorWidgetBase* widget);
  28. void addWidget(EditorWidgetBase* widget);
  29. void addWidget(const CM::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 CM::Vector2I& pos);
  39. CM::RectI getContentBounds() const;
  40. bool mIsLeaf;
  41. DockContainer* mChildren[2];
  42. DockContainer* mParent;
  43. EditorWidgetContainer* mWidgets;
  44. GUIDockSlider* mSlider;
  45. CM::RectI mArea;
  46. float mSplitPosition;
  47. bool mIsHorizontal;
  48. static const CM::UINT32 SLIDER_SIZE;
  49. static const CM::UINT32 MIN_CHILD_SIZE;
  50. private:
  51. void updateChildAreas();
  52. void sliderDragged(const CM::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(BS::GUIWidget& parent, CM::RenderWindow* parentWindow);
  65. /**
  66. * @brief Internal method. Called once every frame.
  67. */
  68. void update();
  69. void render(const CM::Viewport* viewport, CM::RenderQueue& renderQueue);
  70. void insert(EditorWidgetContainer* relativeTo, EditorWidgetBase* widgetToInsert, DockLocation location);
  71. DockManagerLayoutPtr getLayout() const;
  72. void setLayout(const DockManagerLayoutPtr& layout);
  73. void setArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
  74. protected:
  75. ~DockManager();
  76. void updateClippedBounds();
  77. private:
  78. DockManager(BS::GUIWidget& parent, CM::RenderWindow* parentWindow, const BS::GUILayoutOptions& layoutOptions);
  79. static const CM::Color TINT_COLOR;
  80. static const CM::Color HIGHLIGHT_COLOR;
  81. CM::RenderWindow* mParentWindow;
  82. DockContainer mRootContainer;
  83. CM::RectI mArea;
  84. CM::HMesh mDropOverlayMesh;
  85. CM::HMaterial mDropOverlayMat;
  86. CM::RectI mLastOverlayBounds;
  87. DockContainer* mMouseOverContainer;
  88. DockLocation mHighlightedDropLoc;
  89. bool mShowOverlay;
  90. CM::Vector2* mTopDropPolygon;
  91. CM::Vector2* mBotDropPolygon;
  92. CM::Vector2* mLeftDropPolygon;
  93. CM::Vector2* mRightDropPolygon;
  94. void updateDropOverlay(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
  95. bool mouseEvent(const BS::GUIMouseEvent& event);
  96. bool insidePolygon(CM::Vector2* polyPoints, CM::UINT32 numPoints, CM::Vector2 point) const;
  97. };
  98. }