guiTreeViewCtrl_ScriptBinding.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. ConsoleMethodGroupBeginWithDocs(GuiTreeViewCtrl, GuiListBoxCtrl)
  23. /*! Sets the root object to view.
  24. @param obj A SimGroup that will be viewed as a tree.
  25. @return No return value.
  26. */
  27. ConsoleMethodWithDocs( GuiTreeViewCtrl, inspect, ConsoleVoid, 3, 3, (SimGroup obj))
  28. {
  29. SimGroup* treeRoot = NULL;
  30. SimObject* target = Sim::findObject(argv[2]);
  31. if (target)
  32. treeRoot = dynamic_cast<SimGroup*>(target);
  33. object->inspectObject(treeRoot);
  34. }
  35. /*! Removes the root object.
  36. @return No return value.
  37. */
  38. ConsoleMethodWithDocs(GuiTreeViewCtrl, uninspect, ConsoleVoid, 2, 2, ())
  39. {
  40. object->uninspectObject();
  41. }
  42. /*! Informs the tree that the contents of the tree have changed and should be refreshed but preserves selection if possible.
  43. @return No return value.
  44. */
  45. ConsoleMethodWithDocs(GuiTreeViewCtrl, refresh, ConsoleVoid, 2, 2, ())
  46. {
  47. object->refreshTree();
  48. }
  49. /*! Sets if an item is open by the index.
  50. @param index The zero-based index of the item.
  51. @param isOpen True if the item should be open and false otherwise.
  52. @return No return value.
  53. */
  54. ConsoleMethodWithDocs(GuiTreeViewCtrl, setItemOpen, ConsoleVoid, 4, 4, "(int index, bool isOpen)")
  55. {
  56. if (argc != 4)
  57. {
  58. Con::warnf("GuiTreeViewCtrl::setItemOpen() - Invalid number of parameters! Should be (index, isOpen).");
  59. }
  60. else
  61. {
  62. object->setItemOpen(dAtoi(argv[2]), dAtob(argv[3]));
  63. }
  64. }
  65. /*! Returns if an item is open or not using an index.
  66. @param index The zero-based index of the item.
  67. @return True if the item is open and false otherwise.
  68. */
  69. ConsoleMethodWithDocs(GuiTreeViewCtrl, getItemOpen, ConsoleBool, 3, 3, "(int index)")
  70. {
  71. if (argc != 3)
  72. {
  73. Con::warnf("GuiTreeViewCtrl::getItemOpen() - Invalid number of parameters! Should be (index).");
  74. return true;
  75. }
  76. return object->getItemOpen(dAtoi(argv[2]));
  77. }
  78. /*! Returns the index of the parent of the item.
  79. @param index The zero-based index of the child item.
  80. @return The index of the parent or -1 if the parent is the root.
  81. */
  82. ConsoleMethodWithDocs(GuiTreeViewCtrl, getItemParent, ConsoleInt, 3, 3, "(int index)")
  83. {
  84. if (argc != 3)
  85. {
  86. Con::warnf("GuiTreeViewCtrl::getItemOpen() - Invalid number of parameters! Should be (index).");
  87. return -1;
  88. }
  89. return object->getItemTrunk(dAtoi(argv[2]));
  90. }
  91. /*! Refreshes the text of the item based on the inspected object.
  92. @param index The zero-based index of the item that will be updated.
  93. @return No return value.
  94. */
  95. ConsoleMethodWithDocs(GuiTreeViewCtrl, refreshItemText, ConsoleVoid, 3, 3, "(S32 index)")
  96. {
  97. S32 index = dAtoi(argv[2]);
  98. if (index < 0 || index >= object->mItems.size())
  99. {
  100. Con::warnf("GuiTreeViewCtrl::refreshItemText() - Invalid index given.");
  101. return;
  102. }
  103. SimObject* sub = static_cast<SimObject*>(object->mItems[index]->itemData);
  104. object->setItemText(index, object->getObjectText(sub));
  105. }
  106. ConsoleMethodGroupEndWithDocs(GuiTreeViewCtrl)