BsGUIResourceTreeView.h 9.3 KB

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