BsGUISceneTreeView.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. static const MessageId SELECTION_CHANGED_MSG;
  93. protected:
  94. virtual ~GUISceneTreeView();
  95. protected:
  96. SceneTreeElement mRootElement;
  97. GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle,
  98. const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle,
  99. const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
  100. /**
  101. * @brief Checks it the SceneObject referenced by this tree element changed in any way and updates
  102. * the tree element. This can involve recursing all children and updating them as well.
  103. */
  104. void updateTreeElement(SceneTreeElement* element);
  105. /**
  106. * @brief Triggered when a drag and drop operation that was started by the tree view
  107. * ends, regardless if it was processed or not.
  108. */
  109. void dragAndDropFinalize();
  110. /**
  111. * @copydoc TreeView::getRootElement
  112. */
  113. virtual TreeElement& getRootElement() override { return mRootElement; }
  114. /**
  115. * @copydoc TreeView::getRootElementConst
  116. */
  117. virtual const TreeElement& getRootElementConst() const override { return mRootElement; }
  118. /**
  119. * @copydoc TreeView::updateTreeElementHierarchy
  120. */
  121. virtual void updateTreeElementHierarchy() override;
  122. /**
  123. * @copydoc TreeView::renameTreeElement
  124. */
  125. virtual void renameTreeElement(TreeElement* element, const WString& name) override;
  126. /**
  127. * @copydoc TreeView::deleteTreeElement
  128. */
  129. virtual void deleteTreeElement(TreeElement* element) override;
  130. /**
  131. * @copydoc TreeView::acceptDragAndDrop
  132. */
  133. virtual bool acceptDragAndDrop() const override;
  134. /**
  135. * @copydoc TreeView::dragAndDropStart
  136. */
  137. virtual void dragAndDropStart() override;
  138. /**
  139. * @copydoc TreeView::dragAndDropEnded
  140. */
  141. virtual void dragAndDropEnded(TreeElement* overTreeElement) override;
  142. /**
  143. * @copydoc TreeView::_acceptDragAndDrop
  144. */
  145. virtual bool _acceptDragAndDrop(const Vector2I position, UINT32 typeId) const override;
  146. /**
  147. * @copydoc TreeView::selectionChanged
  148. */
  149. virtual void selectionChanged() override;
  150. /**
  151. * @brief Deletes the internal TreeElement representation without
  152. * actually deleting the referenced SceneObject.
  153. */
  154. void deleteTreeElementInternal(TreeElement* element);
  155. /**
  156. * @brief Attempts to find a tree element referencing the specified
  157. * scene object.
  158. */
  159. SceneTreeElement* findTreeElement(const HSceneObject& so);
  160. /**
  161. * @copydoc GUITreeView::duplicateSelection
  162. */
  163. void duplicateSelection() override;
  164. /**
  165. * @copydoc GUITreeView::copySelection
  166. */
  167. void copySelection() override;
  168. /**
  169. * @copydoc GUITreeView::cutSelection
  170. */
  171. void cutSelection() override;
  172. /**
  173. * @copydoc GUITreeView::paste
  174. */
  175. void paste() override;
  176. /**
  177. * @brief Creates a new scene object as a child of the currently selected object (if any).
  178. */
  179. void createNewSO();
  180. /**
  181. * @brief Removes all elements from the list used for copy/cut operations.
  182. */
  183. void clearCopyList();
  184. /**
  185. * @brief Cleans duplicate objects from the provided scene object list.
  186. * This involves removing child elements if their parents are
  187. * already part of the list.
  188. */
  189. static void cleanDuplicates(Vector<HSceneObject>& objects);
  190. Vector<HSceneObject> mCopyList;
  191. bool mCutFlag;
  192. };
  193. typedef ServiceLocator<GUISceneTreeView> SceneTreeViewLocator;
  194. }