BsEditorWidgetContainer.h 6.1 KB

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