BsDockManager.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. namespace BansheeEditor
  4. {
  5. enum class DockLocation
  6. {
  7. Left, Right, Top, Bottom, Center
  8. };
  9. class DockManager
  10. {
  11. class DockContainer
  12. {
  13. public:
  14. DockContainer();
  15. ~DockContainer();
  16. void setArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
  17. void makeLeaf(BS::GUIWidget* widgetParent, EditorWidget* widget);
  18. void addLeft(BS::GUIWidget* widgetParent, EditorWidget* widget);
  19. void addRight(BS::GUIWidget* widgetParent, EditorWidget* widget);
  20. void addTop(BS::GUIWidget* widgetParent, EditorWidget* widget);
  21. void addBottom(BS::GUIWidget* widgetParent, EditorWidget* widget);
  22. DockContainer* find(EditorWidgetContainer* widgetContainer);
  23. /**
  24. * @brief Searches for a DockContainer at the specified position.
  25. *
  26. * @param pos Position in the same space as DockContainer.
  27. *
  28. * @return null if it fails, else the found DockContainer at position.
  29. */
  30. DockContainer* findAtPos(const CM::Int2& pos);
  31. bool mIsLeaf;
  32. DockContainer* mChildren[2];
  33. EditorWidgetContainer* mWidgets;
  34. CM::INT32 mX, mY;
  35. CM::UINT32 mWidth, mHeight;
  36. float mSplitPosition;
  37. bool mIsHorizontal;
  38. static const CM::UINT32 SliderSize;
  39. private:
  40. void splitContainer(BS::GUIWidget* widgetParent, EditorWidget* widget, bool horizontal, bool newChildIsFirst);
  41. };
  42. enum class DockLocation
  43. {
  44. Top,
  45. Bottom,
  46. Left,
  47. Right,
  48. None
  49. };
  50. public:
  51. DockManager(BS::GUIWidget* parent);
  52. ~DockManager();
  53. void render(const CM::Viewport* viewport, CM::RenderQueue& renderQueue);
  54. void insert(EditorWidgetContainer* relativeTo, EditorWidget* widgetToInsert, DockLocation location);
  55. void setArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
  56. private:
  57. static const CM::Color TINT_COLOR;
  58. static const CM::Color HIGHLIGHT_COLOR;
  59. BS::GUIWidget* mParent;
  60. DockContainer mRootContainer;
  61. CM::HMesh mDropOverlayMesh;
  62. CM::HMaterial mDropOverlayMat;
  63. DockContainer* mMouseOverContainer;
  64. DockLocation mHighlightedDropLoc;
  65. CM::Vector2* mTopDropPolygon;
  66. CM::Vector2* mBotDropPolygon;
  67. CM::Vector2* mLeftDropPolygon;
  68. CM::Vector2* mRightDropPolygon;
  69. void updateDropOverlay(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
  70. void onGUIMouseEvent(BS::GUIWidget* widget, BS::GUIElement* element, const BS::GUIMouseEvent& event);
  71. bool insidePolygon(CM::Vector2* polyPoints, CM::UINT32 numPoints, CM::Vector2 point) const;
  72. };
  73. }