BsGUIArea.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "BsGUIArea.h"
  2. #include "BsGUIWidget.h"
  3. #include "BsGUILayoutX.h"
  4. #include "CmViewport.h"
  5. using namespace CamelotFramework;
  6. namespace BansheeEngine
  7. {
  8. GUIArea::GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT16 depth)
  9. :mWidget(widget), mLeft(x), mTop(y), mDepth(depth), mIsDirty(true),
  10. mResizeXWithWidget(false), mResizeYWithWidget(false), mWidth(0), mHeight(0), mRight(0), mBottom(0)
  11. {
  12. mLayout = cm_new<GUILayoutX, PoolAlloc>();
  13. mWidget.registerArea(this);
  14. }
  15. GUIArea::~GUIArea()
  16. {
  17. cm_delete<PoolAlloc>(mLayout);
  18. }
  19. GUIArea* GUIArea::create(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth)
  20. {
  21. GUIArea* area = new (cm_alloc<GUIArea, PoolAlloc>()) GUIArea(widget, x, y, depth);
  22. area->mWidth = width;
  23. area->mHeight = height;
  24. return area;
  25. }
  26. GUIArea* GUIArea::createStretchedXY(GUIWidget& widget, UINT32 offsetLeft,
  27. UINT32 offsetRight, UINT32 offsetTop, UINT32 offsetBottom, UINT16 depth)
  28. {
  29. GUIArea* area = new (cm_alloc<GUIArea, PoolAlloc>()) GUIArea(widget, offsetLeft, offsetTop, depth);
  30. area->mWidth = std::max(0, (INT32)widget.getTarget()->getWidth() - (INT32)offsetLeft - (INT32)offsetRight);
  31. area->mHeight = std::max(0, (INT32)widget.getTarget()->getHeight() - (INT32)offsetTop - (INT32)offsetBottom);
  32. area->mRight = offsetRight;
  33. area->mBottom = offsetBottom;
  34. area->mResizeXWithWidget = true;
  35. area->mResizeYWithWidget = true;
  36. return area;
  37. }
  38. GUIArea* GUIArea::createStretchedX(GUIWidget& widget, CM::UINT32 offsetLeft,
  39. CM::UINT32 offsetRight, CM::UINT32 offsetTop, CM::UINT32 height, CM::UINT16 depth)
  40. {
  41. GUIArea* area = new (cm_alloc<GUIArea, PoolAlloc>()) GUIArea(widget, offsetLeft, offsetTop, depth);
  42. area->mWidth = std::max(0, (INT32)widget.getTarget()->getWidth() - (INT32)offsetLeft - (INT32)offsetRight);
  43. area->mHeight = height;
  44. area->mRight = offsetRight;
  45. area->mResizeXWithWidget = true;
  46. area->mResizeYWithWidget = false;
  47. return area;
  48. }
  49. GUIArea* GUIArea::createStretchedY(GUIWidget& widget, CM::UINT32 offsetTop,
  50. CM::UINT32 offsetBottom, CM::UINT32 offsetLeft, CM::UINT32 width, CM::UINT16 depth)
  51. {
  52. GUIArea* area = new (cm_alloc<GUIArea, PoolAlloc>()) GUIArea(widget, offsetLeft, offsetTop, depth);
  53. area->mWidth = width;
  54. area->mHeight = std::max(0, (INT32)widget.getTarget()->getHeight() - (INT32)offsetTop - (INT32)offsetBottom);
  55. area->mBottom = offsetBottom;
  56. area->mResizeXWithWidget = false;
  57. area->mResizeYWithWidget = true;
  58. return area;
  59. }
  60. void GUIArea::destroy(GUIArea* area)
  61. {
  62. area->mWidget.unregisterArea(area);
  63. cm_delete<PoolAlloc>(area);
  64. }
  65. void GUIArea::destroyInternal(GUIArea* area)
  66. {
  67. cm_delete<PoolAlloc>(area);
  68. }
  69. void GUIArea::_update()
  70. {
  71. if(isDirty())
  72. {
  73. mLayout->_updateLayout(mLeft, mTop, mWidth, mHeight, mWidget.getDepth(), mDepth);
  74. mIsDirty = false;
  75. }
  76. }
  77. bool GUIArea::isDirty() const
  78. {
  79. if(mIsDirty)
  80. return true;
  81. return mLayout->_isContentDirty();
  82. }
  83. void GUIArea::notifyWindowResized(UINT32 newWidth, UINT32 newHeight)
  84. {
  85. if(mResizeXWithWidget)
  86. mWidth = (UINT32)std::max(0, (INT32)newWidth - (INT32)mLeft - (INT32)mRight);
  87. if(mResizeYWithWidget)
  88. mHeight = (UINT32)std::max(0, (INT32)newHeight - (INT32)mTop - (INT32)mBottom);
  89. if(mResizeXWithWidget || mResizeYWithWidget)
  90. mIsDirty = true;
  91. }
  92. }