BsGUIResourceTreeView.h 9.8 KB

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