2
0

BsGUISceneTreeView.h 4.6 KB

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