BsGUISceneTreeView.h 5.0 KB

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