guiTreeViewCtrl.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef _GUI_TREEVIEWCTRL_H
  23. #define _GUI_TREEVIEWCTRL_H
  24. #include "gui/guiListBoxCtrl.h"
  25. #include <vector>
  26. //------------------------------------------------------------------------------
  27. class GuiTreeViewCtrl : public GuiListBoxCtrl
  28. {
  29. private:
  30. typedef GuiListBoxCtrl Parent;
  31. enum class ReorderMethod { Above, Below, Insert };
  32. S32 mFocusLevel;
  33. protected:
  34. SimObjectPtr<SimObject> mRootObject;
  35. S32 mIndentSize;
  36. Point2I mTouchPoint;
  37. bool mDragActive;
  38. S32 mDragIndex;
  39. bool mIsDragLegal;
  40. ReorderMethod mReorderMethod;
  41. bool mIsBoundToGuiEditor;
  42. const GuiControl* mFocusControl;
  43. public:
  44. GuiTreeViewCtrl();
  45. virtual ~GuiTreeViewCtrl();
  46. static void initPersistFields();
  47. class TreeItem : public GuiListBoxCtrl::LBItem
  48. {
  49. public:
  50. TreeItem() : isOpen(1), level(0), triangleArea(RectI()), isVisible(1), branchList(vector<TreeItem*>()), trunk(nullptr) { }
  51. virtual ~TreeItem() { }
  52. bool isOpen;
  53. U16 level;
  54. RectI triangleArea;
  55. bool isVisible;
  56. vector<TreeItem*> branchList;
  57. TreeItem* trunk;
  58. };
  59. private:
  60. TreeItem* grabItemPtr(S32 index);
  61. public:
  62. // GuiControl
  63. //bool onWake();
  64. //void onSleep();
  65. //void onPreRender();
  66. //bool onKeyDown(const GuiEvent& event);
  67. void onTouchDown(const GuiEvent& event);
  68. //void onMiddleMouseDown(const GuiEvent& event);
  69. //void onTouchMove(const GuiEvent& event);
  70. //void onTouchEnter(const GuiEvent& event);
  71. //void onTouchLeave(const GuiEvent& event);
  72. //void onRightMouseDown(const GuiEvent& event);
  73. void onTouchDragged(const GuiEvent& event);
  74. void onTouchUp(const GuiEvent& event);
  75. //bool onAdd();
  76. void onPreRender();
  77. void onRender(Point2I offset, const RectI& updateRect);
  78. //void setControlProfile(GuiControlProfile* prof);
  79. //void resize(const Point2I& newPosition, const Point2I& newExtent);
  80. virtual void onRenderItem(RectI& itemRect, LBItem* item);
  81. virtual void onRenderDragLine(RectI& itemRect);
  82. S32 getHitIndex(const GuiEvent& event);
  83. virtual void handleItemClick(LBItem* hitItem, S32 hitIndex, const GuiEvent& event);
  84. virtual void handleItemClick_ClickCallbacks(LBItem* hitItem, S32 hitIndex, const GuiEvent& event);
  85. void inspectObject(SimObject* obj);
  86. void uninspectObject();
  87. void addBranches(TreeItem* treeItem, SimObject* obj, U16 level);
  88. void refreshTree();
  89. StringTableEntry getObjectText(SimObject* obj);
  90. void calculateHeaderExtent();
  91. virtual GuiListBoxCtrl::LBItem* createItem();
  92. void setBranchesVisible(TreeItem* treeItem, bool isVisible);
  93. void setItemOpen(S32 index, bool isOpen);
  94. bool getItemOpen(S32 index);
  95. S32 getItemTrunk(S32 index);
  96. DECLARE_CONOBJECT(GuiTreeViewCtrl);
  97. };
  98. #endif