PolyUITree.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyScreenLabel.h"
  22. #include "PolyScreenImage.h"
  23. #include "PolyScreenShape.h"
  24. #include "PolyScreenEntity.h"
  25. #include "PolyUITreeEvent.h"
  26. #include "PolyUIBox.h"
  27. #include "PolyTween.h"
  28. #include <vector>
  29. using std::vector;
  30. namespace Polycode {
  31. class _PolyExport UITree : public ScreenEntity {
  32. public:
  33. UITree(String icon, String text, Number treeWidth, Number treeOffset=0);
  34. ~UITree();
  35. void handleEvent(Event *event);
  36. void toggleCollapsed();
  37. UITree *addTreeChild(String icon, String text, void *userData = NULL);
  38. void Update();
  39. void refreshTree();
  40. Number getTreeHeight();
  41. void setParent(UITree *parent);
  42. void clearSelection(UITree *selectedNode);
  43. bool isCollapsed();
  44. void *getUserData();
  45. void setUserData(void *data);
  46. UITree *getSelectedNode();
  47. void setIcon(String iconFile);
  48. void setSelected(bool byKey=false);
  49. void setLabelText(const String &text);
  50. void Resize(Number width);
  51. int getNumTreeChildren() { return treeChildren.size(); }
  52. UITree *getTreeChild(int index) { return treeChildren[index]; }
  53. void removeTreeChild(UITree *child);
  54. void clearTree();
  55. String getLabelText();
  56. Number handleRotation;
  57. UITree *getParent();
  58. bool hasTreeChildren() { return (getNumTreeChildren()); }
  59. UITree *getPrevSibling();
  60. UITree *getNextSibling();
  61. Number getCellHeight() { return cellHeight; }
  62. bool isSelectedByKey() { return selectedByKey; }
  63. private:
  64. bool willDrag;
  65. bool isDragging;
  66. String labelText;
  67. void *userData;
  68. Number treeWidth;
  69. Number treeOffset;
  70. UITree *selectedNode;
  71. UITree *parent;
  72. Number padding;
  73. UIBox *selection;
  74. // UIBox *bgBox;
  75. ScreenShape *bgBox;
  76. ScreenLabel *textLabel;
  77. ScreenImage *iconImage;
  78. bool selected;
  79. Number treeHeight;
  80. vector<UITree*> treeChildren;
  81. bool collapsed;
  82. ScreenImage *arrowIconImage;
  83. String arrowIcon;
  84. Vector2 mouseDownPosition;
  85. String fontName;
  86. int size;
  87. Number cellHeight;
  88. Number cellPadding;
  89. bool selectedByKey;
  90. };
  91. }