BsDockManager.h 3.3 KB

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