BsGUISceneTreeView.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUITreeView.h"
  4. #include "BsEvent.h"
  5. #include "BsServiceLocator.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Contains SceneObject%s currently involved
  10. * in a drag and drop operation.
  11. */
  12. struct BS_ED_EXPORT DraggedSceneObjects
  13. {
  14. DraggedSceneObjects(UINT32 numObjects);
  15. ~DraggedSceneObjects();
  16. UINT32 numObjects;
  17. HSceneObject* objects;
  18. };
  19. /**
  20. * @brief GUI element that displays all SceneObject%s in the current scene
  21. * in the active project in a tree view.
  22. */
  23. class BS_ED_EXPORT GUISceneTreeView : public GUITreeView
  24. {
  25. /**
  26. * @brief Tree element with SceneObject%-specific data.
  27. */
  28. struct SceneTreeElement : public GUITreeView::TreeElement
  29. {
  30. SceneTreeElement()
  31. :mId(0)
  32. { }
  33. HSceneObject mSceneObject;
  34. UINT64 mId;
  35. };
  36. public:
  37. /**
  38. * Returns type name of the GUI element used for finding GUI element styles.
  39. */
  40. static const String& getGUITypeName();
  41. /**
  42. * @brief Creates a new resource tree view element.
  43. *
  44. * @param backgroundStyle Name of the style for the tree view background.
  45. * @param elementBtnStyle Name of the style for a normal tree view element.
  46. * @param foldoutBtnStyle Name of the style for a foldout element (e.g. for a folder).
  47. * @param selectionBackgroundStyle Name of the style for the background of selected elements.
  48. * @param highlightBackgroundStyle Name of the style for the background of highlighted elements.
  49. * @param editBoxStyle Name of the style for element that is being renamed.
  50. * @param dragHighlightStyle Name of the style for the element being dragged over.
  51. * @param dragSepHighlightStyle Name of the style for the separator displayed while dragging
  52. * an element between two other elements.
  53. */
  54. static GUISceneTreeView* create(
  55. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  56. const String& foldoutBtnStyle = StringUtil::BLANK, const String& highlightBackgroundStyle = StringUtil::BLANK,
  57. const String& selectionBackgroundStyle = StringUtil::BLANK, const String& editBoxStyle = StringUtil::BLANK,
  58. const String& dragHighlightStyle = StringUtil::BLANK, const String& dragSepHighlightStyle = StringUtil::BLANK);
  59. /**
  60. * @brief Creates a new resource tree view element.
  61. *
  62. * @param options Options that allow you to control how is the element positioned and sized.
  63. * This will override any similar options set by style.
  64. * @param backgroundStyle Name of the style for the tree view background.
  65. * @param elementBtnStyle Name of the style for a normal tree view element.
  66. * @param foldoutBtnStyle Name of the style for a foldout element (e.g. for a folder).
  67. * @param highlightBackgroundStyle Name of the style for the background of highlighted elements.
  68. * @param selectionBackgroundStyle Name of the style for the background of selected elements.
  69. * @param editBoxStyle Name of the style for element that is being renamed.
  70. * @param dragHighlightStyle Name of the style for the element being dragged over.
  71. * @param dragSepHighlightStyle Name of the style for the separator displayed while dragging
  72. * an element between two other elements.
  73. */
  74. static GUISceneTreeView* create(const GUIOptions& options,
  75. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  76. const String& foldoutBtnStyle = StringUtil::BLANK, const String& highlightBackgroundStyle = StringUtil::BLANK,
  77. const String& selectionBackgroundStyle = StringUtil::BLANK, const String& editBoxStyle = StringUtil::BLANK,
  78. const String& dragHighlightStyle = StringUtil::BLANK, const String& dragSepHighlightStyle = StringUtil::BLANK);
  79. /**
  80. * @brief Returns a list of SceneObject&s currently selected (if any).
  81. */
  82. Vector<HSceneObject> getSelection() const;
  83. /**
  84. * @brief Changes the active selection to the provided SceneObject%s.
  85. */
  86. void setSelection(const Vector<HSceneObject>& objects);
  87. /**
  88. * @brief Scrolls to and highlights the selected object (does not select it).
  89. */
  90. void ping(const HSceneObject& object);
  91. Event<void()> onSelectionChanged; /**< Triggered whenever the selection changes. Call ::getSelection() to retrieve new selection: */
  92. Event<void()> onModified; /**< Triggered whenever the scene is modified in any way from within the scene tree view. (e.g. object is deleted, added, etc.) */
  93. static const MessageId SELECTION_CHANGED_MSG;
  94. protected:
  95. virtual ~GUISceneTreeView();
  96. protected:
  97. SceneTreeElement mRootElement;
  98. GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle,
  99. const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle,
  100. const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
  101. /**
  102. * @brief Checks it the SceneObject referenced by this tree element changed in any way and updates
  103. * the tree element. This can involve recursing all children and updating them as well.
  104. */
  105. void updateTreeElement(SceneTreeElement* element);
  106. /**
  107. * @brief Triggered when a drag and drop operation that was started by the tree view
  108. * ends, regardless if it was processed or not.
  109. */
  110. void dragAndDropFinalize();
  111. /**
  112. * @copydoc TreeView::getRootElement
  113. */
  114. virtual TreeElement& getRootElement() override { return mRootElement; }
  115. /**
  116. * @copydoc TreeView::getRootElementConst
  117. */
  118. virtual const TreeElement& getRootElementConst() const override { return mRootElement; }
  119. /**
  120. * @copydoc TreeView::updateTreeElementHierarchy
  121. */
  122. virtual void updateTreeElementHierarchy() override;
  123. /**
  124. * @copydoc TreeView::renameTreeElement
  125. */
  126. virtual void renameTreeElement(TreeElement* element, const WString& name) override;
  127. /**
  128. * @copydoc TreeView::deleteTreeElement
  129. */
  130. virtual void deleteTreeElement(TreeElement* element) override;
  131. /**
  132. * @copydoc TreeView::acceptDragAndDrop
  133. */
  134. virtual bool acceptDragAndDrop() const override;
  135. /**
  136. * @copydoc TreeView::dragAndDropStart
  137. */
  138. virtual void dragAndDropStart() override;
  139. /**
  140. * @copydoc TreeView::dragAndDropEnded
  141. */
  142. virtual void dragAndDropEnded(TreeElement* overTreeElement) override;
  143. /**
  144. * @copydoc TreeView::_acceptDragAndDrop
  145. */
  146. virtual bool _acceptDragAndDrop(const Vector2I position, UINT32 typeId) const override;
  147. /**
  148. * @copydoc TreeView::selectionChanged
  149. */
  150. virtual void selectionChanged() override;
  151. /**
  152. * @brief Deletes the internal TreeElement representation without
  153. * actually deleting the referenced SceneObject.
  154. */
  155. void deleteTreeElementInternal(TreeElement* element);
  156. /**
  157. * @brief Attempts to find a tree element referencing the specified
  158. * scene object.
  159. */
  160. SceneTreeElement* findTreeElement(const HSceneObject& so);
  161. /**
  162. * @copydoc GUITreeView::duplicateSelection
  163. */
  164. void duplicateSelection() override;
  165. /**
  166. * @copydoc GUITreeView::copySelection
  167. */
  168. void copySelection() override;
  169. /**
  170. * @copydoc GUITreeView::cutSelection
  171. */
  172. void cutSelection() override;
  173. /**
  174. * @copydoc GUITreeView::paste
  175. */
  176. void paste() override;
  177. /**
  178. * @brief Creates a new scene object as a child of the currently selected object (if any).
  179. */
  180. void createNewSO();
  181. /**
  182. * @brief Removes all elements from the list used for copy/cut operations.
  183. */
  184. void clearCopyList();
  185. /**
  186. * @brief Cleans duplicate objects from the provided scene object list.
  187. * This involves removing child elements if their parents are
  188. * already part of the list.
  189. */
  190. static void cleanDuplicates(Vector<HSceneObject>& objects);
  191. Vector<HSceneObject> mCopyList;
  192. bool mCutFlag;
  193. };
  194. typedef ServiceLocator<GUISceneTreeView> SceneTreeViewLocator;
  195. }