BsGUIResourceTreeView.h 9.2 KB

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