BsGUISceneTreeView.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. #include "BsGUISceneTreeView.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUITexture.h"
  5. #include "BsGUIButton.h"
  6. #include "BsGUILabel.h"
  7. #include "BsGUISpace.h"
  8. #include "BsGUIWidget.h"
  9. #include "BsGUIToggle.h"
  10. #include "BsGUITreeViewEditBox.h"
  11. #include "BsGUIMouseEvent.h"
  12. #include "BsGUISkin.h"
  13. #include "BsGUICommandEvent.h"
  14. #include "CmSceneObject.h"
  15. #include "CmSceneManager.h"
  16. #include "BsCmdEditPlainFieldGO.h"
  17. #include "BsDragAndDropManager.h"
  18. #include "BsCmdReparentSO.h"
  19. #include "CmTime.h"
  20. #include "BsGUIScrollArea.h"
  21. using namespace CamelotFramework;
  22. using namespace BansheeEngine;
  23. namespace BansheeEditor
  24. {
  25. const UINT32 GUISceneTreeView::ELEMENT_EXTRA_SPACING = 3;
  26. const UINT32 GUISceneTreeView::INDENT_SIZE = 10;
  27. const UINT32 GUISceneTreeView::INITIAL_INDENT_OFFSET = 16;
  28. const UINT32 GUISceneTreeView::DRAG_MIN_DISTANCE = 3;
  29. const float GUISceneTreeView::AUTO_EXPAND_DELAY_SEC = 0.5f;
  30. const float GUISceneTreeView::SCROLL_AREA_HEIGHT_PCT = 0.1f;
  31. const UINT32 GUISceneTreeView::SCROLL_SPEED_PX_PER_SEC = 25;
  32. GUISceneTreeView::DraggedSceneObjects::DraggedSceneObjects(UINT32 numObjects)
  33. :numObjects(numObjects)
  34. {
  35. objects = cm_newN<HSceneObject>(numObjects);
  36. }
  37. GUISceneTreeView::DraggedSceneObjects::~DraggedSceneObjects()
  38. {
  39. cm_deleteN(objects, numObjects);
  40. objects = nullptr;
  41. }
  42. GUISceneTreeView::TreeElement::TreeElement()
  43. :mParent(nullptr), mFoldoutBtn(nullptr), mElement(nullptr), mIsSelected(false),
  44. mId(0), mIsExpanded(false), mSortedIdx(0), mIsDirty(false), mIsVisible(true)
  45. { }
  46. GUISceneTreeView::TreeElement::~TreeElement()
  47. {
  48. for(auto& child : mChildren)
  49. cm_delete(child);
  50. if(mFoldoutBtn != nullptr)
  51. GUIElement::destroy(mFoldoutBtn);
  52. if(mElement != nullptr)
  53. GUIElement::destroy(mElement);
  54. mChildren.clear();
  55. }
  56. bool GUISceneTreeView::TreeElement::isParentRec(TreeElement* element) const
  57. {
  58. TreeElement* curParent = mParent;
  59. while(curParent != nullptr)
  60. {
  61. if(curParent == element)
  62. return true;
  63. curParent = curParent->mParent;
  64. }
  65. return false;
  66. }
  67. GUISceneTreeView::TreeElement* GUISceneTreeView::InteractableElement::getTreeElement() const
  68. {
  69. if(!isTreeElement())
  70. return nullptr;
  71. UINT32 sortedIdx = (index - 1) / 2;
  72. auto findIter = std::find_if(parent->mChildren.begin(), parent->mChildren.end(),
  73. [&](const TreeElement* x) { return x->mSortedIdx == sortedIdx; });
  74. if(findIter != parent->mChildren.end())
  75. return *findIter;
  76. return nullptr;
  77. }
  78. GUISceneTreeView::GUISceneTreeView(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
  79. GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle,
  80. BS::GUIElementStyle* dragHighlightStyle, BS::GUIElementStyle* dragSepHighlightStyle, const GUILayoutOptions& layoutOptions)
  81. :GUIElementContainer(parent, layoutOptions), mBackgroundStyle(backgroundStyle),
  82. mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr), mIsElementSelected(false),
  83. mNameEditBox(nullptr), mSelectionBackgroundStyle(selectionBackgroundStyle), mDragInProgress(nullptr), mDragHighlightStyle(dragHighlightStyle),
  84. mDragSepHighlightStyle(dragSepHighlightStyle), mDragHighlight(nullptr), mDragSepHighlight(nullptr), mMouseOverDragElement(nullptr), mMouseOverDragElementTime(0.0f),
  85. mScrollState(ScrollState::None), mLastScrollTime(0.0f)
  86. {
  87. if(mBackgroundStyle == nullptr)
  88. mBackgroundStyle = parent.getSkin().getStyle("TreeViewBackground");
  89. if(mElementBtnStyle == nullptr)
  90. mElementBtnStyle = parent.getSkin().getStyle("TreeViewElementBtn");
  91. if(mFoldoutBtnStyle == nullptr)
  92. mFoldoutBtnStyle = parent.getSkin().getStyle("TreeViewFoldoutBtn");
  93. if(mSelectionBackgroundStyle == nullptr)
  94. mSelectionBackgroundStyle = parent.getSkin().getStyle("TreeViewSelectionBackground");
  95. if(mEditBoxStyle == nullptr)
  96. mEditBoxStyle = parent.getSkin().getStyle("TreeViewEditBox");
  97. if(mDragHighlightStyle == nullptr)
  98. mDragHighlightStyle = parent.getSkin().getStyle("TreeViewElementHighlight");
  99. if(mDragSepHighlightStyle == nullptr)
  100. mDragSepHighlightStyle = parent.getSkin().getStyle("TreeViewElementSepHighlight");
  101. mBackgroundImage = GUITexture::create(parent, mBackgroundStyle);
  102. mNameEditBox = GUITreeViewEditBox::create(parent, mEditBoxStyle);
  103. mNameEditBox->disableRecursively();
  104. mNameEditBox->onInputConfirmed.connect(boost::bind(&GUISceneTreeView::onEditAccepted, this));
  105. mNameEditBox->onInputCanceled.connect(boost::bind(&GUISceneTreeView::onEditCanceled, this));
  106. mDragHighlight = GUITexture::create(parent, mDragHighlightStyle);
  107. mDragSepHighlight = GUITexture::create(parent, mDragSepHighlightStyle);
  108. mDragHighlight->disableRecursively();
  109. mDragSepHighlight->disableRecursively();
  110. _registerChildElement(mBackgroundImage);
  111. _registerChildElement(mNameEditBox);
  112. _registerChildElement(mDragHighlight);
  113. _registerChildElement(mDragSepHighlight);
  114. }
  115. GUISceneTreeView::~GUISceneTreeView()
  116. {
  117. }
  118. GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
  119. GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle, GUIElementStyle* dragHighlightStyle,
  120. GUIElementStyle* dragSepHighlightStyle)
  121. {
  122. return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle, foldoutBtnStyle,
  123. selectionBackgroundStyle, editBoxStyle, dragHighlightStyle, dragSepHighlightStyle, GUILayoutOptions::create(&GUISkin::DefaultStyle));
  124. }
  125. GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, const GUIOptions& options, GUIElementStyle* backgroundStyle,
  126. GUIElementStyle* elementBtnStyle, GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle,
  127. GUIElementStyle* editBoxStyle, GUIElementStyle* dragHighlightStyle, GUIElementStyle* dragSepHighlightStyle)
  128. {
  129. return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle,
  130. foldoutBtnStyle, selectionBackgroundStyle, editBoxStyle, dragHighlightStyle, dragSepHighlightStyle, GUILayoutOptions::create(options, &GUISkin::DefaultStyle));
  131. }
  132. void GUISceneTreeView::update()
  133. {
  134. // Attempt to auto-expand elements we are dragging over
  135. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::SceneObject)
  136. {
  137. const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(mDragPosition);
  138. temporarilyExpandElement(element);
  139. }
  140. // NOTE - Instead of iterating through every visible element and comparing it with internal values,
  141. // I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
  142. // update if anything is actually dirty
  143. struct UpdateTreeElement
  144. {
  145. UpdateTreeElement(TreeElement* element, UINT32 seqIdx, bool visible)
  146. :element(element), seqIdx(seqIdx), visible(visible)
  147. { }
  148. TreeElement* element;
  149. UINT32 seqIdx;
  150. bool visible;
  151. };
  152. HSceneObject root = CM::gSceneManager().getRootNode();
  153. mRootElement.mSceneObject = root;
  154. mRootElement.mId = root->getId();
  155. mRootElement.mSortedIdx = 0;
  156. mRootElement.mIsExpanded = true;
  157. Stack<UpdateTreeElement>::type todo;
  158. todo.push(UpdateTreeElement(&mRootElement, 0, true));
  159. while(!todo.empty())
  160. {
  161. UpdateTreeElement updateElement = todo.top();
  162. TreeElement* current = updateElement.element;
  163. HSceneObject currentSO = current->mSceneObject;
  164. todo.pop();
  165. // Check if SceneObject has changed in any way and update the tree element
  166. if(updateElement.visible)
  167. {
  168. bool completeMatch = (UINT32)current->mChildren.size() == currentSO->getNumChildren();
  169. // Early exit case - Most commonly there will be no changes between active and cached data so
  170. // we first do a quick check in order to avoid expensive comparison later
  171. if(completeMatch)
  172. {
  173. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  174. {
  175. UINT32 curId = currentSO->getChild(i)->getId();
  176. if(curId != current->mChildren[i]->mId)
  177. {
  178. completeMatch = false;
  179. break;
  180. }
  181. }
  182. }
  183. // Not a complete match, compare everything and insert/delete elements as needed
  184. if(!completeMatch)
  185. {
  186. Vector<TreeElement*>::type newChildren;
  187. mTempToDelete.resize(current->mChildren.size());
  188. for(UINT32 i = 0; i < (UINT32)current->mChildren.size(); i++)
  189. mTempToDelete[i] = true;
  190. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  191. {
  192. HSceneObject currentSOChild = currentSO->getChild(i);
  193. UINT32 curId = currentSOChild->getId();
  194. bool found = false;
  195. for(UINT32 j = 0; j < current->mChildren.size(); j++)
  196. {
  197. TreeElement* currentChild = current->mChildren[j];
  198. if(curId == currentChild->mId)
  199. {
  200. mTempToDelete[j] = false;
  201. currentChild->mIsDirty = true;
  202. currentChild->mSortedIdx = (UINT32)newChildren.size();
  203. newChildren.push_back(currentChild);
  204. found = true;
  205. break;
  206. }
  207. }
  208. if(!found)
  209. {
  210. TreeElement* newChild = cm_new<TreeElement>();
  211. newChild->mParent = current;
  212. newChild->mSceneObject = currentSOChild;
  213. newChild->mId = currentSOChild->getId();
  214. newChild->mName = currentSOChild->getName();
  215. newChild->mSortedIdx = (UINT32)newChildren.size();
  216. newChild->mIsDirty = true;
  217. newChildren.push_back(newChild);
  218. }
  219. }
  220. for(UINT32 i = 0; i < current->mChildren.size(); i++)
  221. {
  222. if(!mTempToDelete[i])
  223. continue;
  224. if(current->mChildren[i]->mIsSelected)
  225. unselectElement(current->mChildren[i]);
  226. cm_delete(current->mChildren[i]);
  227. }
  228. current->mChildren = newChildren;
  229. current->mIsDirty = true;
  230. }
  231. // Check if name needs updating
  232. const String& name = current->mSceneObject->getName();
  233. if(current->mName != name)
  234. {
  235. current->mName = name;
  236. current->mIsDirty = true;
  237. }
  238. // Calculate the sorted index of the element based on its name
  239. TreeElement* parent = current->mParent;
  240. if(current->mIsDirty && parent != nullptr)
  241. {
  242. for(UINT32 i = 0; i < (UINT32)parent->mChildren.size(); i++)
  243. {
  244. INT32 stringCompare = current->mName.compare(parent->mChildren[i]->mName);
  245. if(stringCompare > 0)
  246. {
  247. if(current->mSortedIdx < parent->mChildren[i]->mSortedIdx)
  248. std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
  249. }
  250. else if(stringCompare < 0)
  251. {
  252. if(current->mSortedIdx > parent->mChildren[i]->mSortedIdx)
  253. std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
  254. }
  255. }
  256. }
  257. }
  258. bool visibilityChanged = false;
  259. if(current->mIsVisible != updateElement.visible)
  260. {
  261. visibilityChanged = true;
  262. current->mIsVisible = updateElement.visible;
  263. current->mIsDirty = true;
  264. }
  265. if(current->mIsDirty && current != &mRootElement)
  266. {
  267. if(updateElement.visible)
  268. {
  269. HString name(toWString(current->mName));
  270. if(current->mElement == nullptr)
  271. {
  272. current->mElement = GUILabel::create(_getParentWidget(), name, mElementBtnStyle);
  273. _registerChildElement(current->mElement);
  274. }
  275. if(current->mChildren.size() > 0)
  276. {
  277. if(current->mFoldoutBtn == nullptr)
  278. {
  279. current->mFoldoutBtn = GUIToggle::create(_getParentWidget(), GUIContent(HString(L"")), mFoldoutBtnStyle);
  280. _registerChildElement(current->mFoldoutBtn);
  281. current->mFoldoutBtn->onToggled.connect(boost::bind(&GUISceneTreeView::elementToggled, this, current, _1));
  282. if(current->mIsExpanded)
  283. current->mFoldoutBtn->toggleOn();
  284. }
  285. }
  286. else
  287. {
  288. if(current->mFoldoutBtn != nullptr)
  289. {
  290. GUIElement::destroy(current->mFoldoutBtn);
  291. current->mFoldoutBtn = nullptr;
  292. }
  293. }
  294. current->mElement->setContent(GUIContent(name));
  295. }
  296. else
  297. {
  298. if(current->mElement != nullptr)
  299. {
  300. GUIElement::destroy(current->mElement);
  301. current->mElement = nullptr;
  302. }
  303. if(current->mFoldoutBtn != nullptr)
  304. {
  305. GUIElement::destroy(current->mFoldoutBtn);
  306. current->mFoldoutBtn = nullptr;
  307. }
  308. if(visibilityChanged && current->mIsSelected)
  309. unselectElement(current);
  310. }
  311. markContentAsDirty();
  312. current->mIsDirty = false;
  313. }
  314. // Queue children for next iteration
  315. if(visibilityChanged || current->mIsVisible)
  316. {
  317. for(UINT32 i = 0; i < (UINT32)current->mChildren.size(); i++)
  318. {
  319. todo.push(UpdateTreeElement(current->mChildren[i], i, current->mIsVisible && current->mIsExpanded));
  320. }
  321. }
  322. }
  323. // Attempt to scroll if needed
  324. if(mScrollState != ScrollState::None)
  325. {
  326. GUIScrollArea* scrollArea = findParentScrollArea();
  327. if(scrollArea != nullptr)
  328. {
  329. float curTime = gTime().getTime();
  330. float timeDiff = curTime - mLastScrollTime;
  331. float secondsPerPixel = 1.0f / SCROLL_SPEED_PX_PER_SEC;
  332. switch(mScrollState)
  333. {
  334. case ScrollState::TransitioningUp:
  335. mScrollState = ScrollState::Up;
  336. mLastScrollTime = curTime;
  337. break;
  338. case ScrollState::TransitioningDown:
  339. mScrollState = ScrollState::Down;
  340. mLastScrollTime = curTime;
  341. break;
  342. case ScrollState::Up:
  343. {
  344. UINT32 scrollAmount = (UINT32)Math::floorToInt(timeDiff / secondsPerPixel);
  345. mLastScrollTime += scrollAmount * secondsPerPixel;
  346. scrollArea->scrollUpPx(scrollAmount);
  347. }
  348. break;
  349. case ScrollState::Down:
  350. {
  351. UINT32 scrollAmount = (UINT32)Math::floorToInt(timeDiff / secondsPerPixel);
  352. mLastScrollTime += scrollAmount * secondsPerPixel;
  353. scrollArea->scrollDownPx(scrollAmount);
  354. }
  355. break;
  356. }
  357. }
  358. }
  359. }
  360. bool GUISceneTreeView::mouseEvent(const GUIMouseEvent& event)
  361. {
  362. if(event.getType() == GUIMouseEventType::MouseUp)
  363. {
  364. if(DragAndDropManager::instance().isDragInProgress())
  365. return false;
  366. const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
  367. TreeElement* treeElement = nullptr;
  368. if(element != nullptr && element->isTreeElement())
  369. {
  370. treeElement = element->getTreeElement();
  371. }
  372. if(treeElement != nullptr && event.getPosition().x >= treeElement->mElement->getBounds().x)
  373. {
  374. if(event.isCtrlDown())
  375. {
  376. selectElement(treeElement);
  377. }
  378. else if(event.isShiftDown())
  379. {
  380. if(isSelectionActive())
  381. {
  382. TreeElement* selectionRoot = mSelectedElements[0].element;
  383. unselectAll();
  384. auto iterStartFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  385. [&] (const InteractableElement& x) { return x.parent == selectionRoot->mParent; } );
  386. bool foundStart = false;
  387. bool foundEnd = false;
  388. for(; iterStartFind != mVisibleElements.end(); ++iterStartFind)
  389. {
  390. if(!iterStartFind->isTreeElement())
  391. continue;
  392. TreeElement* curElem = iterStartFind->getTreeElement();
  393. if(curElem == selectionRoot)
  394. {
  395. foundStart = true;
  396. break;
  397. }
  398. }
  399. auto iterEndFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  400. [&] (const InteractableElement& x) { return &x == element; } );
  401. if(iterEndFind != mVisibleElements.end())
  402. foundEnd = true;
  403. if(foundStart && foundEnd)
  404. {
  405. if(iterStartFind < iterEndFind)
  406. {
  407. for(;iterStartFind != (iterEndFind + 1); ++iterStartFind)
  408. {
  409. if(iterStartFind->isTreeElement())
  410. selectElement(iterStartFind->getTreeElement());
  411. }
  412. }
  413. else if(iterEndFind < iterStartFind)
  414. {
  415. for(;iterEndFind != (iterStartFind + 1); ++iterEndFind)
  416. {
  417. if(iterEndFind->isTreeElement())
  418. selectElement(iterEndFind->getTreeElement());
  419. }
  420. }
  421. else
  422. selectElement(treeElement);
  423. }
  424. if(!foundStart || !foundEnd)
  425. selectElement(treeElement);
  426. }
  427. else
  428. {
  429. selectElement(treeElement);
  430. }
  431. }
  432. else
  433. {
  434. unselectAll();
  435. selectElement(treeElement);
  436. }
  437. markContentAsDirty();
  438. return true;
  439. }
  440. }
  441. else if(event.getType() == GUIMouseEventType::MouseDragStart)
  442. {
  443. mDragStartPosition = event.getPosition();
  444. }
  445. else if(event.getType() == GUIMouseEventType::MouseDrag)
  446. {
  447. UINT32 dist = mDragStartPosition.manhattanDist(event.getPosition());
  448. if(!DragAndDropManager::instance().isDragInProgress())
  449. {
  450. if(dist > DRAG_MIN_DISTANCE)
  451. {
  452. const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(mDragStartPosition);
  453. TreeElement* treeElement = nullptr;
  454. if(element != nullptr && element->isTreeElement())
  455. {
  456. // If element we are trying to drag isn't selected, select it
  457. TreeElement* treeElement = element->getTreeElement();
  458. auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
  459. [&] (const SelectedElement& x) { return x.element == treeElement; });
  460. if(iterFind == mSelectedElements.end())
  461. {
  462. unselectAll();
  463. selectElement(element->getTreeElement());
  464. }
  465. }
  466. DraggedSceneObjects* draggedSceneObjects = cm_new<DraggedSceneObjects>((UINT32)mSelectedElements.size());
  467. UINT32 cnt = 0;
  468. for(auto& selectedElement : mSelectedElements)
  469. {
  470. draggedSceneObjects->objects[cnt] = selectedElement.element->mSceneObject;
  471. cnt++;
  472. }
  473. DragAndDropManager::instance().startDrag(HTexture(), (UINT32)DragAndDropType::SceneObject, (void*)draggedSceneObjects,
  474. boost::bind(&GUISceneTreeView::dragAndDropEnded, this));
  475. mDragPosition = event.getPosition();
  476. mDragInProgress = true;
  477. mScrollState = ScrollState::None;
  478. markContentAsDirty();
  479. }
  480. }
  481. }
  482. else if(event.getType() == GUIMouseEventType::MouseDragAndDropDragged)
  483. {
  484. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::SceneObject)
  485. {
  486. mDragPosition = event.getPosition();
  487. mDragInProgress = true;
  488. markContentAsDirty();
  489. if(mBottomScrollBounds.contains(mDragPosition))
  490. {
  491. if(mScrollState != ScrollState::Down)
  492. mScrollState = ScrollState::TransitioningDown;
  493. }
  494. else if(mTopScrollBounds.contains(mDragPosition))
  495. {
  496. if(mScrollState != ScrollState::Up)
  497. mScrollState = ScrollState::TransitioningUp;
  498. }
  499. else
  500. mScrollState = ScrollState::None;
  501. return true;
  502. }
  503. }
  504. else if(event.getType() == GUIMouseEventType::MouseDragAndDropDropped)
  505. {
  506. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::SceneObject)
  507. {
  508. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(DragAndDropManager::instance().getDragData());
  509. const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
  510. TreeElement* treeElement = nullptr;
  511. if(element != nullptr)
  512. {
  513. if(element->isTreeElement())
  514. treeElement = element->getTreeElement();
  515. else
  516. treeElement = element->parent;
  517. }
  518. if(treeElement != nullptr)
  519. {
  520. Vector<HSceneObject>::type sceneObjects;
  521. HSceneObject newParent = treeElement->mSceneObject;
  522. for(UINT32 i = 0; i < draggedSceneObjects->numObjects; i++)
  523. {
  524. if(draggedSceneObjects->objects[i] != newParent)
  525. sceneObjects.push_back(draggedSceneObjects->objects[i]);
  526. }
  527. CmdReparentSO::execute(sceneObjects, newParent);
  528. }
  529. unselectAll();
  530. return true;
  531. }
  532. }
  533. else if(event.getType() == GUIMouseEventType::MouseOut)
  534. {
  535. mDragInProgress = false;
  536. markContentAsDirty();
  537. }
  538. return false;
  539. }
  540. bool GUISceneTreeView::commandEvent(const GUICommandEvent& ev)
  541. {
  542. if(ev.getType() == GUICommandEventType::Rename)
  543. {
  544. if(isSelectionActive() && mEditElement == nullptr)
  545. {
  546. unselectAll();
  547. enableEdit(mSelectedElements[0].element);
  548. }
  549. return true;
  550. }
  551. if(ev.getType() == GUICommandEventType::CursorMoveUp || ev.getType() == GUICommandEventType::SelectUp)
  552. {
  553. TreeElement* topMostElement = getTopMostSelectedElement();
  554. auto topMostIter = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  555. [&] (const InteractableElement& x) { return x.getTreeElement() == topMostElement; });
  556. if(topMostIter != mVisibleElements.end() && topMostIter != mVisibleElements.begin())
  557. {
  558. do
  559. {
  560. topMostIter--;
  561. } while (!topMostIter->isTreeElement() && topMostIter != mVisibleElements.begin());
  562. if(topMostIter->isTreeElement())
  563. {
  564. if(ev.getType() == GUICommandEventType::CursorMoveUp)
  565. unselectAll();
  566. selectElement(topMostIter->getTreeElement());
  567. }
  568. }
  569. }
  570. else if(ev.getType() == GUICommandEventType::CursorMoveDown || ev.getType() == GUICommandEventType::SelectDown)
  571. {
  572. TreeElement* bottoMostElement = getBottomMostSelectedElement();
  573. auto bottomMostIter = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  574. [&] (const InteractableElement& x) { return x.getTreeElement() == bottoMostElement; });
  575. if(bottomMostIter != mVisibleElements.end())
  576. {
  577. do
  578. {
  579. bottomMostIter++;
  580. } while (bottomMostIter != mVisibleElements.end() && !bottomMostIter->isTreeElement());
  581. if(bottomMostIter != mVisibleElements.end() && bottomMostIter->isTreeElement())
  582. {
  583. if(ev.getType() == GUICommandEventType::CursorMoveDown)
  584. unselectAll();
  585. selectElement(bottomMostIter->getTreeElement());
  586. }
  587. }
  588. }
  589. return false;
  590. }
  591. void GUISceneTreeView::dragAndDropEnded()
  592. {
  593. mDragInProgress = false;
  594. markContentAsDirty();
  595. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(DragAndDropManager::instance().getDragData());
  596. cm_delete(draggedSceneObjects);
  597. }
  598. bool GUISceneTreeView::isSelectionActive() const
  599. {
  600. return mIsElementSelected && mSelectedElements.size() > 0;
  601. }
  602. void GUISceneTreeView::selectElement(TreeElement* element)
  603. {
  604. auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
  605. [&] (const SelectedElement& x) { return x.element == element; });
  606. if(iterFind == mSelectedElements.end())
  607. {
  608. GUITexture* background = GUITexture::create(_getParentWidget(), mSelectionBackgroundStyle);
  609. _registerChildElement(background);
  610. element->mIsSelected = true;
  611. mSelectedElements.push_back(SelectedElement(element, background));
  612. mIsElementSelected = true;
  613. }
  614. }
  615. void GUISceneTreeView::unselectElement(TreeElement* element)
  616. {
  617. auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
  618. [&] (const SelectedElement& x) { return x.element == element; });
  619. if(iterFind != mSelectedElements.end())
  620. {
  621. iterFind->element->mIsSelected = false;
  622. GUIElement::destroy(iterFind->background);
  623. mSelectedElements.erase(iterFind);
  624. markContentAsDirty();
  625. }
  626. mIsElementSelected = mSelectedElements.size() > 0;
  627. }
  628. void GUISceneTreeView::unselectAll()
  629. {
  630. for(auto& selectedElem : mSelectedElements)
  631. {
  632. selectedElem.element->mIsSelected = false;
  633. GUIElement::destroy(selectedElem.background);
  634. }
  635. mSelectedElements.clear();
  636. mIsElementSelected = false;
  637. markContentAsDirty();
  638. }
  639. void GUISceneTreeView::elementToggled(TreeElement* element, bool toggled)
  640. {
  641. element->mIsExpanded = toggled;
  642. }
  643. void GUISceneTreeView::onEditAccepted()
  644. {
  645. disableEdit(true);
  646. }
  647. void GUISceneTreeView::onEditCanceled()
  648. {
  649. if(mEditElement != nullptr)
  650. disableEdit(false);
  651. }
  652. void GUISceneTreeView::enableEdit(TreeElement* element)
  653. {
  654. assert(mEditElement == nullptr);
  655. mEditElement = element;
  656. mNameEditBox->enableRecursively();
  657. mNameEditBox->setFocus(true);
  658. if(element->mElement != nullptr)
  659. element->mElement->disableRecursively();
  660. }
  661. void GUISceneTreeView::disableEdit(bool applyChanges)
  662. {
  663. assert(mEditElement != nullptr);
  664. if(mEditElement->mElement != nullptr)
  665. mEditElement->mElement->enableRecursively();
  666. if(applyChanges)
  667. {
  668. String newName = toString(mNameEditBox->getText());
  669. CmdEditPlainFieldGO<String>::execute(mEditElement->mSceneObject, "mName", newName);
  670. }
  671. mNameEditBox->disableRecursively();
  672. mEditElement = nullptr;
  673. }
  674. Vector2I GUISceneTreeView::_getOptimalSize() const
  675. {
  676. struct UpdateTreeElement
  677. {
  678. UpdateTreeElement(const TreeElement* element, UINT32 indent)
  679. :element(element), indent(indent)
  680. { }
  681. const TreeElement* element;
  682. UINT32 indent;
  683. };
  684. Vector2I optimalSize;
  685. if(_getLayoutOptions().fixedWidth && _getLayoutOptions().fixedHeight)
  686. {
  687. optimalSize.x = _getLayoutOptions().width;
  688. optimalSize.y = _getLayoutOptions().height;
  689. }
  690. else
  691. {
  692. Stack<UpdateTreeElement>::type todo;
  693. todo.push(UpdateTreeElement(&mRootElement, 0));
  694. while(!todo.empty())
  695. {
  696. UpdateTreeElement currentUpdateElement = todo.top();
  697. const TreeElement* current = currentUpdateElement.element;
  698. todo.pop();
  699. INT32 yOffset = 0;
  700. if(current->mElement != nullptr)
  701. {
  702. Vector2I curOptimalSize = current->mElement->_getOptimalSize();
  703. optimalSize.x = std::max(optimalSize.x,
  704. (INT32)(INITIAL_INDENT_OFFSET + curOptimalSize.x + currentUpdateElement.indent * INDENT_SIZE));
  705. yOffset = curOptimalSize.y + ELEMENT_EXTRA_SPACING;
  706. }
  707. optimalSize.y += yOffset;
  708. for(auto& child : current->mChildren)
  709. {
  710. if(!child->mIsVisible)
  711. continue;
  712. todo.push(UpdateTreeElement(child, currentUpdateElement.indent + 1));
  713. }
  714. }
  715. if(_getLayoutOptions().fixedWidth)
  716. optimalSize.x = _getLayoutOptions().width;
  717. else
  718. {
  719. if(_getLayoutOptions().minWidth > 0)
  720. optimalSize.x = std::max((INT32)_getLayoutOptions().minWidth, optimalSize.x);
  721. if(_getLayoutOptions().maxWidth > 0)
  722. optimalSize.x = std::min((INT32)_getLayoutOptions().maxWidth, optimalSize.x);
  723. }
  724. if(_getLayoutOptions().fixedHeight)
  725. optimalSize.y = _getLayoutOptions().height;
  726. else
  727. {
  728. if(_getLayoutOptions().minHeight > 0)
  729. optimalSize.y = std::max((INT32)_getLayoutOptions().minHeight, optimalSize.y);
  730. if(_getLayoutOptions().maxHeight > 0)
  731. optimalSize.y = std::min((INT32)_getLayoutOptions().maxHeight, optimalSize.y);
  732. }
  733. }
  734. return optimalSize;
  735. }
  736. void GUISceneTreeView::updateClippedBounds()
  737. {
  738. Vector2I offset = _getOffset();
  739. mClippedBounds = RectI(offset.x, offset.y, _getWidth(), _getHeight());
  740. RectI localClipRect(mClipRect.x + mOffset.x, mClipRect.y + mOffset.y, mClipRect.width, mClipRect.height);
  741. mClippedBounds.clip(localClipRect);
  742. }
  743. void GUISceneTreeView::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  744. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  745. {
  746. struct UpdateTreeElement
  747. {
  748. UpdateTreeElement(TreeElement* element, UINT32 indent)
  749. :element(element), indent(indent)
  750. { }
  751. TreeElement* element;
  752. UINT32 indent;
  753. };
  754. mVisibleElements.clear();
  755. Stack<UpdateTreeElement>::type todo;
  756. todo.push(UpdateTreeElement(&mRootElement, 0));
  757. // NOTE - Instead of iterating through all elements, try to find those within the clip rect
  758. // and only iterate through those. Others should somehow be marked in-active (similar to GUIElement::isDisabled()?)
  759. Vector<TreeElement*>::type tempOrderedElements;
  760. Vector2I offset(x, y);
  761. while(!todo.empty())
  762. {
  763. UpdateTreeElement currentUpdateElement = todo.top();
  764. TreeElement* current = currentUpdateElement.element;
  765. UINT32 indent = currentUpdateElement.indent;
  766. todo.pop();
  767. INT32 btnHeight = 0;
  768. INT32 yOffset = 0;
  769. if(current->mElement != nullptr)
  770. {
  771. Vector2I elementSize = current->mElement->_getOptimalSize();
  772. btnHeight = elementSize.y;
  773. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 0, RectI(x, offset.y, width, ELEMENT_EXTRA_SPACING)));
  774. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 1, RectI(x, offset.y + ELEMENT_EXTRA_SPACING, width, btnHeight)));
  775. offset.x = x + INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
  776. offset.y += ELEMENT_EXTRA_SPACING;
  777. current->mElement->_setOffset(offset);
  778. current->mElement->_setWidth(elementSize.x);
  779. current->mElement->_setHeight(elementSize.y);
  780. current->mElement->_setAreaDepth(areaDepth);
  781. current->mElement->_setWidgetDepth(widgetDepth);
  782. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  783. current->mElement->_setClipRect(elemClipRect);
  784. yOffset = btnHeight;
  785. }
  786. if(current->mFoldoutBtn != nullptr)
  787. {
  788. Vector2I elementSize = current->mFoldoutBtn->_getOptimalSize();
  789. offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.x);
  790. Vector2I myOffset = offset;
  791. myOffset.y -= 2; // TODO: Arbitrary offset, I should adjust it based on font baseline so that the button is nicely centered on text
  792. if(elementSize.y > btnHeight)
  793. {
  794. UINT32 diff = elementSize.y - btnHeight;
  795. float half = diff * 0.5f;
  796. myOffset.y -= Math::floorToInt(half);
  797. }
  798. current->mFoldoutBtn->_setOffset(myOffset);
  799. current->mFoldoutBtn->_setWidth(elementSize.x);
  800. current->mFoldoutBtn->_setHeight(elementSize.y);
  801. current->mFoldoutBtn->_setAreaDepth(areaDepth);
  802. current->mFoldoutBtn->_setWidgetDepth(widgetDepth);
  803. RectI elemClipRect(clipRect.x - myOffset.x, clipRect.y - myOffset.y, clipRect.width, clipRect.height);
  804. current->mFoldoutBtn->_setClipRect(elemClipRect);
  805. }
  806. offset.y += yOffset;
  807. tempOrderedElements.resize(current->mChildren.size(), nullptr);
  808. for(auto& child : current->mChildren)
  809. {
  810. tempOrderedElements[child->mSortedIdx] = child;
  811. }
  812. for(auto iter = tempOrderedElements.rbegin(); iter != tempOrderedElements.rend(); ++iter)
  813. {
  814. TreeElement* child = *iter;
  815. if(!child->mIsVisible)
  816. continue;
  817. todo.push(UpdateTreeElement(child, indent + 1));
  818. }
  819. }
  820. UINT32 remainingHeight = (UINT32)std::max(0, (INT32)height - (offset.y - y));
  821. if(remainingHeight > 0)
  822. mVisibleElements.push_back(InteractableElement(&mRootElement, (UINT32)mRootElement.mChildren.size() * 2, RectI(x, offset.y, width, remainingHeight)));
  823. for(auto selectedElem : mSelectedElements)
  824. {
  825. GUILabel* targetElement = selectedElem.element->mElement;
  826. Vector2I offset = targetElement->_getOffset();
  827. offset.x = x;
  828. selectedElem.background->_setOffset(offset);
  829. selectedElem.background->_setWidth(width);
  830. selectedElem.background->_setHeight(targetElement->_getHeight());
  831. selectedElem.background->_setAreaDepth(areaDepth + 1);
  832. selectedElem.background->_setWidgetDepth(widgetDepth);
  833. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  834. selectedElem.background->_setClipRect(elemClipRect);
  835. }
  836. if(mEditElement != nullptr)
  837. {
  838. GUILabel* targetElement = mEditElement->mElement;
  839. Vector2I offset = targetElement->_getOffset();
  840. UINT32 remainingWidth = (UINT32)std::max(0, (((INT32)width) - (offset.x - x)));
  841. mNameEditBox->_setOffset(offset);
  842. mNameEditBox->_setWidth(remainingWidth);
  843. mNameEditBox->_setHeight(targetElement->_getHeight());
  844. mNameEditBox->_setAreaDepth(areaDepth);
  845. mNameEditBox->_setWidgetDepth(widgetDepth);
  846. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  847. mNameEditBox->_setClipRect(elemClipRect);
  848. }
  849. if(mDragInProgress)
  850. {
  851. const InteractableElement* interactableElement = findElementUnderCoord(mDragPosition);
  852. if(interactableElement == nullptr)
  853. {
  854. if(!mDragHighlight->_isDisabled())
  855. mDragHighlight->disableRecursively();
  856. if(!mDragSepHighlight->_isDisabled())
  857. mDragSepHighlight->disableRecursively();
  858. }
  859. else
  860. {
  861. if(interactableElement->isTreeElement())
  862. {
  863. if(!mDragSepHighlight->_isDisabled())
  864. mDragSepHighlight->disableRecursively();
  865. if(mDragHighlight->_isDisabled())
  866. mDragHighlight->enableRecursively();
  867. Vector2I offset(interactableElement->bounds.x, interactableElement->bounds.y);
  868. mDragHighlight->_setOffset(offset);
  869. mDragHighlight->_setWidth(interactableElement->bounds.width);
  870. mDragHighlight->_setHeight(interactableElement->bounds.height);
  871. mDragHighlight->_setAreaDepth(areaDepth + 1);
  872. mDragHighlight->_setWidgetDepth(widgetDepth);
  873. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  874. mDragHighlight->_setClipRect(elemClipRect);
  875. }
  876. else
  877. {
  878. if(!mDragHighlight->_isDisabled())
  879. mDragHighlight->disableRecursively();
  880. if(mDragSepHighlight->_isDisabled())
  881. mDragSepHighlight->enableRecursively();
  882. Vector2I offset(interactableElement->bounds.x, interactableElement->bounds.y);
  883. mDragSepHighlight->_setOffset(offset);
  884. mDragSepHighlight->_setWidth(interactableElement->bounds.width);
  885. mDragSepHighlight->_setHeight(interactableElement->bounds.height);
  886. mDragSepHighlight->_setAreaDepth(areaDepth + 1);
  887. mDragSepHighlight->_setWidgetDepth(widgetDepth);
  888. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  889. mDragSepHighlight->_setClipRect(elemClipRect);
  890. }
  891. }
  892. }
  893. else
  894. {
  895. if(!mDragHighlight->_isDisabled())
  896. mDragHighlight->disableRecursively();
  897. if(!mDragSepHighlight->_isDisabled())
  898. mDragSepHighlight->disableRecursively();
  899. }
  900. // Update scroll bounds
  901. UINT32 scrollHeight = (UINT32)Math::roundToInt(clipRect.height * SCROLL_AREA_HEIGHT_PCT);
  902. mTopScrollBounds.x = clipRect.x;
  903. mTopScrollBounds.y = clipRect.y;
  904. mTopScrollBounds.width = clipRect.width;
  905. mTopScrollBounds.height = scrollHeight;
  906. mBottomScrollBounds.x = clipRect.x;
  907. mBottomScrollBounds.y = clipRect.y + clipRect.height - scrollHeight;
  908. mBottomScrollBounds.width = clipRect.width;
  909. mBottomScrollBounds.height = scrollHeight;
  910. }
  911. const GUISceneTreeView::InteractableElement* GUISceneTreeView::findElementUnderCoord(const CM::Vector2I& coord) const
  912. {
  913. for(auto& element : mVisibleElements)
  914. {
  915. if(element.bounds.contains(coord))
  916. {
  917. return &element;
  918. }
  919. }
  920. return nullptr;
  921. }
  922. GUISceneTreeView::TreeElement* GUISceneTreeView::getTopMostSelectedElement() const
  923. {
  924. auto topMostElement = mVisibleElements.end();
  925. for(auto& selectedElement : mSelectedElements)
  926. {
  927. auto iterFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  928. [&] (const InteractableElement& x) { return x.getTreeElement() == selectedElement.element; });
  929. if(iterFind != mVisibleElements.end())
  930. {
  931. if(topMostElement == mVisibleElements.end())
  932. topMostElement = iterFind;
  933. else
  934. {
  935. if(iterFind->bounds.y < topMostElement->bounds.y)
  936. topMostElement = iterFind;
  937. }
  938. }
  939. }
  940. if(topMostElement != mVisibleElements.end())
  941. return topMostElement->getTreeElement();
  942. else
  943. return nullptr;
  944. }
  945. GUISceneTreeView::TreeElement* GUISceneTreeView::getBottomMostSelectedElement() const
  946. {
  947. auto& botMostElement = mVisibleElements.end();
  948. for(auto& selectedElement : mSelectedElements)
  949. {
  950. auto iterFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  951. [&] (const InteractableElement& x) { return x.getTreeElement() == selectedElement.element; });
  952. if(iterFind != mVisibleElements.end())
  953. {
  954. if(botMostElement == mVisibleElements.end())
  955. botMostElement = iterFind;
  956. else
  957. {
  958. if((iterFind->bounds.y + iterFind->bounds.height) > (botMostElement->bounds.y + botMostElement->bounds.height))
  959. botMostElement = iterFind;
  960. }
  961. }
  962. }
  963. if(botMostElement != mVisibleElements.end())
  964. return botMostElement->getTreeElement();
  965. else
  966. return nullptr;
  967. }
  968. void GUISceneTreeView::temporarilyExpandElement(const GUISceneTreeView::InteractableElement* mouseOverElement)
  969. {
  970. TreeElement* treeElement = nullptr;
  971. if(mouseOverElement != nullptr && mouseOverElement->isTreeElement())
  972. treeElement = mouseOverElement->getTreeElement();
  973. if(treeElement == nullptr || treeElement != mMouseOverDragElement)
  974. {
  975. while(!mAutoExpandedElements.empty())
  976. {
  977. TreeElement* autoExpandedElement = mAutoExpandedElements.top();
  978. bool unexpandElement = false;
  979. if(mouseOverElement != nullptr && mouseOverElement->parent != nullptr)
  980. {
  981. if(mouseOverElement->parent != autoExpandedElement && !mouseOverElement->parent->isParentRec(autoExpandedElement))
  982. unexpandElement = true;
  983. else
  984. break;
  985. }
  986. else
  987. unexpandElement = true;
  988. if(unexpandElement)
  989. {
  990. autoExpandedElement->mIsExpanded = false;
  991. if(autoExpandedElement->mFoldoutBtn != nullptr)
  992. autoExpandedElement->mFoldoutBtn->toggleOff();
  993. mAutoExpandedElements.pop();
  994. }
  995. }
  996. mMouseOverDragElement = treeElement;
  997. mMouseOverDragElementTime = gTime().getTime();
  998. }
  999. else
  1000. {
  1001. if(mMouseOverDragElement != nullptr && !mMouseOverDragElement->mIsExpanded)
  1002. {
  1003. float timeDiff = gTime().getTime() - mMouseOverDragElementTime;
  1004. if(timeDiff >= AUTO_EXPAND_DELAY_SEC)
  1005. {
  1006. mAutoExpandedElements.push(mMouseOverDragElement);
  1007. mMouseOverDragElement->mIsExpanded = true;
  1008. if(mMouseOverDragElement->mFoldoutBtn != nullptr)
  1009. mMouseOverDragElement->mFoldoutBtn->toggleOn();
  1010. }
  1011. }
  1012. }
  1013. }
  1014. GUIScrollArea* GUISceneTreeView::findParentScrollArea() const
  1015. {
  1016. GUIElementBase* parent = _getParent();
  1017. while(parent != nullptr)
  1018. {
  1019. if(parent->_getType() == GUIElementBase::Type::Element)
  1020. {
  1021. GUIElement* parentElement = static_cast<GUIElement*>(parent);
  1022. if(parentElement->getElementType() == GUIElement::ElementType::ScrollArea)
  1023. {
  1024. GUIScrollArea* scrollArea = static_cast<GUIScrollArea*>(parentElement);
  1025. return scrollArea;
  1026. }
  1027. }
  1028. parent = parent->_getParent();
  1029. }
  1030. return nullptr;
  1031. }
  1032. const String& GUISceneTreeView::getGUITypeName()
  1033. {
  1034. static String typeName = "SceneTreeView";
  1035. return typeName;
  1036. }
  1037. }