BsDockManager.h 3.4 KB

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