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