BsGUISceneTreeView.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. using namespace CamelotFramework;
  17. using namespace BansheeEngine;
  18. namespace BansheeEditor
  19. {
  20. const UINT32 GUISceneTreeView::ELEMENT_EXTRA_SPACING = 3;
  21. const UINT32 GUISceneTreeView::INDENT_SIZE = 10;
  22. const UINT32 GUISceneTreeView::INITIAL_INDENT_OFFSET = 16;
  23. GUISceneTreeView::TreeElement::TreeElement()
  24. :mParent(nullptr), mFoldoutBtn(nullptr), mElement(nullptr),
  25. mId(0), mIsExpanded(false), mSortedIdx(0), mIsDirty(false), mIsVisible(true)
  26. { }
  27. GUISceneTreeView::TreeElement::~TreeElement()
  28. {
  29. for(auto& child : mChildren)
  30. cm_delete(child);
  31. if(mFoldoutBtn != nullptr)
  32. GUIElement::destroy(mFoldoutBtn);
  33. if(mElement != nullptr)
  34. GUIElement::destroy(mElement);
  35. mChildren.clear();
  36. }
  37. GUISceneTreeView::GUISceneTreeView(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
  38. GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle,
  39. const GUILayoutOptions& layoutOptions)
  40. :GUIElementContainer(parent, layoutOptions), mBackgroundStyle(backgroundStyle),
  41. mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr),
  42. mSelectedElement(nullptr), mSelectionBackground(nullptr), mNameEditBox(nullptr), mSelectionBackgroundStyle(selectionBackgroundStyle)
  43. {
  44. if(mBackgroundStyle == nullptr)
  45. mBackgroundStyle = parent.getSkin().getStyle("TreeViewBackground");
  46. if(mElementBtnStyle == nullptr)
  47. mElementBtnStyle = parent.getSkin().getStyle("TreeViewElementBtn");
  48. if(mFoldoutBtnStyle == nullptr)
  49. mFoldoutBtnStyle = parent.getSkin().getStyle("TreeViewFoldoutBtn");
  50. if(mSelectionBackgroundStyle == nullptr)
  51. mSelectionBackgroundStyle = parent.getSkin().getStyle("TreeViewSelectionBackground");
  52. if(mEditBoxStyle == nullptr)
  53. mEditBoxStyle = parent.getSkin().getStyle("TreeViewEditBox");
  54. mBackgroundImage = GUITexture::create(parent, mBackgroundStyle);
  55. mSelectionBackground = GUITexture::create(parent, mSelectionBackgroundStyle);
  56. mSelectionBackground->disableRecursively();
  57. mNameEditBox = GUITreeViewEditBox::create(parent, mEditBoxStyle);
  58. mNameEditBox->disableRecursively();
  59. mNameEditBox->onInputConfirmed.connect(boost::bind(&GUISceneTreeView::onEditAccepted, this));
  60. mNameEditBox->onInputCanceled.connect(boost::bind(&GUISceneTreeView::onEditCanceled, this));
  61. _registerChildElement(mBackgroundImage);
  62. _registerChildElement(mSelectionBackground);
  63. _registerChildElement(mNameEditBox);
  64. }
  65. GUISceneTreeView::~GUISceneTreeView()
  66. {
  67. }
  68. GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
  69. GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle)
  70. {
  71. return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle, foldoutBtnStyle,
  72. selectionBackgroundStyle, editBoxStyle, GUILayoutOptions::create(&GUISkin::DefaultStyle));
  73. }
  74. GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, const GUIOptions& options, GUIElementStyle* backgroundStyle,
  75. GUIElementStyle* elementBtnStyle, GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle)
  76. {
  77. return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle,
  78. foldoutBtnStyle, selectionBackgroundStyle, editBoxStyle, GUILayoutOptions::create(options, &GUISkin::DefaultStyle));
  79. }
  80. void GUISceneTreeView::update()
  81. {
  82. // NOTE - Instead of iterating through every visible element and comparing it with internal values,
  83. // I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
  84. // update if anything is actually dirty
  85. struct UpdateTreeElement
  86. {
  87. UpdateTreeElement(TreeElement* element, UINT32 seqIdx, bool visible)
  88. :element(element), seqIdx(seqIdx), visible(visible)
  89. { }
  90. TreeElement* element;
  91. UINT32 seqIdx;
  92. bool visible;
  93. };
  94. HSceneObject root = CM::gSceneManager().getRootNode();
  95. mRootElement.mSceneObject = root;
  96. mRootElement.mId = root->getId();
  97. mRootElement.mSortedIdx = 0;
  98. mRootElement.mIsExpanded = true;
  99. Stack<UpdateTreeElement>::type todo;
  100. todo.push(UpdateTreeElement(&mRootElement, 0, true));
  101. while(!todo.empty())
  102. {
  103. UpdateTreeElement updateElement = todo.top();
  104. TreeElement* current = updateElement.element;
  105. HSceneObject currentSO = current->mSceneObject;
  106. todo.pop();
  107. // Check if SceneObject has changed in any way and update the tree element
  108. if(updateElement.visible)
  109. {
  110. bool completeMatch = (UINT32)current->mChildren.size() == currentSO->getNumChildren();
  111. // Early exit case - Most commonly there will be no changes between active and cached data so
  112. // we first do a quick check in order to avoid expensive comparison later
  113. if(completeMatch)
  114. {
  115. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  116. {
  117. UINT32 curId = currentSO->getChild(i)->getId();
  118. if(curId != current->mChildren[i]->mId)
  119. {
  120. completeMatch = false;
  121. break;
  122. }
  123. }
  124. }
  125. // Not a complete match, compare everything and insert/delete elements as needed
  126. if(!completeMatch)
  127. {
  128. Vector<TreeElement*>::type newChildren;
  129. mTempToDelete.resize(current->mChildren.size(), true);
  130. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  131. {
  132. HSceneObject currentSOChild = currentSO->getChild(i);
  133. UINT32 curId = currentSOChild->getId();
  134. bool found = false;
  135. for(UINT32 j = 0; j < current->mChildren.size(); j++)
  136. {
  137. TreeElement* currentChild = current->mChildren[j];
  138. if(curId == currentChild->mId)
  139. {
  140. mTempToDelete[j] = false;
  141. currentChild->mIsDirty = true;
  142. currentChild->mSortedIdx = (UINT32)newChildren.size();
  143. newChildren.push_back(currentChild);
  144. found = true;
  145. break;
  146. }
  147. }
  148. if(!found)
  149. {
  150. TreeElement* newChild = cm_new<TreeElement>();
  151. newChild->mParent = current;
  152. newChild->mSceneObject = currentSOChild;
  153. newChild->mId = currentSOChild->getId();
  154. newChild->mName = currentSOChild->getName();
  155. newChild->mSortedIdx = (UINT32)newChildren.size();
  156. newChild->mIsDirty = true;
  157. newChildren.push_back(newChild);
  158. }
  159. }
  160. for(UINT32 i = 0; i < current->mChildren.size(); i++)
  161. {
  162. if(!mTempToDelete[i])
  163. continue;
  164. cm_delete(current->mChildren[i]);
  165. }
  166. current->mChildren = newChildren;
  167. current->mIsDirty = true;
  168. }
  169. // Check if name needs updating
  170. const String& name = current->mSceneObject->getName();
  171. if(current->mName != name)
  172. {
  173. current->mName = name;
  174. current->mIsDirty = true;
  175. }
  176. // Calculate the sorted index of the element based on its name
  177. TreeElement* parent = current->mParent;
  178. if(current->mIsDirty && parent != nullptr)
  179. {
  180. for(UINT32 i = 0; i < (UINT32)parent->mChildren.size(); i++)
  181. {
  182. INT32 stringCompare = current->mName.compare(parent->mChildren[i]->mName);
  183. if(stringCompare > 0)
  184. {
  185. if(current->mSortedIdx < parent->mChildren[i]->mSortedIdx)
  186. std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
  187. }
  188. else if(stringCompare < 0)
  189. {
  190. if(current->mSortedIdx > parent->mChildren[i]->mSortedIdx)
  191. std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
  192. }
  193. }
  194. }
  195. }
  196. bool visibilityChanged = false;
  197. if(current->mIsVisible != updateElement.visible)
  198. {
  199. visibilityChanged = true;
  200. current->mIsVisible = updateElement.visible;
  201. current->mIsDirty = true;
  202. }
  203. if(current->mIsDirty && current != &mRootElement)
  204. {
  205. if(updateElement.visible)
  206. {
  207. HString name(toWString(current->mName));
  208. if(current->mElement == nullptr)
  209. {
  210. current->mElement = GUILabel::create(_getParentWidget(), name, mElementBtnStyle);
  211. _registerChildElement(current->mElement);
  212. }
  213. if(current->mChildren.size() > 0)
  214. {
  215. if(current->mFoldoutBtn == nullptr)
  216. {
  217. current->mFoldoutBtn = GUIToggle::create(_getParentWidget(), GUIContent(HString(L"")), mFoldoutBtnStyle);
  218. _registerChildElement(current->mFoldoutBtn);
  219. current->mFoldoutBtn->onToggled.connect(boost::bind(&GUISceneTreeView::elementToggled, this, current, _1));
  220. }
  221. }
  222. else
  223. {
  224. if(current->mFoldoutBtn != nullptr)
  225. {
  226. GUIElement::destroy(current->mFoldoutBtn);
  227. current->mFoldoutBtn = nullptr;
  228. }
  229. }
  230. current->mElement->setContent(GUIContent(name));
  231. }
  232. else
  233. {
  234. if(current->mElement != nullptr)
  235. {
  236. GUIElement::destroy(current->mElement);
  237. current->mElement = nullptr;
  238. }
  239. if(current->mFoldoutBtn != nullptr)
  240. {
  241. GUIElement::destroy(current->mFoldoutBtn);
  242. current->mFoldoutBtn = nullptr;
  243. }
  244. }
  245. markContentAsDirty();
  246. current->mIsDirty = false;
  247. }
  248. // Queue children for next iteration
  249. if(visibilityChanged || current->mIsVisible)
  250. {
  251. for(UINT32 i = 0; i < (UINT32)current->mChildren.size(); i++)
  252. {
  253. todo.push(UpdateTreeElement(current->mChildren[i], i, current->mIsVisible && current->mIsExpanded));
  254. }
  255. }
  256. }
  257. if(mSelectedElement != nullptr)
  258. {
  259. if(mSelectionBackground->_isDisabled())
  260. mSelectionBackground->enableRecursively();
  261. }
  262. else
  263. {
  264. if(!mSelectionBackground->_isDisabled())
  265. mSelectionBackground->disableRecursively();
  266. }
  267. }
  268. bool GUISceneTreeView::mouseEvent(const GUIMouseEvent& event)
  269. {
  270. if(event.getType() == GUIMouseEventType::MouseUp)
  271. {
  272. const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
  273. if(element != nullptr && element->isTreeElement())
  274. mSelectedElement = interactableToRealElement(*element);
  275. markContentAsDirty();
  276. return true;
  277. }
  278. return false;
  279. }
  280. bool GUISceneTreeView::commandEvent(const GUICommandEvent& ev)
  281. {
  282. if(ev.getType() == GUICommandEventType::Rename)
  283. {
  284. if(mSelectedElement != nullptr && mEditElement == nullptr)
  285. enableEdit(mSelectedElement);
  286. return true;
  287. }
  288. return false;
  289. }
  290. void GUISceneTreeView::elementToggled(TreeElement* element, bool toggled)
  291. {
  292. element->mIsExpanded = toggled;
  293. }
  294. void GUISceneTreeView::onEditAccepted()
  295. {
  296. disableEdit(true);
  297. }
  298. void GUISceneTreeView::onEditCanceled()
  299. {
  300. disableEdit(false);
  301. }
  302. void GUISceneTreeView::enableEdit(TreeElement* element)
  303. {
  304. assert(mEditElement == nullptr);
  305. mEditElement = element;
  306. mNameEditBox->enableRecursively();
  307. if(element->mElement != nullptr)
  308. element->mElement->disableRecursively();
  309. }
  310. void GUISceneTreeView::disableEdit(bool applyChanges)
  311. {
  312. assert(mEditElement != nullptr);
  313. if(mEditElement->mElement != nullptr)
  314. mEditElement->mElement->enableRecursively();
  315. if(applyChanges)
  316. {
  317. // TODO - Actually rename GameObject. Don't forget Undo/Redo
  318. }
  319. mNameEditBox->disableRecursively();
  320. mEditElement = nullptr;
  321. }
  322. Vector2I GUISceneTreeView::_getOptimalSize() const
  323. {
  324. struct UpdateTreeElement
  325. {
  326. UpdateTreeElement(const TreeElement* element, UINT32 indent)
  327. :element(element), indent(indent)
  328. { }
  329. const TreeElement* element;
  330. UINT32 indent;
  331. };
  332. Vector2I optimalSize;
  333. if(_getLayoutOptions().fixedWidth && _getLayoutOptions().fixedHeight)
  334. {
  335. optimalSize.x = _getLayoutOptions().width;
  336. optimalSize.y = _getLayoutOptions().height;
  337. }
  338. else
  339. {
  340. Stack<UpdateTreeElement>::type todo;
  341. todo.push(UpdateTreeElement(&mRootElement, 0));
  342. optimalSize.y += ELEMENT_EXTRA_SPACING;
  343. while(!todo.empty())
  344. {
  345. UpdateTreeElement currentUpdateElement = todo.top();
  346. const TreeElement* current = currentUpdateElement.element;
  347. todo.pop();
  348. INT32 yOffset = 0;
  349. if(current->mElement != nullptr)
  350. {
  351. Vector2I curOptimalSize = current->mElement->_getOptimalSize();
  352. optimalSize.x = std::max(optimalSize.x,
  353. (INT32)(INITIAL_INDENT_OFFSET + curOptimalSize.x + currentUpdateElement.indent * INDENT_SIZE));
  354. yOffset = curOptimalSize.y + ELEMENT_EXTRA_SPACING;
  355. }
  356. optimalSize.y += yOffset;
  357. for(auto& child : current->mChildren)
  358. {
  359. if(!child->mIsVisible)
  360. continue;
  361. todo.push(UpdateTreeElement(child, currentUpdateElement.indent + 1));
  362. }
  363. }
  364. if(_getLayoutOptions().fixedWidth)
  365. optimalSize.x = _getLayoutOptions().width;
  366. else
  367. {
  368. if(_getLayoutOptions().minWidth > 0)
  369. optimalSize.x = std::max((INT32)_getLayoutOptions().minWidth, optimalSize.x);
  370. if(_getLayoutOptions().maxWidth > 0)
  371. optimalSize.x = std::min((INT32)_getLayoutOptions().maxWidth, optimalSize.x);
  372. }
  373. if(_getLayoutOptions().fixedHeight)
  374. optimalSize.y = _getLayoutOptions().height;
  375. else
  376. {
  377. if(_getLayoutOptions().minHeight > 0)
  378. optimalSize.y = std::max((INT32)_getLayoutOptions().minHeight, optimalSize.y);
  379. if(_getLayoutOptions().maxHeight > 0)
  380. optimalSize.y = std::min((INT32)_getLayoutOptions().maxHeight, optimalSize.y);
  381. }
  382. }
  383. return optimalSize;
  384. }
  385. void GUISceneTreeView::updateClippedBounds()
  386. {
  387. Vector2I offset = _getOffset();
  388. mClippedBounds = RectI(offset.x, offset.y, _getWidth(), _getHeight());
  389. }
  390. void GUISceneTreeView::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  391. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  392. {
  393. struct UpdateTreeElement
  394. {
  395. UpdateTreeElement(TreeElement* element, UINT32 indent)
  396. :element(element), indent(indent)
  397. { }
  398. TreeElement* element;
  399. UINT32 indent;
  400. };
  401. mVisibleElements.clear();
  402. Stack<UpdateTreeElement>::type todo;
  403. todo.push(UpdateTreeElement(&mRootElement, 0));
  404. // NOTE - Instead of iterating through all elements, try to find those within the clip rect
  405. // and only iterate through those. Others should somehow be marked in-active (similar to GUIElement::isDisabled()?)
  406. Vector<TreeElement*>::type tempOrderedElements;
  407. Vector2I offset(x, y);
  408. while(!todo.empty())
  409. {
  410. UpdateTreeElement currentUpdateElement = todo.top();
  411. TreeElement* current = currentUpdateElement.element;
  412. UINT32 indent = currentUpdateElement.indent;
  413. todo.pop();
  414. if(current->mParent != nullptr && current->mSortedIdx == 0)
  415. {
  416. mVisibleElements.push_back(InteractableElement(current->mParent, 0, RectI(x, offset.y, width, ELEMENT_EXTRA_SPACING)));
  417. }
  418. INT32 btnHeight = 0;
  419. INT32 yOffset = 0;
  420. if(current->mElement != nullptr)
  421. {
  422. Vector2I elementSize = current->mElement->_getOptimalSize();
  423. btnHeight = elementSize.y;
  424. offset.x = INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
  425. current->mElement->_setOffset(offset);
  426. current->mElement->_setWidth(elementSize.x);
  427. current->mElement->_setHeight(elementSize.y);
  428. current->mElement->_setAreaDepth(areaDepth);
  429. current->mElement->_setWidgetDepth(widgetDepth);
  430. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  431. current->mElement->_setClipRect(elemClipRect);
  432. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 1, RectI(x, offset.y, width, btnHeight)));
  433. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 2, RectI(x, offset.y + btnHeight, width, ELEMENT_EXTRA_SPACING)));
  434. yOffset = btnHeight + ELEMENT_EXTRA_SPACING;
  435. }
  436. if(current->mFoldoutBtn != nullptr)
  437. {
  438. Vector2I elementSize = current->mFoldoutBtn->_getOptimalSize();
  439. offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.y);
  440. Vector2I myOffset = offset;
  441. if(elementSize.y > btnHeight)
  442. {
  443. UINT32 diff = elementSize.y - btnHeight;
  444. float half = diff * 0.5f;
  445. myOffset.y -= Math::floorToInt(half);
  446. }
  447. current->mFoldoutBtn->_setOffset(myOffset);
  448. current->mFoldoutBtn->_setWidth(elementSize.x);
  449. current->mFoldoutBtn->_setHeight(elementSize.y);
  450. current->mFoldoutBtn->_setAreaDepth(areaDepth);
  451. current->mFoldoutBtn->_setWidgetDepth(widgetDepth);
  452. RectI elemClipRect(clipRect.x - myOffset.x, clipRect.y - myOffset.y, clipRect.width, clipRect.height);
  453. current->mFoldoutBtn->_setClipRect(elemClipRect);
  454. }
  455. offset.y += yOffset;
  456. tempOrderedElements.resize(current->mChildren.size(), nullptr);
  457. for(auto& child : current->mChildren)
  458. {
  459. tempOrderedElements[child->mSortedIdx] = child;
  460. }
  461. for(auto iter = tempOrderedElements.rbegin(); iter != tempOrderedElements.rend(); ++iter)
  462. {
  463. TreeElement* child = *iter;
  464. if(!child->mIsVisible)
  465. continue;
  466. todo.push(UpdateTreeElement(child, indent + 1));
  467. }
  468. }
  469. if(mSelectedElement != nullptr)
  470. {
  471. GUILabel* targetElement = mSelectedElement->mElement;
  472. Vector2I offset = targetElement->_getOffset();
  473. offset.x = x;
  474. mSelectionBackground->_setOffset(offset);
  475. mSelectionBackground->_setWidth(width);
  476. mSelectionBackground->_setHeight(targetElement->_getHeight());
  477. mSelectionBackground->_setAreaDepth(areaDepth + 1);
  478. mSelectionBackground->_setWidgetDepth(widgetDepth);
  479. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  480. mSelectionBackground->_setClipRect(elemClipRect);
  481. }
  482. if(mEditElement != nullptr)
  483. {
  484. GUILabel* targetElement = mEditElement->mElement;
  485. Vector2I offset = targetElement->_getOffset();
  486. UINT32 remainingWidth = (UINT32)std::max(0, (((INT32)width) - (offset.x - x)));
  487. mNameEditBox->_setOffset(offset);
  488. mNameEditBox->_setWidth(remainingWidth);
  489. mNameEditBox->_setHeight(targetElement->_getHeight());
  490. mNameEditBox->_setAreaDepth(areaDepth);
  491. mNameEditBox->_setWidgetDepth(widgetDepth);
  492. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  493. mNameEditBox->_setClipRect(elemClipRect);
  494. }
  495. }
  496. const GUISceneTreeView::InteractableElement* GUISceneTreeView::findElementUnderCoord(const CM::Vector2I& coord) const
  497. {
  498. for(auto& element : mVisibleElements)
  499. {
  500. if(element.bounds.contains(coord))
  501. {
  502. return &element;
  503. }
  504. }
  505. return nullptr;
  506. }
  507. GUISceneTreeView::TreeElement* GUISceneTreeView::interactableToRealElement(const GUISceneTreeView::InteractableElement& element)
  508. {
  509. if(!element.isTreeElement())
  510. return nullptr;
  511. UINT32 sortedIdx = (element.index - 1) / 2;
  512. auto findIter = std::find_if(element.parent->mChildren.begin(), element.parent->mChildren.end(),
  513. [&](const TreeElement* x) { return x->mSortedIdx == sortedIdx; });
  514. if(findIter != element.parent->mChildren.end())
  515. return *findIter;
  516. return nullptr;
  517. }
  518. const String& GUISceneTreeView::getGUITypeName()
  519. {
  520. static String typeName = "SceneTreeView";
  521. return typeName;
  522. }
  523. }