BsGUISceneTreeView.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 editBoxStyle Name of the style for element that is being renamed.
  49. * @param dragHighlightStyle Name of the style for the element being dragged over.
  50. * @param dragSepHighlightStyle Name of the style for the separator displayed while dragging
  51. * an element between two other elements.
  52. */
  53. static GUISceneTreeView* create(
  54. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  55. const String& foldoutBtnStyle = StringUtil::BLANK, const String& selectionBackgroundStyle = StringUtil::BLANK,
  56. const String& editBoxStyle = StringUtil::BLANK, const String& dragHighlightStyle = StringUtil::BLANK,
  57. const String& dragSepHighlightStyle = StringUtil::BLANK);
  58. /**
  59. * @brief Creates a new resource tree view element.
  60. *
  61. * @param options Options that allow you to control how is the element positioned and sized.
  62. * This will override any similar options set by style.
  63. * @param backgroundStyle Name of the style for the tree view background.
  64. * @param elementBtnStyle Name of the style for a normal tree view element.
  65. * @param foldoutBtnStyle Name of the style for a foldout element (e.g. for a folder).
  66. * @param selectionBackgroundStyle Name of the style for the background of selected elements.
  67. * @param editBoxStyle Name of the style for element that is being renamed.
  68. * @param dragHighlightStyle Name of the style for the element being dragged over.
  69. * @param dragSepHighlightStyle Name of the style for the separator displayed while dragging
  70. * an element between two other elements.
  71. */
  72. static GUISceneTreeView* create(const GUIOptions& options,
  73. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  74. const String& foldoutBtnStyle = StringUtil::BLANK, const String& selectionBackgroundStyle = StringUtil::BLANK,
  75. const String& editBoxStyle = StringUtil::BLANK, const String& dragHighlightStyle = StringUtil::BLANK,
  76. const String& dragSepHighlightStyle = StringUtil::BLANK);
  77. /**
  78. * @brief Returns a list of SceneObject&s currently selected (if any).
  79. */
  80. Vector<HSceneObject> getSelection() const;
  81. /**
  82. * @brief Changes the active selection to the provided SceneObject%s.
  83. */
  84. void setSelection(const Vector<HSceneObject>& objects);
  85. Event<void()> onSelectionChanged; /**< Triggered whenever the selection changes. Call ::getSelection() to retrieve new selection: */
  86. static const MessageId SELECTION_CHANGED_MSG;
  87. protected:
  88. virtual ~GUISceneTreeView();
  89. protected:
  90. SceneTreeElement mRootElement;
  91. GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle,
  92. const String& foldoutBtnStyle, const String& selectionBackgroundStyle, const String& editBoxStyle,
  93. const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
  94. /**
  95. * @brief Checks it the SceneObject referenced by this tree element changed in any way and updates
  96. * the tree element. This can involve recursing all children and updating them as well.
  97. */
  98. void updateTreeElement(SceneTreeElement* element);
  99. /**
  100. * @brief Triggered when a drag and drop operation that was started by the tree view
  101. * ends, regardless if it was processed or not.
  102. */
  103. void dragAndDropFinalize();
  104. /**
  105. * @copydoc TreeView::getRootElement
  106. */
  107. virtual TreeElement& getRootElement() override { return mRootElement; }
  108. /**
  109. * @copydoc TreeView::getRootElementConst
  110. */
  111. virtual const TreeElement& getRootElementConst() const override { return mRootElement; }
  112. /**
  113. * @copydoc TreeView::updateTreeElementHierarchy
  114. */
  115. virtual void updateTreeElementHierarchy() override;
  116. /**
  117. * @copydoc TreeView::renameTreeElement
  118. */
  119. virtual void renameTreeElement(TreeElement* element, const WString& name) override;
  120. /**
  121. * @copydoc TreeView::deleteTreeElement
  122. */
  123. virtual void deleteTreeElement(TreeElement* element) override;
  124. /**
  125. * @copydoc TreeView::acceptDragAndDrop
  126. */
  127. virtual bool acceptDragAndDrop() const override;
  128. /**
  129. * @copydoc TreeView::dragAndDropStart
  130. */
  131. virtual void dragAndDropStart() override;
  132. /**
  133. * @copydoc TreeView::dragAndDropEnded
  134. */
  135. virtual void dragAndDropEnded(TreeElement* overTreeElement) override;
  136. /**
  137. * @copydoc TreeView::_acceptDragAndDrop
  138. */
  139. virtual bool _acceptDragAndDrop(const Vector2I position, UINT32 typeId) const override;
  140. /**
  141. * @copydoc TreeView::selectionChanged
  142. */
  143. virtual void selectionChanged() override;
  144. /**
  145. * @brief Deletes the internal TreeElement representation without
  146. * actually deleting the referenced SceneObject.
  147. */
  148. void deleteTreeElementInternal(TreeElement* element);
  149. };
  150. typedef ServiceLocator<GUISceneTreeView> SceneTreeViewLocator;
  151. }