BsGUITabbedTitleBar.h 7.4 KB

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