BsEditorWidgetContainer.h 5.7 KB

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