BsGUISceneTreeView.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include <boost/signal.hpp>
  5. namespace BansheeEditor
  6. {
  7. class GUISceneTreeView : public BS::GUIElementContainer
  8. {
  9. enum class ScrollState
  10. {
  11. None,
  12. Up,
  13. Down,
  14. TransitioningUp,
  15. TransitioningDown
  16. };
  17. struct TreeElement
  18. {
  19. TreeElement();
  20. ~TreeElement();
  21. TreeElement* mParent;
  22. CM::Vector<TreeElement*>::type mChildren;
  23. BS::GUIToggle* mFoldoutBtn;
  24. BS::GUILabel* mElement;
  25. CM::HSceneObject mSceneObject;
  26. CM::String mName;
  27. CM::UINT32 mId;
  28. CM::UINT32 mSortedIdx;
  29. bool mIsExpanded;
  30. bool mIsSelected;
  31. bool mIsDirty;
  32. bool mIsVisible;
  33. bool isParentRec(TreeElement* element) const;
  34. };
  35. struct InteractableElement
  36. {
  37. InteractableElement(TreeElement* parent, CM::UINT32 index, const CM::RectI& bounds)
  38. :parent(parent), index(index), bounds(bounds)
  39. { }
  40. bool isTreeElement() const { return index % 2 == 1; }
  41. TreeElement* getTreeElement() const;
  42. TreeElement* parent;
  43. CM::UINT32 index;
  44. CM::RectI bounds;
  45. };
  46. struct SelectedElement
  47. {
  48. SelectedElement(TreeElement* elem, BS::GUITexture* back)
  49. :element(elem), background(back)
  50. { }
  51. TreeElement* element;
  52. BS::GUITexture* background;
  53. };
  54. struct DraggedSceneObjects
  55. {
  56. DraggedSceneObjects(CM::UINT32 numObjects);
  57. ~DraggedSceneObjects();
  58. CM::UINT32 numObjects;
  59. CM::HSceneObject* objects;
  60. };
  61. public:
  62. static const CM::String& getGUITypeName();
  63. static GUISceneTreeView* create(BS::GUIWidget& parent,
  64. BS::GUIElementStyle* backgroundStyle = nullptr, BS::GUIElementStyle* elementBtnStyle = nullptr,
  65. BS::GUIElementStyle* foldoutBtnStyle = nullptr, BS::GUIElementStyle* selectionBackgroundStyle = nullptr,
  66. BS::GUIElementStyle* editBoxStyle = nullptr, BS::GUIElementStyle* dragHighlightStyle = nullptr,
  67. BS::GUIElementStyle* dragSepHighlightStyle = nullptr);
  68. static GUISceneTreeView* create(BS::GUIWidget& parent, const BS::GUIOptions& options,
  69. BS::GUIElementStyle* backgroundStyle = nullptr, BS::GUIElementStyle* elementBtnStyle = nullptr,
  70. BS::GUIElementStyle* foldoutBtnStyle = nullptr, BS::GUIElementStyle* selectionBackgroundStyle = nullptr,
  71. BS::GUIElementStyle* editBoxStyle = nullptr, BS::GUIElementStyle* dragHighlightStyle = nullptr,
  72. BS::GUIElementStyle* dragSepHighlightStyle = nullptr);
  73. void update();
  74. protected:
  75. virtual ~GUISceneTreeView();
  76. CM::Vector2I _getOptimalSize() const;
  77. void updateClippedBounds();
  78. void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
  79. CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
  80. protected:
  81. static const CM::UINT32 ELEMENT_EXTRA_SPACING;
  82. static const CM::UINT32 INDENT_SIZE;
  83. static const CM::UINT32 INITIAL_INDENT_OFFSET;
  84. static const CM::UINT32 DRAG_MIN_DISTANCE;
  85. static const float AUTO_EXPAND_DELAY_SEC;
  86. static const float SCROLL_AREA_HEIGHT_PCT;
  87. static const CM::UINT32 SCROLL_SPEED_PX_PER_SEC;
  88. const BS::GUIElementStyle* mBackgroundStyle;
  89. const BS::GUIElementStyle* mElementBtnStyle;
  90. const BS::GUIElementStyle* mFoldoutBtnStyle;
  91. const BS::GUIElementStyle* mSelectionBackgroundStyle;
  92. const BS::GUIElementStyle* mEditBoxStyle;
  93. const BS::GUIElementStyle* mDragHighlightStyle;
  94. const BS::GUIElementStyle* mDragSepHighlightStyle;
  95. BS::GUITexture* mBackgroundImage;
  96. TreeElement mRootElement;
  97. CM::Vector<InteractableElement>::type mVisibleElements;
  98. CM::Vector<bool>::type mTempToDelete;
  99. bool mIsElementSelected;
  100. CM::Vector<SelectedElement>::type mSelectedElements;
  101. TreeElement* mEditElement;
  102. GUITreeViewEditBox* mNameEditBox;
  103. CM::Vector2I mDragStartPosition;
  104. CM::Vector2I mDragPosition;
  105. bool mDragInProgress;
  106. BS::GUITexture* mDragHighlight;
  107. BS::GUITexture* mDragSepHighlight;
  108. CM::RectI mTopScrollBounds;
  109. CM::RectI mBottomScrollBounds;
  110. ScrollState mScrollState;
  111. float mLastScrollTime;
  112. CM::Stack<TreeElement*>::type mAutoExpandedElements;
  113. TreeElement* mMouseOverDragElement;
  114. float mMouseOverDragElementTime;
  115. GUISceneTreeView(BS::GUIWidget& parent, BS::GUIElementStyle* backgroundStyle, BS::GUIElementStyle* elementBtnStyle,
  116. BS::GUIElementStyle* foldoutBtnStyle, BS::GUIElementStyle* selectionBackgroundStyle, BS::GUIElementStyle* editBoxStyle,
  117. BS::GUIElementStyle* dragHighlightStyle, BS::GUIElementStyle* dragSepHighlightStyle, const BS::GUILayoutOptions& layoutOptions);
  118. const GUISceneTreeView::InteractableElement* findElementUnderCoord(const CM::Vector2I& coord) const;
  119. TreeElement* getTopMostSelectedElement() const;
  120. TreeElement* getBottomMostSelectedElement() const;
  121. void enableEdit(TreeElement* element);
  122. void disableEdit(bool acceptChanges);
  123. virtual bool mouseEvent(const BS::GUIMouseEvent& ev);
  124. virtual bool commandEvent(const BS::GUICommandEvent& ev);
  125. void elementToggled(TreeElement* element, bool toggled);
  126. bool isSelectionActive() const;
  127. void selectElement(TreeElement* element);
  128. void unselectElement(TreeElement* element);
  129. void unselectAll();
  130. void temporarilyExpandElement(const GUISceneTreeView::InteractableElement* mouseOverElement);
  131. void scrollToElement(TreeElement* element, bool center);
  132. BS::GUIScrollArea* findParentScrollArea() const;
  133. void onEditAccepted();
  134. void onEditCanceled();
  135. void dragAndDropEnded();
  136. };
  137. }