BsDockManager.h 3.0 KB

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