BsGUIResourceTreeView.h 9.6 KB

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