BsGUITabbedTitleBar.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 "BsGUIElementContainer.h"
  6. #include "BsRect2I.h"
  7. #include "BsEvent.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Tabbed title bar to be used in editor windows. Displays tabs that can
  12. * be activated, reordered by dragging, or dragged off and on to/on other title bars.
  13. */
  14. class GUITabbedTitleBar : public GUIElementContainer
  15. {
  16. public:
  17. /**
  18. * Returns type name of the GUI element used for finding GUI element styles.
  19. */
  20. static const String& getGUITypeName();
  21. /**
  22. * @brief Creates a new GUI foldout element.
  23. *
  24. * @param backgroundStyle GUI style to display the background in. Keep as blank for default.
  25. * @param backgroundStyle GUI style to display the tab buttons in. Keep as blank for default.
  26. * @param maxBtnStyle GUI style to display the maximize button in. Keep as blank for default.
  27. * @param closeBtnStyle GUI style to display the close button in. Keep as blank for default.
  28. */
  29. static GUITabbedTitleBar* create(const String& backgroundStyle = StringUtil::BLANK, const String& tabBtnStyle = StringUtil::BLANK,
  30. const String& maxBtnStyle = StringUtil::BLANK, const String& closeBtnStyle = StringUtil::BLANK);
  31. /**
  32. * @brief Creates a new GUI foldout element.
  33. *
  34. *
  35. * @param options Options that allow you to control how is the element positioned and sized.
  36. * This will override any similar options set by style.
  37. * @param backgroundStyle GUI style to display the background in. Keep as blank for default.
  38. * @param backgroundStyle GUI style to display the tab buttons in. Keep as blank for default.
  39. * @param maxBtnStyle GUI style to display the maximize button in. Keep as blank for default.
  40. * @param closeBtnStyle GUI style to display the close button in. Keep as blank for default.
  41. */
  42. static GUITabbedTitleBar* create(const GUIOptions& options,
  43. const String& backgroundStyle = StringUtil::BLANK, const String& tabBtnStyle = StringUtil::BLANK,
  44. const String& maxBtnStyle = StringUtil::BLANK, const String& closeBtnStyle = StringUtil::BLANK);
  45. /**
  46. * @brief Adds a new tab to the end of the tab list.
  47. *
  48. * @param name Title to display on the tab button.
  49. *
  50. * @returns A unique index (not sequential) that you may use for later identifying the tab.
  51. */
  52. UINT32 addTab(const HString& name);
  53. /**
  54. * @brief Inserts a new tab button at the specified position.
  55. *
  56. * @param position Sequential index to insert the tab button in. This will be clamped
  57. * to a valid range.
  58. * @param name Title to display on the tab button.
  59. *
  60. * @returns A unique index (not sequential) that you may use for later identifying the tab.
  61. */
  62. UINT32 insertTab(UINT32 position, const HString& name);
  63. /**
  64. * @brief Removes the tab button with the specified unique index.
  65. */
  66. void removeTab(UINT32 uniqueIdx);
  67. /**
  68. * @brief Activates the tab button with the specified unique index.
  69. */
  70. void setActive(UINT32 uniqueIdx);
  71. /**
  72. * @brief Finds the unique tab index from the provided sequential tab position.
  73. */
  74. UINT32 getTabIdx(UINT32 position) const;
  75. /**
  76. * @brief Returns the total number of display tab buttons.
  77. */
  78. UINT32 getNumTabs() const { return (UINT32)mTabButtons.size(); }
  79. /**
  80. * @brief Changes the displayed title for a tab with the specified index.
  81. */
  82. void updateTabName(UINT32 uniqueIdx, const HString& name);
  83. /**
  84. * @brief Calculates areas between the tab buttons and other GUI elements on the title bar.
  85. * These areas are normally used for setting up valid areas the user can click on and drag
  86. * the window the title bar belongs to.
  87. */
  88. Vector<Rect2I> calcDraggableAreas(INT32 x, INT32 y, UINT32 width, UINT32 height) const;
  89. /**
  90. * @brief Triggered when the active tab changes. Provided parameter is the
  91. * unique index of the activated tab.
  92. */
  93. Event<void(UINT32)> onTabActivated;
  94. /**
  95. * @brief Triggered when a tab is closed. Provided parameter is the
  96. * unique index of the closed tab.
  97. */
  98. Event<void(UINT32)> onTabClosed;
  99. /**
  100. * @brief Triggered when a tab maximize button is clicked. Provided parameter is the
  101. * unique index of the maximized/restored tab.
  102. */
  103. Event<void(UINT32)> onTabMaximized;
  104. /**
  105. * @brief Triggered when a tab gets dragged off the title bar. Provided
  106. * parameter is the unique index of the activated tab.
  107. */
  108. Event<void(UINT32)> onTabDraggedOff;
  109. /**
  110. * @brief Triggered when a new tab gets dragged on the title bar. Provided
  111. * parameter is the sequential index of the activated tab.
  112. */
  113. Event<void(UINT32)> onTabDraggedOn;
  114. protected:
  115. GUITabbedTitleBar(const String& backgroundStyle, const String& tabBtnStyle,
  116. const String& minBtnStyle, const String& closeBtnStyle, const GUIDimensions& dimensions);
  117. virtual ~GUITabbedTitleBar();
  118. /**
  119. * @copydoc GUIElementContainer::updateClippedBounds
  120. */
  121. void updateClippedBounds() override;
  122. /**
  123. * @copydoc GUIElementContainer::_getOptimalSize
  124. */
  125. Vector2I _getOptimalSize() const override;
  126. /**
  127. * @copydoc GUIElementContainer::_updateLayoutInternal
  128. */
  129. void _updateLayoutInternal(const GUILayoutData& data) override;
  130. /**
  131. * @copydoc GUIElementContainer::_mouseEvent
  132. */
  133. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  134. /**
  135. * @brief Starts the internal drag and drop operation.
  136. *
  137. * @param seqIdx Sequential index of the dragged tab.
  138. * @param startDragPos Pointer position of where the drag originated, relative
  139. * to parent widget.
  140. */
  141. void startDrag(UINT32 seqIdx, const Vector2I& startDragPos);
  142. /**
  143. * @brief Ends the internal drag and drop operation started with ::startDrag.
  144. */
  145. void endDrag();
  146. /**
  147. * @brief Triggered when a tab button is toggled on or off.
  148. *
  149. * @param tabIdx Unique index of the tab.
  150. * @param toggledOn Whether the tab was activated or deactivated.
  151. */
  152. void tabToggled(UINT32 tabIdx, bool toggledOn);
  153. /**
  154. * @brief Triggered when the close button is pressed.
  155. */
  156. void tabClosed();
  157. /**
  158. * @brief Triggered when the maximize button is pressed.
  159. */
  160. void tabMaximize();
  161. /**
  162. * @brief Triggered every frame while a tab button is being dragged.
  163. *
  164. * @param tabIdx Unique index of the dragged tab.
  165. * @param dragPos Position of the pointer, relative to parent widget.
  166. */
  167. void tabDragged(UINT32 tabIdx, const Vector2I& dragPos);
  168. /**
  169. * @brief Triggered when a drag operation on a tab button ends.
  170. *
  171. * @param tabIdx Unique index of the dragged tab.
  172. * @param dragPos Position of the pointer, relative to parent widget.
  173. */
  174. void tabDragEnd(UINT32 tabIdx, const Vector2I& dragPos);
  175. /**
  176. * @brief Converts unique tab index to a sequential index corresponding to the
  177. * tab's position in the title bar.
  178. */
  179. INT32 uniqueIdxToSeqIdx(UINT32 uniqueIdx) const;
  180. static const INT32 TAB_SPACING;
  181. static const INT32 FIRST_TAB_OFFSET;
  182. static const INT32 OPTION_BTN_SPACING;
  183. static const INT32 OPTION_BTN_RIGHT_OFFSET;
  184. Vector<GUITabButton*> mTabButtons;
  185. UINT32 mUniqueTabIdx;
  186. UINT32 mActiveTabIdx;
  187. GUITexture* mBackgroundImage;
  188. GUIButton* mMaxBtn;
  189. GUIButton* mCloseBtn;
  190. GUIToggleGroupPtr mTabToggleGroup;
  191. EditorWidgetBase* mTempDraggedWidget;
  192. UINT32 mTempDraggedTabIdx;
  193. bool mDragInProgress;
  194. GUITabButton* mDraggedBtn;
  195. INT32 mDragBtnOffset;
  196. INT32 mInitialDragOffset;
  197. String mBackgroundStyle;
  198. String mCloseBtnStyle;
  199. String mMaximizeBtnStyle;
  200. String mTabBtnStyle;
  201. };
  202. }