BsGUIResourceTreeView.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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::dragAndDropFinalize
  147. */
  148. virtual void dragAndDropFinalize() override;
  149. /**
  150. * @copydoc GUITreeView::_acceptDragAndDrop
  151. */
  152. virtual bool _acceptDragAndDrop(const Vector2I position, UINT32 typeId) const override;
  153. /**
  154. * @copydoc GUITreeView::selectionChanged
  155. */
  156. virtual void selectionChanged() override;
  157. /**
  158. * @copydoc GUITreeView::_changeParentWidget
  159. */
  160. void _changeParentWidget(GUIWidget* widget) override;
  161. /**
  162. * @brief Updates the contents of the provided tree entry with a project library entry.
  163. */
  164. void updateFromProjectLibraryEntry(ResourceTreeElement* treeElement, const ProjectLibrary::LibraryEntry* libraryEntry);
  165. /**
  166. * @brief Creates a new tree view entry.
  167. *
  168. * @param parent Parent tree view entry to create the new one for.
  169. * @param fullPath Absolute path to the new tree entry.
  170. */
  171. ResourceTreeElement* addTreeElement(ResourceTreeElement* parent, const Path& fullPath);
  172. /**
  173. * @brief Deletes the provided tree element.
  174. */
  175. void deleteTreeElement(ResourceTreeElement* element);
  176. /**
  177. * @brief Sorts the children of the provided tree element by name.
  178. */
  179. void sortTreeElement(ResourceTreeElement* element);
  180. /**
  181. * @brief Attempts to find a tree element with the specified path.
  182. * Returns null if one cannot be found.
  183. */
  184. ResourceTreeElement* findTreeElement(const Path& fullPath);
  185. /**
  186. * @brief Called whenever a new entry is added to the project library.
  187. */
  188. void entryAdded(const Path& path);
  189. /**
  190. * @brief Called whenever an entry is removed from the project library.
  191. */
  192. void entryRemoved(const Path& path);
  193. /**
  194. * @brief Sets an OS drag and drop target that allows this element to receive OS-specific
  195. * drag and drop events originating from other processes.
  196. */
  197. void setDropTarget(RenderWindow* parentWindow, INT32 x, INT32 y, UINT32 width, UINT32 height);
  198. /**
  199. * @brief Removes the currently set OS drop target.
  200. */
  201. void clearDropTarget();
  202. /**
  203. * @brief Triggered whenever the user drags the pointer over the set drop target,
  204. * while OS drag and drop operation is active.
  205. *
  206. * @param x X coordinate of the pointer, relative to drop area.
  207. * @param y Y coordinate of the pointer, relative to drop area.
  208. */
  209. void dropTargetDragMove(INT32 x, INT32 y);
  210. /**
  211. * @brief Triggered whenever pointer leaves the drop target,
  212. * while OS drag and drop operation is active.
  213. */
  214. void dropTargetDragLeave();
  215. /**
  216. * @brief Triggered whenever the user releases the pointer over the set drop target,
  217. * while OS drag and drop operation is active.
  218. *
  219. * @param x X coordinate of the pointer, relative to drop area.
  220. * @param y Y coordinate of the pointer, relative to drop area.
  221. */
  222. void dropTargetDragDropped(INT32 x, INT32 y);
  223. /**
  224. * @brief Generates a unique path in the case that something already
  225. * exists on the provided one.
  226. */
  227. Path findUniquePath(const Path& path);
  228. };
  229. typedef ServiceLocator<GUIResourceTreeView> ResourceTreeViewLocator;
  230. }