CGUIAttributeEditor.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "CGUIAttributeEditor.h"
  2. #include "IGUIEnvironment.h"
  3. #include "IFileSystem.h"
  4. #include "IVideoDriver.h"
  5. #include "IAttributes.h"
  6. #include "IGUIFont.h"
  7. #include "IGUIScrollBar.h"
  8. #include "CGUIAttribute.h"
  9. #include "CGUIStringAttribute.h"
  10. namespace irr
  11. {
  12. namespace gui
  13. {
  14. using namespace core;
  15. using namespace io;
  16. CGUIAttributeEditor::CGUIAttributeEditor(IGUIEnvironment* environment, s32 id, IGUIElement *parent) :
  17. CGUIPanel(environment, parent, id, rect<s32>(0, 0, 100, 100)),
  18. Attribs(0), Panel(0)
  19. {
  20. #ifdef _DEBUG
  21. setDebugName("CGUIAttributeEditor");
  22. #endif
  23. // create attributes
  24. Attribs = environment->getFileSystem()->createEmptyAttributes(Environment->getVideoDriver());
  25. calculateClientArea();
  26. resizeInnerPane();
  27. // refresh attrib list
  28. refreshAttribs();
  29. IGUIScrollBar* sb = getVScrollBar();
  30. core::rect<s32> r = sb->getRelativePosition();
  31. r.LowerRightCorner.Y -= 16;
  32. sb->setRelativePosition(r);
  33. }
  34. CGUIAttributeEditor::~CGUIAttributeEditor()
  35. {
  36. for (u32 i=0; i<AttribList.size(); ++i)
  37. {
  38. AttribList[i]->remove();
  39. AttribList[i]->drop();
  40. }
  41. AttribList.clear();
  42. Attribs->drop();
  43. }
  44. IAttributes* CGUIAttributeEditor::getAttribs()
  45. {
  46. return Attribs;
  47. }
  48. void CGUIAttributeEditor::refreshAttribs()
  49. {
  50. // clear the attribute list
  51. u32 i;
  52. for (i=0; i<AttribList.size(); ++i)
  53. {
  54. AttribList[i]->remove();
  55. AttribList[i]->drop();
  56. }
  57. AttribList.clear();
  58. position2di top(10, 5);
  59. rect<s32> r(top.X, top.Y,
  60. getClientArea().getWidth() - 10,
  61. 5 + Environment->getSkin()->getFont()->getDimension(L"A").Height);
  62. // add attribute elements
  63. u32 c = Attribs->getAttributeCount();
  64. for (i=0; i<c; ++i)
  65. {
  66. // try to create attribute
  67. stringc str = Attribs->getAttributeTypeString(i);
  68. str += "_attribute";
  69. CGUIAttribute* n = (CGUIAttribute*)Environment->addGUIElement(str.c_str(), 0);
  70. // if this doesn't exist, use a string editor
  71. if (!n)
  72. n = (CGUIAttribute*)Environment->addGUIElement("string_attribute", 0);
  73. if (n)
  74. {
  75. AttribList.push_back(n);
  76. n->setParentID(getID());
  77. n->grab();
  78. }
  79. // We can't set "this" as parent above as we need functionality
  80. // of the overloaded addChild which isn't called in the constructor.
  81. // (that's a general Irrlicht messup with too fat constructors)
  82. addChild(n);
  83. AttribList[i]->setSubElement(true);
  84. AttribList[i]->setRelativePosition(r);
  85. AttribList[i]->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
  86. AttribList[i]->setAttrib(Attribs, i);
  87. r += position2di(0, AttribList[i]->getRelativePosition().getHeight() + 5);
  88. }
  89. }
  90. void CGUIAttributeEditor::updateAttribs()
  91. {
  92. for (u32 i=0; i<AttribList.size(); ++i)
  93. AttribList[i]->updateAttrib(false);
  94. }
  95. } // namespace gui
  96. } // namespace irr