BsGUIPanelContainer.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "BsGUIPanelContainer.h"
  2. #include "BsGUIArea.h"
  3. #include "BsScriptGUIPanel.h"
  4. #include "BsGUILayout.h"
  5. #include "BsGUIWidget.h"
  6. #include "BsScriptGUIArea.h"
  7. namespace BansheeEngine
  8. {
  9. GUIPanelContainer::GUIPanelContainer(const PrivatelyConstruct& dummy, const ScriptGUIPanel& guiPanel, const GUILayoutOptions& layoutOptions)
  10. :GUIElementContainer(layoutOptions), mGUIPanel(&guiPanel)
  11. {
  12. }
  13. GUIPanelContainer::~GUIPanelContainer()
  14. {
  15. }
  16. GUIPanelContainer* GUIPanelContainer::create(const ScriptGUIPanel& guiPanel, const GUIOptions& layoutOptions)
  17. {
  18. return bs_new<GUIPanelContainer>(PrivatelyConstruct(), guiPanel, GUILayoutOptions::create(layoutOptions));
  19. }
  20. GUIPanelContainer* GUIPanelContainer::create(const ScriptGUIPanel& guiPanel)
  21. {
  22. return bs_new<GUIPanelContainer>(PrivatelyConstruct(), guiPanel, GUILayoutOptions::create());
  23. }
  24. void GUIPanelContainer::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  25. Rect2I clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  26. {
  27. const Vector<ScriptGUIArea*> areas = mGUIPanel->getAreas();
  28. for (auto& scriptArea : areas)
  29. {
  30. GUIArea* area = scriptArea->getInternalValue();
  31. if (area->x() != x || area->y() != y)
  32. area->setPosition(x, y);
  33. if (area->width() != width || area->height() != height)
  34. area->setSize(width, height);
  35. Rect2I areaClipRect(clipRect.x - x, clipRect.y - y, clipRect.width, clipRect.height);
  36. if (area->getClipRect() != areaClipRect)
  37. area->setClipRect(areaClipRect);
  38. // We want to force the layout update right away otherwise it might get delayed until next frame.
  39. // (Since we are currently in a middle of a layout update its possible this area was already processed)
  40. area->_update();
  41. }
  42. }
  43. Vector2I GUIPanelContainer::_getOptimalSize() const
  44. {
  45. const Vector<ScriptGUIArea*> areas = mGUIPanel->getAreas();
  46. Vector2I optimalSize;
  47. for (auto& scriptArea : areas)
  48. {
  49. GUIArea* area = scriptArea->getInternalValue();
  50. area->_update();
  51. optimalSize.x = std::max(optimalSize.x, area->getLayout()._getOptimalSize().x);
  52. optimalSize.y = std::max(optimalSize.y, area->getLayout()._getOptimalSize().y);
  53. }
  54. return optimalSize;
  55. }
  56. const String& GUIPanelContainer::getGUITypeName()
  57. {
  58. static String typeName = "GUIAreaContainer";
  59. return typeName;
  60. }
  61. }