BsEditorWidgetContainer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsEvent.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A GUI object that contains one or multiple editor widgets.
  8. * Each widget is represented by a single tab and can be activated,
  9. * deactivated, moved or dragged off.
  10. *
  11. * @note Internal class.
  12. */
  13. class BS_ED_EXPORT EditorWidgetContainer
  14. {
  15. public:
  16. EditorWidgetContainer(CGUIWidget* parent, EditorWindowBase* parentEditorWindow);
  17. virtual ~EditorWidgetContainer();
  18. /**
  19. * @brief Adds a new widget to the container, adding a new tab to
  20. * the end of the tab bar.
  21. */
  22. void add(EditorWidgetBase& widget);
  23. /**
  24. * @brief Removes a widget from the container.
  25. */
  26. void remove(EditorWidgetBase& widget);
  27. /**
  28. * @brief Inserts a widget at the specified index, adding a new
  29. * tab at that position.
  30. *
  31. * @param idx Sequential index where to insert the widget.
  32. * @param widget Widget to insert.
  33. */
  34. void insert(UINT32 idx, EditorWidgetBase& widget);
  35. /**
  36. * @brief Checks if the container already contains the provided widget.
  37. */
  38. bool contains(EditorWidgetBase& widget);
  39. /**
  40. * @brief Sets the size of the container in pixels. This also modifies
  41. * the size of all child widgets.
  42. */
  43. void setSize(UINT32 width, UINT32 height);
  44. /**
  45. * @brief Sets the position of the container, relative to the parent
  46. * GUI widget. This also modifies the position of all child widgets.
  47. */
  48. void setPosition(INT32 x, INT32 y);
  49. /**
  50. * @brief Returns the number of widgets currently docked in this container.
  51. */
  52. UINT32 getNumWidgets() const { return (UINT32)mWidgets.size(); }
  53. /**
  54. * @brief Returns a widget at the specified index.
  55. *
  56. * @param idx Sequential index of the widget to retrieve.
  57. */
  58. EditorWidgetBase* getWidget(UINT32 idx) const;
  59. /**
  60. * @brief Returns a widget that is currently visible (its tab is active).
  61. */
  62. EditorWidgetBase* getActiveWidget() const;
  63. /**
  64. * @brief Returns the parent GUI widget the container is using to render the GUI on.
  65. */
  66. CGUIWidget& getParentWidget() const { return *mParent; }
  67. /**
  68. * @brief Returns the parent editor window the container is docked in.
  69. */
  70. EditorWindowBase* getParentWindow() const { return mParentWindow; }
  71. /**
  72. * @brief Returns bounds not including the tabbed title bar. These are the bounds
  73. * available to child widget GUI.
  74. */
  75. Rect2I getContentBounds() const;
  76. /**
  77. * @brief Returns a list of areas that can be dragged off. These are normally areas
  78. * represented by tab buttons.
  79. */
  80. Vector<Rect2I> getDraggableAreas() const;
  81. /**
  82. * @brief Called once per frame. Calls update on all docked widgets.
  83. */
  84. void update();
  85. /**
  86. * @brief Updates the tabbed title bar by refreshing the names of all docked widgets.
  87. */
  88. void refreshWidgetNames();
  89. /**
  90. * @brief Triggers when a widget is about to be destroyed.
  91. */
  92. void _notifyWidgetDestroyed(EditorWidgetBase* widget);
  93. Event<void()> onWidgetAdded; /**< Triggered whenever a new widget is added to this container. */
  94. Event<void()> onWidgetClosed; /**< Triggered whenever a widget docked in this container is closed. */
  95. Event<void()> onMaximized; /**< Triggered when the maximize button is clicked. */
  96. private:
  97. EditorWindowBase* mParentWindow;
  98. GUITabbedTitleBar* mTitleBar;
  99. GUIPanel* mTitleBarPanel;
  100. CGUIWidget* mParent;
  101. INT32 mX, mY;
  102. UINT32 mWidth, mHeight;
  103. UnorderedMap<UINT32, EditorWidgetBase*> mWidgets;
  104. INT32 mActiveWidget;
  105. static const UINT32 TitleBarHeight;
  106. /**
  107. * @brief Removes a widget without triggering a widget closed event.
  108. */
  109. void removeInternal(EditorWidgetBase& widget);
  110. /**
  111. * @brief Changes the currently active widget to the one at the specified index. Making
  112. * the widget active means it will be visible in the container.
  113. *
  114. * @param idx Unique widget index (not sequential).
  115. */
  116. void setActiveWidget(UINT32 idx);
  117. /**
  118. * @brief Triggered when a user clicks on a tab in the tabbed title bar.
  119. *
  120. * @param idx Unique widget index (not sequential) of the tab that was activated.
  121. */
  122. void tabActivated(UINT32 idx);
  123. /**
  124. * @brief Triggered when a user closes a tab in the tabbed title bar.
  125. *
  126. * @param idx Unique widget index (not sequential) of the tab that was closed.
  127. */
  128. void tabClosed(UINT32 idx);
  129. /**
  130. * @brief Triggered when a user clicks the maximize button on the title bar.
  131. *
  132. * @param idx Unique widget index (not sequential) of the tab that was closed.
  133. */
  134. void tabMaximized(UINT32 idx);
  135. /**
  136. * @brief Triggered when a user drags a tab off the tabbed title bar.
  137. *
  138. * @param idx Unique widget index (not sequential) of the tab that was dragged off.
  139. */
  140. void tabDraggedOff(UINT32 idx);
  141. /**
  142. * @brief Triggered when a user drags a tab on the tabbed title bar.
  143. *
  144. * @param idx Sequential index at the position on which the tab has been dragged on.
  145. */
  146. void tabDraggedOn(UINT32 idx);
  147. /**
  148. * @brief Triggered when the widget drag and drop operation finishes.
  149. *
  150. * @param wasDragProcessed Signals whether any object handled the drop.
  151. */
  152. static void tabDroppedCallback(bool wasDragProcessed);
  153. };
  154. }