BsGUIResourceTreeView.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsServiceLocator.h"
  4. #include "BsGUITreeView.h"
  5. #include "BsProjectLibrary.h"
  6. #include "BsEvent.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Contains paths to resources currently involved
  11. * in a drag and drop operation.
  12. */
  13. struct DraggedResources
  14. {
  15. Vector<Path> resourcePaths;
  16. };
  17. /**
  18. * @brief GUI element that displays all resources in the active project in a tree view.
  19. */
  20. class GUIResourceTreeView : public GUITreeView
  21. {
  22. /**
  23. * @brief Tree element with resource-specific data.
  24. */
  25. struct ResourceTreeElement : public GUITreeView::TreeElement
  26. {
  27. Path mFullPath;
  28. WString mElementName;
  29. };
  30. /**
  31. * @brief Contains paths to resources currently involved
  32. * in a drag and drop operation initiated by this tree view.
  33. */
  34. struct InternalDraggedResources
  35. {
  36. InternalDraggedResources(UINT32 numObjects);
  37. ~InternalDraggedResources();
  38. UINT32 numObjects;
  39. Path* resourcePaths;
  40. };
  41. public:
  42. /**
  43. * Returns type name of the GUI element used for finding GUI element styles.
  44. */
  45. static const String& getGUITypeName();
  46. /**
  47. * @brief Creates a new resource tree view element.
  48. *
  49. * @param backgroundStyle Name of the style for the tree view background.
  50. * @param elementBtnStyle Name of the style for a normal tree view element.
  51. * @param foldoutBtnStyle Name of the style for a foldout element (e.g. for a folder).
  52. * @param highlightBackgroundStyle Name of the style for the background of highlighted elements.
  53. * @param selectionBackgroundStyle Name of the style for the background of selected elements.
  54. * @param editBoxStyle Name of the style for element that is being renamed.
  55. * @param dragHighlightStyle Name of the style for the element being dragged over.
  56. * @param dragSepHighlightStyle Name of the style for the separator displayed while dragging
  57. * an element between two other elements.
  58. */
  59. static GUIResourceTreeView* create(
  60. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  61. const String& foldoutBtnStyle = StringUtil::BLANK, const String& highlightBackgroundStyle = StringUtil::BLANK,
  62. const String& selectionBackgroundStyle = StringUtil::BLANK, const String& editBoxStyle = StringUtil::BLANK,
  63. const String& dragHighlightStyle = StringUtil::BLANK, const String& dragSepHighlightStyle = StringUtil::BLANK);
  64. /**
  65. * @brief Creates a new resource tree view element.
  66. *
  67. * @param options Options that allow you to control how is the element positioned and sized.
  68. * This will override any similar options set by style.
  69. * @param backgroundStyle Name of the style for the tree view background.
  70. * @param elementBtnStyle Name of the style for a normal tree view element.
  71. * @param foldoutBtnStyle Name of the style for a foldout element (e.g. for a folder).
  72. * @param highlightBackgroundStyle Name of the style for the background of highlighted elements.
  73. * @param selectionBackgroundStyle Name of the style for the background of selected elements.
  74. * @param editBoxStyle Name of the style for element that is being renamed.
  75. * @param dragHighlightStyle Name of the style for the element being dragged over.
  76. * @param dragSepHighlightStyle Name of the style for the separator displayed while dragging
  77. * an element between two other elements.
  78. */
  79. static GUIResourceTreeView* create(const GUIOptions& options,
  80. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  81. const String& foldoutBtnStyle = StringUtil::BLANK, const String& highlightBackgroundStyle = StringUtil::BLANK,
  82. const String& selectionBackgroundStyle = StringUtil::BLANK, const String& editBoxStyle = StringUtil::BLANK,
  83. const String& dragHighlightStyle = StringUtil::BLANK, const String& dragSepHighlightStyle = StringUtil::BLANK);
  84. /**
  85. * @brief Returns a list of paths of currently selected resources (if any).
  86. * Returned paths are relative to the project folder.
  87. */
  88. Vector<Path> getSelection() const;
  89. /**
  90. * @brief Changes the active selection to the provided resources.
  91. * Paths can be absolute or relative.
  92. */
  93. void setSelection(const Vector<Path>& paths);
  94. Event<void()> onSelectionChanged; /**< Triggered whenever the selection changes. Call ::getSelection() to retrieve new selection: */
  95. static const MessageId SELECTION_CHANGED_MSG;
  96. protected:
  97. virtual ~GUIResourceTreeView();
  98. protected:
  99. InternalDraggedResources* mDraggedResources;
  100. ResourceTreeElement mRootElement;
  101. RenderWindow* mCurrentWindow;
  102. OSDropTarget* mDropTarget;
  103. bool mDropTargetDragActive;
  104. HEvent mDropTargetEnterConn;
  105. HEvent mDropTargetMoveConn;
  106. HEvent mDropTargetLeaveConn;
  107. HEvent mDropTargetDroppedConn;
  108. GUIResourceTreeView(const String& backgroundStyle, const String& elementBtnStyle, const String& foldoutBtnStyle,
  109. const String& highlightBackgroundStyle, const String& selectionBackgroundStyle, const String& editBoxStyle,
  110. const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
  111. /**
  112. * @copydoc GUITreeView::_updateLayoutInternal
  113. */
  114. virtual void _updateLayoutInternal(const GUILayoutData& data) override;
  115. /**
  116. * @copydoc GUITreeView::getRootElement
  117. */
  118. virtual TreeElement& getRootElement() override { return mRootElement; }
  119. /**
  120. * @copydoc GUITreeView::getRootElementConst
  121. */
  122. virtual const TreeElement& getRootElementConst() const override { return mRootElement; }
  123. /**
  124. * @copydoc GUITreeView::updateTreeElementHierarchy
  125. */
  126. virtual void updateTreeElementHierarchy() override;
  127. /**
  128. * @copydoc GUITreeView::renameTreeElement
  129. */
  130. virtual void renameTreeElement(TreeElement* element, const WString& name) override;
  131. /**
  132. * @copydoc GUITreeView::deleteTreeElement
  133. */
  134. virtual void deleteTreeElement(TreeElement* element) override;
  135. /**
  136. * @copydoc GUITreeView::acceptDragAndDrop
  137. */
  138. virtual bool acceptDragAndDrop() const override;
  139. /**
  140. * @copydoc GUITreeView::dragAndDropStart
  141. */
  142. virtual void dragAndDropStart() override;
  143. /**
  144. * @copydoc GUITreeView::dragAndDropEnded
  145. */
  146. virtual void dragAndDropEnded(TreeElement* overTreeElement) override;
  147. /**
  148. * @copydoc GUITreeView::_acceptDragAndDrop
  149. */
  150. virtual bool _acceptDragAndDrop(const Vector2I position, UINT32 typeId) const override;
  151. /**
  152. * @copydoc GUITreeView::selectionChanged
  153. */
  154. virtual void selectionChanged() override;
  155. /**
  156. * @copydoc GUITreeView::_changeParentWidget
  157. */
  158. void _changeParentWidget(GUIWidget* widget) override;
  159. /**
  160. * @brief Triggered when a drag and drop operation that was started by the tree view
  161. * ends, regardless if it was processed or not.
  162. */
  163. void dragAndDropFinalize();
  164. /**
  165. * @brief Updates the contents of the provided tree entry with a project library entry.
  166. */
  167. void updateFromProjectLibraryEntry(ResourceTreeElement* treeElement, const ProjectLibrary::LibraryEntry* libraryEntry);
  168. /**
  169. * @brief Creates a new tree view entry.
  170. *
  171. * @param parent Parent tree view entry to create the new one for.
  172. * @param fullPath Absolute path to the new tree entry.
  173. */
  174. ResourceTreeElement* addTreeElement(ResourceTreeElement* parent, const Path& fullPath);
  175. /**
  176. * @brief Deletes the provided tree element.
  177. */
  178. void deleteTreeElement(ResourceTreeElement* element);
  179. /**
  180. * @brief Sorts the children of the provided tree element by name.
  181. */
  182. void sortTreeElement(ResourceTreeElement* element);
  183. /**
  184. * @brief Attempts to find a tree element with the specified path.
  185. * Returns null if one cannot be found.
  186. */
  187. ResourceTreeElement* findTreeElement(const Path& fullPath);
  188. /**
  189. * @brief Called whenever a new entry is added to the project library.
  190. */
  191. void entryAdded(const Path& path);
  192. /**
  193. * @brief Called whenever an entry is removed from the project library.
  194. */
  195. void entryRemoved(const Path& path);
  196. /**
  197. * @brief Sets an OS drag and drop target that allows this element to receive OS-specific
  198. * drag and drop events originating from other processes.
  199. */
  200. void setDropTarget(RenderWindow* parentWindow, INT32 x, INT32 y, UINT32 width, UINT32 height);
  201. /**
  202. * @brief Removes the currently set OS drop target.
  203. */
  204. void clearDropTarget();
  205. /**
  206. * @brief Triggered whenever the user drags the pointer over the set drop target,
  207. * while OS drag and drop operation is active.
  208. *
  209. * @param x X coordinate of the pointer, relative to drop area.
  210. * @param y Y coordinate of the pointer, relative to drop area.
  211. */
  212. void dropTargetDragMove(INT32 x, INT32 y);
  213. /**
  214. * @brief Triggered whenever pointer leaves the drop target,
  215. * while OS drag and drop operation is active.
  216. */
  217. void dropTargetDragLeave();
  218. /**
  219. * @brief Triggered whenever the user releases the pointer over the set drop target,
  220. * while OS drag and drop operation is active.
  221. *
  222. * @param x X coordinate of the pointer, relative to drop area.
  223. * @param y Y coordinate of the pointer, relative to drop area.
  224. */
  225. void dropTargetDragDropped(INT32 x, INT32 y);
  226. /**
  227. * @brief Generates a unique path in the case that something already
  228. * exists on the provided one.
  229. */
  230. Path findUniquePath(const Path& path);
  231. };
  232. typedef ServiceLocator<GUIResourceTreeView> ResourceTreeViewLocator;
  233. }