BsGUITreeView.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 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 RectI& 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. RectI 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(INT32 x, INT32 y, UINT32 width, UINT32 height,
  61. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth);
  62. protected:
  63. static const UINT32 ELEMENT_EXTRA_SPACING;
  64. static const UINT32 INDENT_SIZE;
  65. static const UINT32 INITIAL_INDENT_OFFSET;
  66. static const UINT32 DRAG_MIN_DISTANCE;
  67. static const float AUTO_EXPAND_DELAY_SEC;
  68. static const float SCROLL_AREA_HEIGHT_PCT;
  69. static const UINT32 SCROLL_SPEED_PX_PER_SEC;
  70. String mBackgroundStyle;
  71. String mElementBtnStyle;
  72. String mFoldoutBtnStyle;
  73. String mSelectionBackgroundStyle;
  74. String mEditBoxStyle;
  75. String mDragHighlightStyle;
  76. String mDragSepHighlightStyle;
  77. GUITexture* mBackgroundImage;
  78. Vector<InteractableElement> mVisibleElements;
  79. bool mIsElementSelected;
  80. Vector<SelectedElement> mSelectedElements;
  81. TreeElement* mEditElement;
  82. GUITreeViewEditBox* mNameEditBox;
  83. Vector2I mDragStartPosition;
  84. Vector2I mDragPosition;
  85. bool mDragInProgress;
  86. GUITexture* mDragHighlight;
  87. GUITexture* mDragSepHighlight;
  88. RectI mTopScrollBounds;
  89. RectI mBottomScrollBounds;
  90. ScrollState mScrollState;
  91. float mLastScrollTime;
  92. Stack<TreeElement*> mAutoExpandedElements;
  93. TreeElement* mMouseOverDragElement;
  94. float mMouseOverDragElementTime;
  95. static VirtualButton mRenameVB;
  96. static VirtualButton mDeleteVB;
  97. GUITreeView(const String& backgroundStyle, const String& elementBtnStyle,
  98. const String& foldoutBtnStyle, const String& selectionBackgroundStyle, const String& editBoxStyle,
  99. const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUILayoutOptions& layoutOptions);
  100. const GUITreeView::InteractableElement* findElementUnderCoord(const Vector2I& coord) const;
  101. TreeElement* getTopMostSelectedElement() const;
  102. TreeElement* getBottomMostSelectedElement() const;
  103. void enableEdit(TreeElement* element);
  104. void disableEdit(bool acceptChanges);
  105. virtual bool mouseEvent(const GUIMouseEvent& ev);
  106. virtual bool commandEvent(const GUICommandEvent& ev);
  107. virtual bool virtualButtonEvent(const GUIVirtualButtonEvent& ev);
  108. void elementToggled(TreeElement* element, bool toggled);
  109. virtual TreeElement& getRootElement() = 0;
  110. virtual const TreeElement& getRootElementConst() const = 0;
  111. virtual void updateTreeElementHierarchy() = 0;
  112. virtual void renameTreeElement(TreeElement* element, const WString& name) = 0;
  113. virtual void deleteTreeElement(TreeElement* element) = 0;
  114. virtual bool acceptDragAndDrop() const = 0;
  115. virtual void dragAndDropStart() = 0;
  116. virtual void dragAndDropEnded(TreeElement* overTreeElement) = 0;
  117. virtual void dragAndDropFinalize() = 0;
  118. bool isSelectionActive() const;
  119. void selectElement(TreeElement* element);
  120. void unselectElement(TreeElement* element);
  121. void unselectAll();
  122. void expandElement(TreeElement* element);
  123. void collapseElement(TreeElement* element);
  124. void updateElementGUI(TreeElement* element);
  125. void closeTemporarilyExpandedElements();
  126. void temporarilyExpandElement(const GUITreeView::InteractableElement* mouseOverElement);
  127. void scrollToElement(TreeElement* element, bool center);
  128. GUIScrollArea* findParentScrollArea() const;
  129. void onEditAccepted();
  130. void onEditCanceled();
  131. };
  132. }