BsGUITreeView.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsVirtualInput.h"
  5. #include "BsEvent.h"
  6. namespace BansheeEngine
  7. {
  8. class BS_ED_EXPORT GUITreeView : public GUIElementContainer
  9. {
  10. protected:
  11. enum class ScrollState
  12. {
  13. None,
  14. Up,
  15. Down,
  16. TransitioningUp,
  17. TransitioningDown
  18. };
  19. struct TreeElement
  20. {
  21. TreeElement();
  22. virtual ~TreeElement();
  23. TreeElement* mParent;
  24. Vector<TreeElement*> mChildren;
  25. GUIToggle* mFoldoutBtn;
  26. GUILabel* mElement;
  27. String mName;
  28. UINT32 mSortedIdx;
  29. bool mIsExpanded;
  30. bool mIsSelected;
  31. bool mIsVisible;
  32. bool isParentRec(TreeElement* element) const;
  33. };
  34. struct InteractableElement
  35. {
  36. InteractableElement(TreeElement* parent, UINT32 index, const Rect2I& bounds)
  37. :parent(parent), index(index), bounds(bounds)
  38. { }
  39. bool isTreeElement() const { return index % 2 == 1; }
  40. TreeElement* getTreeElement() const;
  41. TreeElement* parent;
  42. UINT32 index;
  43. Rect2I bounds;
  44. };
  45. struct SelectedElement
  46. {
  47. SelectedElement(TreeElement* elem, GUITexture* back)
  48. :element(elem), background(back)
  49. { }
  50. TreeElement* element;
  51. GUITexture* background;
  52. };
  53. public:
  54. static const String& getGUITypeName();
  55. void update();
  56. protected:
  57. virtual ~GUITreeView();
  58. Vector2I _getOptimalSize() const;
  59. void updateClippedBounds();
  60. virtual void _updateLayoutInternal(const GUILayoutData& data);
  61. protected:
  62. static const UINT32 ELEMENT_EXTRA_SPACING;
  63. static const UINT32 INDENT_SIZE;
  64. static const UINT32 INITIAL_INDENT_OFFSET;
  65. static const UINT32 DRAG_MIN_DISTANCE;
  66. static const float AUTO_EXPAND_DELAY_SEC;
  67. static const float SCROLL_AREA_HEIGHT_PCT;
  68. static const UINT32 SCROLL_SPEED_PX_PER_SEC;
  69. String mBackgroundStyle;
  70. String mElementBtnStyle;
  71. String mFoldoutBtnStyle;
  72. String mSelectionBackgroundStyle;
  73. String mEditBoxStyle;
  74. String mDragHighlightStyle;
  75. String mDragSepHighlightStyle;
  76. GUITexture* mBackgroundImage;
  77. Vector<InteractableElement> mVisibleElements;
  78. bool mIsElementSelected;
  79. Vector<SelectedElement> mSelectedElements;
  80. TreeElement* mEditElement;
  81. GUITreeViewEditBox* mNameEditBox;
  82. Vector2I mDragStartPosition;
  83. Vector2I mDragPosition;
  84. bool mDragInProgress;
  85. GUITexture* mDragHighlight;
  86. GUITexture* mDragSepHighlight;
  87. Rect2I mTopScrollBounds;
  88. Rect2I mBottomScrollBounds;
  89. ScrollState mScrollState;
  90. float mLastScrollTime;
  91. Stack<TreeElement*> mAutoExpandedElements;
  92. TreeElement* mMouseOverDragElement;
  93. float mMouseOverDragElementTime;
  94. static VirtualButton mRenameVB;
  95. static VirtualButton mDeleteVB;
  96. GUITreeView(const String& backgroundStyle, const String& elementBtnStyle,
  97. const String& foldoutBtnStyle, const String& selectionBackgroundStyle, const String& editBoxStyle,
  98. const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
  99. const GUITreeView::InteractableElement* findElementUnderCoord(const Vector2I& coord) const;
  100. TreeElement* getTopMostSelectedElement() const;
  101. TreeElement* getBottomMostSelectedElement() const;
  102. void enableEdit(TreeElement* element);
  103. void disableEdit(bool acceptChanges);
  104. virtual bool _mouseEvent(const GUIMouseEvent& ev);
  105. virtual bool _commandEvent(const GUICommandEvent& ev);
  106. virtual bool _virtualButtonEvent(const GUIVirtualButtonEvent& ev);
  107. void elementToggled(TreeElement* element, bool toggled);
  108. virtual TreeElement& getRootElement() = 0;
  109. virtual const TreeElement& getRootElementConst() const = 0;
  110. virtual void updateTreeElementHierarchy() = 0;
  111. virtual void renameTreeElement(TreeElement* element, const WString& name) = 0;
  112. virtual void deleteTreeElement(TreeElement* element) = 0;
  113. virtual bool acceptDragAndDrop() const = 0;
  114. virtual void dragAndDropStart() = 0;
  115. virtual void dragAndDropEnded(TreeElement* overTreeElement) = 0;
  116. virtual void dragAndDropFinalize() = 0;
  117. virtual void selectionChanged() { }
  118. bool isSelectionActive() const;
  119. void selectElement(TreeElement* element);
  120. void unselectElement(TreeElement* element);
  121. void unselectAll();
  122. void expandToElement(TreeElement* element);
  123. void expandElement(TreeElement* element);
  124. void collapseElement(TreeElement* element);
  125. void updateElementGUI(TreeElement* element);
  126. void closeTemporarilyExpandedElements();
  127. void temporarilyExpandElement(const GUITreeView::InteractableElement* mouseOverElement);
  128. void scrollToElement(TreeElement* element, bool center);
  129. GUIScrollArea* findParentScrollArea() const;
  130. void onEditAccepted();
  131. void onEditCanceled();
  132. };
  133. }