2
0

BsGUITreeView.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsVirtualInput.h"
  5. #include <boost/signal.hpp>
  6. namespace BansheeEditor
  7. {
  8. class GUITreeView : public BS::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. CM::Vector<TreeElement*>::type mChildren;
  25. BS::GUIToggle* mFoldoutBtn;
  26. BS::GUILabel* mElement;
  27. CM::String mName;
  28. CM::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, CM::UINT32 index, const CM::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. CM::UINT32 index;
  43. CM::RectI bounds;
  44. };
  45. struct SelectedElement
  46. {
  47. SelectedElement(TreeElement* elem, BS::GUITexture* back)
  48. :element(elem), background(back)
  49. { }
  50. TreeElement* element;
  51. BS::GUITexture* background;
  52. };
  53. public:
  54. static const CM::String& getGUITypeName();
  55. void update();
  56. protected:
  57. virtual ~GUITreeView();
  58. CM::Vector2I _getOptimalSize() const;
  59. void updateClippedBounds();
  60. virtual void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
  61. CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
  62. protected:
  63. static const CM::UINT32 ELEMENT_EXTRA_SPACING;
  64. static const CM::UINT32 INDENT_SIZE;
  65. static const CM::UINT32 INITIAL_INDENT_OFFSET;
  66. static const CM::UINT32 DRAG_MIN_DISTANCE;
  67. static const float AUTO_EXPAND_DELAY_SEC;
  68. static const float SCROLL_AREA_HEIGHT_PCT;
  69. static const CM::UINT32 SCROLL_SPEED_PX_PER_SEC;
  70. const BS::GUIElementStyle* mBackgroundStyle;
  71. const BS::GUIElementStyle* mElementBtnStyle;
  72. const BS::GUIElementStyle* mFoldoutBtnStyle;
  73. const BS::GUIElementStyle* mSelectionBackgroundStyle;
  74. const BS::GUIElementStyle* mEditBoxStyle;
  75. const BS::GUIElementStyle* mDragHighlightStyle;
  76. const BS::GUIElementStyle* mDragSepHighlightStyle;
  77. BS::GUITexture* mBackgroundImage;
  78. CM::Vector<InteractableElement>::type mVisibleElements;
  79. bool mIsElementSelected;
  80. CM::Vector<SelectedElement>::type mSelectedElements;
  81. TreeElement* mEditElement;
  82. GUITreeViewEditBox* mNameEditBox;
  83. CM::Vector2I mDragStartPosition;
  84. CM::Vector2I mDragPosition;
  85. bool mDragInProgress;
  86. BS::GUITexture* mDragHighlight;
  87. BS::GUITexture* mDragSepHighlight;
  88. CM::RectI mTopScrollBounds;
  89. CM::RectI mBottomScrollBounds;
  90. ScrollState mScrollState;
  91. float mLastScrollTime;
  92. CM::Stack<TreeElement*>::type mAutoExpandedElements;
  93. TreeElement* mMouseOverDragElement;
  94. float mMouseOverDragElementTime;
  95. static BS::VirtualButton mRenameVB;
  96. static BS::VirtualButton mDeleteVB;
  97. GUITreeView(BS::GUIWidget& parent, BS::GUIElementStyle* backgroundStyle, BS::GUIElementStyle* elementBtnStyle,
  98. BS::GUIElementStyle* foldoutBtnStyle, BS::GUIElementStyle* selectionBackgroundStyle, BS::GUIElementStyle* editBoxStyle,
  99. BS::GUIElementStyle* dragHighlightStyle, BS::GUIElementStyle* dragSepHighlightStyle, const BS::GUILayoutOptions& layoutOptions);
  100. const GUITreeView::InteractableElement* findElementUnderCoord(const CM::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 BS::GUIMouseEvent& ev);
  106. virtual bool commandEvent(const BS::GUICommandEvent& ev);
  107. virtual bool virtualButtonEvent(const BS::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 CM::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. BS::GUIScrollArea* findParentScrollArea() const;
  129. void onEditAccepted();
  130. void onEditCanceled();
  131. };
  132. }