BsGUILayoutExplicit.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "BsGUILayoutExplicit.h"
  2. #include "BsGUIElement.h"
  3. #include "BsGUISpace.h"
  4. #include "BsMath.h"
  5. #include "BsVector2I.h"
  6. namespace BansheeEngine
  7. {
  8. GUILayoutExplicit::GUILayoutExplicit(GUIArea* parentArea)
  9. :GUILayout(parentArea)
  10. { }
  11. LayoutSizeRange GUILayoutExplicit::_calculateLayoutSizeRange() const
  12. {
  13. return LayoutSizeRange();
  14. }
  15. void GUILayoutExplicit::_updateOptimalLayoutSizes()
  16. {
  17. }
  18. void GUILayoutExplicit::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const
  19. {
  20. assert(mChildren.size() == numElements);
  21. // Compute offsets and height
  22. UINT32 childIdx = 0;
  23. for (auto& child : mChildren)
  24. {
  25. if (child->_getType() == GUIElementBase::Type::Element)
  26. {
  27. GUIElement* element = static_cast<GUIElement*>(child);
  28. elementAreas[childIdx].x = element->_getOffset().x;
  29. elementAreas[childIdx].y = element->_getOffset().y;
  30. elementAreas[childIdx].width = element->_getWidth();
  31. elementAreas[childIdx].height = element->_getHeight();
  32. }
  33. else if (child->_getType() == GUIElementBase::Type::Layout)
  34. {
  35. GUILayout* layout = static_cast<GUILayout*>(child);
  36. elementAreas[childIdx].height = height;
  37. elementAreas[childIdx].width = width;
  38. elementAreas[childIdx].x = x;
  39. elementAreas[childIdx].y = y;
  40. }
  41. childIdx++;
  42. }
  43. }
  44. void GUILayoutExplicit::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  45. {
  46. UINT32 childIdx = 0;
  47. for (auto& child : mChildren)
  48. {
  49. if (child->_getType() == GUIElementBase::Type::Element)
  50. {
  51. GUIElement* element = static_cast<GUIElement*>(child);
  52. element->_setWidgetDepth(widgetDepth);
  53. element->_setAreaDepth(areaDepth);
  54. Vector2I offset = element->_getOffset();
  55. Rect2I elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  56. element->_setClipRect(elemClipRect);
  57. Rect2I newClipRect(offset.x, offset.y, element->_getWidth(), element->_getHeight());
  58. newClipRect.clip(clipRect);
  59. element->_updateLayoutInternal(offset.x, offset.y, element->_getWidth(), element->_getHeight(), newClipRect, widgetDepth, areaDepth);
  60. }
  61. else if (child->_getType() == GUIElementBase::Type::Layout)
  62. {
  63. GUILayout* layout = static_cast<GUILayout*>(child);
  64. layout->_updateLayoutInternal(x, y, width, height, clipRect, widgetDepth, areaDepth);
  65. }
  66. childIdx++;
  67. }
  68. mActualWidth = 0; // Not relevant
  69. mActualHeight = 0;
  70. _markAsClean();
  71. }
  72. Vector2I GUILayoutExplicit::_calcActualSize(Rect2I* elementAreas, UINT32 numElements) const
  73. {
  74. return Vector2I(0, 0); // Not relevant
  75. }
  76. }