BsEditorWidgetContainer.h 5.6 KB

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