guiTreeViewCtrl.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gui/guiTreeViewCtrl.h"
  23. #include "graphics/dgl.h"
  24. #include "gui/guiDefaultControlRender.h"
  25. #include "gui/guiCanvas.h"
  26. #include "gui/editor/guiEditCtrl.h"
  27. #include "guiTreeViewCtrl_ScriptBinding.h"
  28. IMPLEMENT_CONOBJECT(GuiTreeViewCtrl);
  29. GuiTreeViewCtrl::GuiTreeViewCtrl()
  30. {
  31. mActive = true;
  32. mIsContainer = false;
  33. mIndentSize = 10;
  34. mMultipleSelections = true;
  35. mTouchPoint = Point2I::Zero;
  36. mDragActive = false;
  37. mDragIndex = 0;
  38. mIsDragLegal = false;
  39. mIsBoundToGuiEditor = false;
  40. mFocusControl = nullptr;
  41. }
  42. GuiTreeViewCtrl::~GuiTreeViewCtrl()
  43. {
  44. }
  45. GuiTreeViewCtrl::TreeItem* GuiTreeViewCtrl::grabItemPtr(S32 index)
  46. {
  47. // Range Check
  48. if (index >= mItems.size() || index < 0)
  49. {
  50. Con::warnf("GuiTreeViewCtrl::grabItemPtr - index out of range!");
  51. return nullptr;
  52. }
  53. // Grab our item
  54. TreeItem* treeItem = dynamic_cast<GuiTreeViewCtrl::TreeItem*>(mItems[index]);
  55. return treeItem;
  56. }
  57. void GuiTreeViewCtrl::initPersistFields()
  58. {
  59. Parent::initPersistFields();
  60. addField("BindToGuiEditor", TypeBool, Offset(mIsBoundToGuiEditor, GuiTreeViewCtrl));
  61. }
  62. void GuiTreeViewCtrl::onTouchDown(const GuiEvent& event)
  63. {
  64. mTouchPoint == event.mousePoint;
  65. S32 hitIndex = getHitIndex(event);
  66. if (mIsBoundToGuiEditor && smDesignTime && hitIndex == 0)
  67. {
  68. if (!(event.modifier & SI_CTRL) && !(event.modifier & SI_SHIFT))
  69. {
  70. clearSelection();
  71. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  72. if (edit)
  73. {
  74. GuiControl* root = static_cast<GuiControl*>(mItems[0]->itemData);
  75. edit->setCurrentAddSet(root, true);
  76. }
  77. }
  78. }
  79. else
  80. {
  81. Parent::onTouchDown(event);
  82. }
  83. }
  84. void GuiTreeViewCtrl::onTouchDragged(const GuiEvent& event)
  85. {
  86. mDragActive = false;
  87. if (!mActive || !mVisible)
  88. return;
  89. S32 hitIndex = getHitIndex(event);
  90. if (hitIndex >= mItems.size() || hitIndex == -1)
  91. return;
  92. LBItem* hitItem = mItems[hitIndex];
  93. if (hitItem == NULL || !hitItem->isActive)
  94. return;
  95. if (mAbs(mTouchPoint.x - event.mousePoint.x) > 2 || mAbs(mTouchPoint.y - event.mousePoint.y) > 2)
  96. {
  97. mDragActive = true;
  98. }
  99. }
  100. void GuiTreeViewCtrl::onTouchUp(const GuiEvent& event)
  101. {
  102. if (mDragActive && mIsDragLegal)
  103. {
  104. TreeItem* dragItem = grabItemPtr(mDragIndex);
  105. if (mReorderMethod == ReorderMethod::Below && dragItem->isOpen)
  106. {
  107. mReorderMethod = ReorderMethod::Insert;
  108. }
  109. SimGroup* target = static_cast<SimGroup*>(mReorderMethod == ReorderMethod::Insert ? dragItem->itemData : dragItem->trunk->itemData);
  110. if (!target)
  111. {
  112. Con::warnf("GuiTreeViewCtrl::onTouchUp - attempted to drag selection into an object that is not a SimGroup");
  113. return;
  114. }
  115. vector<SimObject*> objectAboveTargetList = vector<SimObject*>();
  116. if (mReorderMethod != ReorderMethod::Insert)
  117. {
  118. S32 index = mReorderMethod == ReorderMethod::Below ? mDragIndex : mDragIndex - 1;
  119. TreeItem* checkItem = grabItemPtr(index);
  120. while (checkItem->level == dragItem->level)
  121. {
  122. if(!checkItem->isSelected)
  123. {
  124. SimObject* obj = static_cast<SimObject*>(checkItem->itemData);
  125. objectAboveTargetList.push_back(obj);
  126. }
  127. index = index - 1;
  128. checkItem = grabItemPtr(index);
  129. }
  130. }
  131. else
  132. {
  133. dragItem->isOpen = true;
  134. }
  135. for (S32 i = mItems.size() - 1; i >= 0; i--)
  136. {
  137. TreeItem* treeItem = dynamic_cast<TreeItem*>(mItems[i]);
  138. if(treeItem && treeItem->isSelected)
  139. {
  140. SimObject* obj = static_cast<SimObject*>(treeItem->itemData);
  141. if(obj)
  142. {
  143. target->addObject(obj);
  144. target->bringObjectToFront(obj);
  145. }
  146. }
  147. }
  148. for (auto obj : objectAboveTargetList)
  149. {
  150. SimGroup* group = obj->getGroup();
  151. group->bringObjectToFront(obj);
  152. }
  153. GuiControl* control = static_cast<GuiControl*>(mReorderMethod != ReorderMethod::Insert ? dragItem->trunk->itemData : dragItem->itemData);
  154. if (control)
  155. {
  156. control->childrenReordered();
  157. }
  158. refreshTree();
  159. }
  160. mDragActive = false;
  161. Parent::onTouchUp(event);
  162. }
  163. void GuiTreeViewCtrl::onPreRender()
  164. {
  165. if (mIsBoundToGuiEditor && smDesignTime && smEditorHandle)
  166. {
  167. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  168. if (edit)
  169. {
  170. const GuiControl* oldFocus = mFocusControl;
  171. mFocusControl = edit->getCurrentAddSet();
  172. if(oldFocus != mFocusControl)
  173. {
  174. for (S32 i = 0; i < mItems.size(); i++)
  175. {
  176. LBItem* item = mItems[i];
  177. TreeItem* treeItem = dynamic_cast<TreeItem*>(item);
  178. SimObject* obj = static_cast<SimObject*>(item->itemData);
  179. if (obj && obj->getId() == mFocusControl->getId())
  180. {
  181. treeItem->isSelected = false;
  182. if(!treeItem->isOpen)
  183. {
  184. treeItem->isOpen = true;
  185. refreshTree();
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. void GuiTreeViewCtrl::onRender(Point2I offset, const RectI& updateRect)
  194. {
  195. mFocusLevel = -1;
  196. RectI clip = dglGetClipRect();
  197. if (mFitParentWidth && (mBounds.extent.x != clip.extent.x || mItemSize.x != clip.extent.x))
  198. {
  199. mBounds.extent.x = clip.extent.x;
  200. mItemSize.x = clip.extent.x;
  201. }
  202. RectI dragRect;
  203. for (S32 i = 0, j = 0; i < mItems.size(); i++)
  204. {
  205. // Only render visible items
  206. if ((j + 1) * mItemSize.y + offset.y < updateRect.point.y)
  207. continue;
  208. // Break out once we're no longer in visible item range
  209. if (j * mItemSize.y + offset.y >= updateRect.point.y + updateRect.extent.y)
  210. break;
  211. RectI itemRect = RectI(offset.x, offset.y + (j * mItemSize.y), mItemSize.x, mItemSize.y);
  212. TreeItem* treeItem = dynamic_cast<TreeItem*>(mItems[i]);
  213. if(!treeItem || treeItem->isVisible)
  214. {
  215. if (mFocusLevel >= 0 && mFocusLevel >= treeItem->level)
  216. {
  217. mFocusLevel = -1;
  218. }
  219. // Render our item
  220. onRenderItem(itemRect, mItems[i]);
  221. if (mItems[i]->ID == mFocusControl->getId())
  222. {
  223. mFocusLevel = treeItem->level;
  224. }
  225. if (mDragActive && j == mDragIndex)
  226. {
  227. dragRect = RectI(itemRect);
  228. }
  229. j++;
  230. }
  231. }
  232. if(mDragActive && mIsDragLegal)
  233. {
  234. onRenderDragLine(dragRect);
  235. }
  236. }
  237. void GuiTreeViewCtrl::onRenderItem(RectI& itemRect, LBItem* item)
  238. {
  239. TreeItem* treeItem = dynamic_cast<TreeItem*>(item);
  240. SimObject* obj = static_cast<SimObject*>(item->itemData);
  241. if (!treeItem)
  242. {
  243. Parent::onRenderItem(itemRect, item);
  244. return;
  245. }
  246. Point2I cursorPt = Point2I(0, 0);
  247. GuiCanvas* root = getRoot();
  248. if (root)
  249. {
  250. cursorPt = root->getCursorPos();
  251. }
  252. bool isFocus = obj == mFocusControl;
  253. GuiControlState currentState = GuiControlState::NormalState;
  254. if (!mActive || !item->isActive)
  255. currentState = GuiControlState::DisabledState;
  256. else if (item->isSelected)
  257. currentState = GuiControlState::SelectedState;
  258. else if (itemRect.pointInRect(cursorPt))
  259. currentState = GuiControlState::HighlightState;
  260. RectI ctrlRect = applyMargins(itemRect.point, itemRect.extent, currentState, mProfile);
  261. if (!ctrlRect.isValidRect())
  262. {
  263. return;
  264. }
  265. renderUniversalRect(ctrlRect, mProfile, currentState);
  266. //Render Text
  267. dglSetBitmapModulation(getFontColor(mProfile, currentState));
  268. RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
  269. RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
  270. //indent to the focus level
  271. if(mFocusLevel >= 0)
  272. {
  273. contentRect.point.x += (mFocusLevel * contentRect.extent.y);
  274. contentRect.extent.x -= (mFocusLevel * contentRect.extent.y);
  275. //convert this space to a line by crushing down the sides
  276. S32 crush = mRound((contentRect.extent.y - 2) / 2);
  277. RectI line = RectI(contentRect.point.x + crush, contentRect.point.y, 2, contentRect.extent.y);
  278. ColorI lineColor = currentState == SelectedState ? mProfile->getFillColor(NormalState) : mProfile->getFillColor(SelectedState);
  279. dglDrawRectFill(line, lineColor);
  280. //Remove indent
  281. contentRect.point.x -= (mFocusLevel * contentRect.extent.y);
  282. contentRect.extent.x += (mFocusLevel * contentRect.extent.y);
  283. }
  284. // Indent by level
  285. contentRect.point.x += (treeItem->level * contentRect.extent.y);
  286. contentRect.extent.x -= (treeItem->level * contentRect.extent.y);
  287. // Render open/close triangle
  288. if(obj)
  289. {
  290. SimGroup* setObj = dynamic_cast<SimGroup*>(obj);
  291. GuiControl* guiCtrl = dynamic_cast<GuiControl*>(obj);
  292. bool showTriangle = (guiCtrl && guiCtrl->mIsContainer) || (!guiCtrl && setObj && setObj->size() > 0);
  293. if (showTriangle)
  294. {
  295. RectI drawArea = RectI(contentRect.point.x, contentRect.point.y, contentRect.extent.y, contentRect.extent.y);
  296. treeItem->triangleArea.set(drawArea.point, drawArea.extent);
  297. ColorI color = mProfile->getFontColor(currentState);
  298. if (isFocus)
  299. {
  300. color = mProfile->getFillColor(SelectedState);
  301. }
  302. renderTriangleIcon(drawArea, color, treeItem->isOpen ? GuiDirection::Down : GuiDirection::Right, 8);
  303. }
  304. }
  305. contentRect.point.x += contentRect.extent.y;
  306. contentRect.extent.x -= contentRect.extent.y;
  307. renderText(contentRect.point, contentRect.extent, item->itemText, mProfile);
  308. }
  309. void GuiTreeViewCtrl::onRenderDragLine(RectI& itemRect)
  310. {
  311. ColorI colorW = ColorI(255,255,255,150);
  312. ColorI colorB = ColorI(0, 0, 0, 150);
  313. RectI rect = RectI(itemRect);
  314. rect.inset(4, 2);
  315. if (mReorderMethod == ReorderMethod::Insert)
  316. {
  317. dglDrawRect(itemRect, colorW);
  318. itemRect.inset(-1, -1);
  319. dglDrawRect(itemRect, colorB);
  320. }
  321. else if (mReorderMethod == ReorderMethod::Above)
  322. {
  323. itemRect.extent.y = 4;
  324. dglDrawRect(itemRect, colorW);
  325. itemRect.inset(-1, -1);
  326. dglDrawRect(itemRect, colorB);
  327. }
  328. else if(mReorderMethod == ReorderMethod::Below)
  329. {
  330. itemRect.point.y += mItemSize.y;
  331. itemRect.extent.y = 4;
  332. dglDrawRect(itemRect, colorW);
  333. itemRect.inset(-1, -1);
  334. dglDrawRect(itemRect, colorB);
  335. }
  336. }
  337. S32 GuiTreeViewCtrl::getHitIndex(const GuiEvent& event)
  338. {
  339. Point2I localPoint = globalToLocalCoord(event.mousePoint);
  340. if (localPoint.y < 0)
  341. {
  342. return -1;
  343. }
  344. S32 slot = (S32)mFloor((F32)localPoint.y / (F32)mItemSize.y);
  345. for (S32 i = 0, j = 0; i < mItems.size(); i++)
  346. {
  347. TreeItem* treeItem = dynamic_cast<TreeItem*>(mItems[i]);
  348. if (treeItem && treeItem->isVisible)
  349. {
  350. if (j == slot)
  351. {
  352. S32 roundSlot = (S32)mRound((F32)localPoint.y / (F32)mItemSize.y);
  353. mReorderMethod = roundSlot == slot ? ReorderMethod::Above : ReorderMethod::Below;
  354. SimObject* obj = static_cast<SimObject*>(treeItem->itemData);
  355. bool showTriangle = false;
  356. if(obj)
  357. {
  358. SimGroup* setObj = dynamic_cast<SimGroup*>(obj);
  359. GuiControl* guiCtrl = dynamic_cast<GuiControl*>(obj);
  360. showTriangle = (guiCtrl && guiCtrl->mIsContainer) || (!guiCtrl && setObj && setObj->size() > 0);
  361. if (((slot * mItemSize.y) + 5) < localPoint.y && mReorderMethod == ReorderMethod::Above && showTriangle)
  362. {
  363. mReorderMethod = ReorderMethod::Insert;
  364. }
  365. }
  366. if (j == 0)
  367. {
  368. mReorderMethod = ReorderMethod::Insert;
  369. }
  370. mIsDragLegal = true;
  371. for(TreeItem* trunk = treeItem; trunk != nullptr; trunk = trunk->trunk)
  372. {
  373. if (trunk->isSelected)
  374. {
  375. mIsDragLegal = false;
  376. break;
  377. }
  378. }
  379. mDragIndex = j;
  380. return i;
  381. }
  382. j++;
  383. }
  384. }
  385. return -1;
  386. }
  387. void GuiTreeViewCtrl::handleItemClick(LBItem* hitItem, S32 hitIndex, const GuiEvent& event)
  388. {
  389. TreeItem* treeItem = dynamic_cast<TreeItem*>(hitItem);
  390. if (treeItem)
  391. {
  392. if (treeItem->triangleArea.pointInRect(event.mousePoint))
  393. {
  394. treeItem->isOpen = !treeItem->isOpen;
  395. setBranchesVisible(treeItem, treeItem->isOpen);
  396. return;
  397. }
  398. }
  399. Parent::handleItemClick(hitItem, hitIndex, event);
  400. }
  401. void GuiTreeViewCtrl::handleItemClick_ClickCallbacks(LBItem* hitItem, S32 hitIndex, const GuiEvent& event)
  402. {
  403. TreeItem* treeItem = dynamic_cast<TreeItem*>(hitItem);
  404. if (!treeItem)
  405. {
  406. Parent::handleItemClick_ClickCallbacks(hitItem, hitIndex, event);
  407. return;
  408. }
  409. SimObject* obj = static_cast<SimObject*>(treeItem->itemData);
  410. if (hitItem == mLastClickItem && event.mouseClickCount == 2)
  411. {
  412. if (caller->isMethod("onDoubleClick"))
  413. Con::executef(caller, 2, "onDoubleClick", Con::getIntArg(obj->getId()));
  414. }
  415. else if (caller->isMethod("onClick"))
  416. {
  417. Con::executef(caller, 2, "onClick", Con::getIntArg(obj->getId()));
  418. }
  419. }
  420. void GuiTreeViewCtrl::inspectObject(SimObject* obj)
  421. {
  422. clearItems();
  423. mRootObject = obj;
  424. StringTableEntry text = getObjectText(obj);
  425. S32 id = addItemWithID(text, obj->getId(), obj);
  426. TreeItem* treeItem = grabItemPtr(id);
  427. treeItem->level = 0;
  428. addBranches(treeItem, obj, 1);
  429. }
  430. void GuiTreeViewCtrl::uninspectObject()
  431. {
  432. clearItems();
  433. mRootObject = NULL;
  434. }
  435. void GuiTreeViewCtrl::addBranches(TreeItem* treeItem, SimObject* obj, U16 level)
  436. {
  437. SimGroup* setObj = dynamic_cast<SimGroup*>(obj);
  438. if(setObj)
  439. {
  440. for(auto sub : *setObj)
  441. {
  442. StringTableEntry text = getObjectText(sub);
  443. S32 index = addItemWithID(text, sub->getId(), sub);
  444. TreeItem* branch = grabItemPtr(index);
  445. branch->level = level;
  446. branch->trunk = treeItem;
  447. treeItem->branchList.push_back(branch);
  448. addBranches(branch, sub, level + 1);
  449. }
  450. }
  451. }
  452. GuiListBoxCtrl::LBItem* GuiTreeViewCtrl::createItem()
  453. {
  454. LBItem* newItem = new TreeItem;
  455. if (!newItem)
  456. {
  457. return nullptr;
  458. }
  459. return newItem;
  460. }
  461. void GuiTreeViewCtrl::refreshTree()
  462. {
  463. if (mRootObject)
  464. {
  465. Vector<U32> selectedList;
  466. Vector<U32> openList;
  467. for (auto item : mItems)
  468. {
  469. TreeItem* treeItem = dynamic_cast<TreeItem*>(item);
  470. if (item->isSelected)
  471. {
  472. selectedList.push_back(treeItem->ID);
  473. }
  474. if (treeItem && treeItem->isOpen)
  475. {
  476. openList.push_back(treeItem->ID);
  477. }
  478. }
  479. Point2I pos = Point2I::Zero;
  480. auto scroller = dynamic_cast<GuiScrollCtrl*>(getParent());
  481. if (scroller)
  482. {
  483. pos = scroller->mScrollOffset;
  484. }
  485. inspectObject(mRootObject);
  486. for (auto item : mItems)
  487. {
  488. TreeItem* treeItem = dynamic_cast<TreeItem*>(item);
  489. if (selectedList.contains(treeItem->ID))
  490. {
  491. item->isSelected = true;
  492. mSelectedItems.push_front(item);
  493. }
  494. if (treeItem && openList.contains(treeItem->ID))
  495. {
  496. treeItem->isOpen = true;
  497. }
  498. else if(treeItem)
  499. {
  500. treeItem->isOpen = false;
  501. setBranchesVisible(treeItem, treeItem->isOpen);
  502. }
  503. }
  504. if (scroller)
  505. {
  506. scroller->scrollTo(pos.x, pos.y);
  507. }
  508. }
  509. }
  510. StringTableEntry GuiTreeViewCtrl::getObjectText(SimObject* obj)
  511. {
  512. char buffer[1024];
  513. if (obj)
  514. {
  515. if (isMethod("onGetObjectText"))
  516. {
  517. const char* text = Con::executef(this, 2, "onGetObjectText", Con::getIntArg(obj->getId()));
  518. StringTableEntry name = StringTable->insert(text, true);
  519. if (name != StringTable->EmptyString)
  520. {
  521. return name;
  522. }
  523. }
  524. const char* pObjName = obj->getName();
  525. const char* pInternalName = obj->getInternalName();
  526. GuiControl* ctrl = dynamic_cast<GuiControl*>(obj);
  527. const char* theText = ctrl ? ctrl->getText() : "";
  528. StringTableEntry textEntry = StringTable->insert(theText, true);
  529. if(textEntry == StringTable->EmptyString)
  530. {
  531. if (pObjName != NULL)
  532. dSprintf(buffer, sizeof(buffer), "%d: %s - %s", obj->getId(), obj->getClassName(), pObjName);
  533. else if (pInternalName != NULL)
  534. dSprintf(buffer, sizeof(buffer), "%d: %s [%s]", obj->getId(), obj->getClassName(), pInternalName);
  535. else
  536. dSprintf(buffer, sizeof(buffer), "%d: %s", obj->getId(), obj->getClassName());
  537. }
  538. else
  539. {
  540. if (pObjName != NULL)
  541. dSprintf(buffer, sizeof(buffer), "%d: %s \"%s\" - %s", obj->getId(), obj->getClassName(), textEntry, pObjName);
  542. else if (pInternalName != NULL)
  543. dSprintf(buffer, sizeof(buffer), "%d: %s \"%s\" [%s]", obj->getId(), obj->getClassName(), textEntry, pInternalName);
  544. else
  545. dSprintf(buffer, sizeof(buffer), "%d: %s \"%s\"", obj->getId(), obj->getClassName(), textEntry);
  546. }
  547. }
  548. return StringTable->insert(buffer, true);
  549. }
  550. void GuiTreeViewCtrl::calculateHeaderExtent()
  551. {
  552. if(mProfile)
  553. {
  554. GuiBorderProfile* topProfile = mProfile->getTopBorder();
  555. GuiBorderProfile* bottomProfile = mProfile->getBottomBorder();
  556. S32 topSize = (topProfile) ? topProfile->getMargin(NormalState) + topProfile->getBorder(NormalState) + topProfile->getPadding(NormalState) : 0;
  557. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(NormalState) + bottomProfile->getBorder(NormalState) + bottomProfile->getPadding(NormalState) : 0;
  558. GFont* font = mProfile->getFont();
  559. S32 fontSize = (font) ? font->getHeight() : 0;
  560. S32 height = topSize + bottomSize + fontSize;
  561. S32 width = mBounds.extent.x;
  562. }
  563. }
  564. void GuiTreeViewCtrl::setBranchesVisible(TreeItem* treeItem, bool isVisible)
  565. {
  566. for (auto branch : treeItem->branchList)
  567. {
  568. if(!isVisible || branch->isOpen)
  569. {
  570. setBranchesVisible(branch, isVisible);
  571. }
  572. branch->isVisible = isVisible;
  573. }
  574. }
  575. void GuiTreeViewCtrl::setItemOpen(S32 index, bool isOpen)
  576. {
  577. if ((index >= mItems.size()) || index < 0)
  578. {
  579. Con::warnf("GuiTreeViewCtrl::setItemOpen - invalid index");
  580. return;
  581. }
  582. TreeItem* item = dynamic_cast<TreeItem*>(mItems[index]);
  583. item->isOpen = isOpen;
  584. }
  585. bool GuiTreeViewCtrl::getItemOpen(S32 index)
  586. {
  587. if ((index >= mItems.size()) || index < 0)
  588. {
  589. Con::warnf("GuiTreeViewCtrl::getItemOpen - invalid index");
  590. return true;
  591. }
  592. TreeItem* item = dynamic_cast<TreeItem*>(mItems[index]);
  593. return item->isOpen;
  594. }
  595. S32 GuiTreeViewCtrl::getItemTrunk(S32 index)
  596. {
  597. if ((index >= mItems.size()) || index < 0)
  598. {
  599. Con::warnf(" GuiTreeViewCtrl::getItemTrunk - invalid index");
  600. return -1;
  601. }
  602. TreeItem* item = dynamic_cast<TreeItem*>(mItems[index]);
  603. return item->level == 0 ? -1 : getItemIndex(item->trunk);
  604. }