guiPanelCtrl.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include "gui/containers/guiPanelCtrl.h"
  23. #include "graphics/dgl.h"
  24. #include "guiPanelCtrl_ScriptBinding.h"
  25. #include "gui/guiDefaultControlRender.h"
  26. IMPLEMENT_CONOBJECT(GuiPanelCtrl);
  27. GuiPanelCtrl::GuiPanelCtrl()
  28. {
  29. mActive = true;
  30. mHeader = NULL;
  31. }
  32. GuiPanelCtrl::~GuiPanelCtrl()
  33. {
  34. }
  35. void GuiPanelCtrl::initPersistFields()
  36. {
  37. Parent::initPersistFields();
  38. }
  39. bool GuiPanelCtrl::onAdd()
  40. {
  41. if (!Parent::onAdd())
  42. return false;
  43. if (!mHeader)
  44. {
  45. mHeader = new GuiButtonCtrl();
  46. AssertFatal(mHeader, "GuiPaneCtrl::onAdd() Cannot create a GuiButtonCtrl for the header.");
  47. if (mHeader)
  48. {
  49. mHeader->setField("horizSizing", "width");
  50. mHeader->setField("vertSizing", "bottom");
  51. mHeader->setField("extent", "64 64");
  52. mHeader->setField("minExtent", "16 16");
  53. mHeader->setField("position", "0 0");
  54. mHeader->registerObject();
  55. addObject(mHeader);
  56. mHeader->setConsoleCommand(avar("%d.setExpanded(!%d.getExpanded());", getId(), getId()));
  57. }
  58. }
  59. return true;
  60. }
  61. void GuiPanelCtrl::onRender(Point2I offset, const RectI &updateRect)
  62. {
  63. if (mText != mHeader->getText())
  64. {
  65. mHeader->setText(mText);
  66. }
  67. if (mCollapsedExtent != mHeader->mBounds.extent)
  68. {
  69. mHeader->mBounds.extent.set(mCollapsedExtent.x, mCollapsedExtent.y);
  70. }
  71. if (mHeader->mProfile != mProfile)
  72. {
  73. mHeader->setControlProfile(mProfile);
  74. }
  75. //Render the childen
  76. RectI contentRect = RectI(offset, mBounds.extent);
  77. renderChildControls(offset, contentRect, updateRect);
  78. }
  79. void GuiPanelCtrl::setControlProfile(GuiControlProfile *prof)
  80. {
  81. Parent::setControlProfile(prof);
  82. if(mHeader)
  83. mHeader->setControlProfile(prof);
  84. }
  85. bool GuiPanelCtrl::calcExpandedExtent()
  86. {
  87. if (!size())
  88. return false;
  89. mExpandedExtent = Point2I(0, 0);
  90. for (iterator itr = begin(); itr != end(); ++itr)
  91. {
  92. GuiControl* child = dynamic_cast<GuiControl*>(*itr);
  93. mExpandedExtent.setMax(child->getExtent() + child->getPosition());
  94. }
  95. mExpandedExtent.set(getMax(mCollapsedExtent.x, mExpandedExtent.x), getMax(mCollapsedExtent.y, mExpandedExtent.y));
  96. return true;
  97. }