BsGUITabbedTitleBar.h 7.5 KB

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