guiTreeViewCtrl.h 3.9 KB

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