BsEditorWidget.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "BsEditorWidget.h"
  2. #include "BsGUIManager.h"
  3. #include "BsGUIWidget.h"
  4. #include "BsGUITexture.h"
  5. #include "BsGUISkin.h"
  6. #include "BsGUILayout.h"
  7. #include "BsBuiltinResources.h"
  8. #include "BsGUIArea.h"
  9. #include "BsEditorWidgetContainer.h"
  10. #include "BsEditorWidgetManager.h"
  11. namespace BansheeEngine
  12. {
  13. EditorWidgetBase::EditorWidgetBase(const HString& displayName, const String& name, EditorWidgetContainer& parentContainer)
  14. :mDisplayName(displayName), mName(name), mParent(nullptr), mContent(nullptr), mX(0), mY(0), mWidth(0), mHeight(0)
  15. {
  16. parentContainer.add(*this);
  17. }
  18. EditorWidgetBase::~EditorWidgetBase()
  19. {
  20. if (mContent != nullptr)
  21. GUIArea::destroy(mContent);
  22. }
  23. void EditorWidgetBase::close()
  24. {
  25. EditorWidgetManager::instance().close(this);
  26. }
  27. void EditorWidgetBase::destroy(EditorWidgetBase* widget)
  28. {
  29. widget->~EditorWidgetBase();
  30. bs_free(widget);
  31. }
  32. void EditorWidgetBase::_setPosition(INT32 x, INT32 y)
  33. {
  34. if (mX == x && mY == y)
  35. return;
  36. mX = x;
  37. mY = y;
  38. if(mContent != nullptr)
  39. mContent->setPosition(x, y);
  40. doOnMoved(x, y);
  41. }
  42. void EditorWidgetBase::_setSize(UINT32 width, UINT32 height)
  43. {
  44. if (mWidth == width && mHeight == height)
  45. return;
  46. mWidth = width;
  47. mHeight = height;
  48. if(mContent != nullptr)
  49. mContent->setSize(width, height);
  50. doOnResized(width, height);
  51. }
  52. void EditorWidgetBase::doOnMoved(INT32 x, INT32 y)
  53. {
  54. if (!onMoved.empty())
  55. onMoved(x, y);
  56. }
  57. void EditorWidgetBase::doOnResized(UINT32 width, UINT32 height)
  58. {
  59. if (!onResized.empty())
  60. onResized(width, height);
  61. }
  62. void EditorWidgetBase::doOnParentChanged()
  63. {
  64. }
  65. // Note: Must not be virtual as parent container uses it in constructor
  66. void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent)
  67. {
  68. if(mParent != parent)
  69. {
  70. if(parent != nullptr)
  71. {
  72. if(mContent == nullptr)
  73. mContent = GUIArea::create(parent->getParentWidget(), 0, 0, 0, 0, 10000);
  74. else
  75. mContent->changeParentWidget(&parent->getParentWidget());
  76. }
  77. else
  78. {
  79. if(mContent != nullptr)
  80. mContent->changeParentWidget(nullptr);
  81. }
  82. mParent = parent;
  83. doOnParentChanged();
  84. if(!onParentChanged.empty())
  85. onParentChanged(mParent);
  86. }
  87. }
  88. void EditorWidgetBase::_disable()
  89. {
  90. mContent->disable();
  91. }
  92. void EditorWidgetBase::_enable()
  93. {
  94. mContent->enable();
  95. }
  96. GUIWidget& EditorWidgetBase::getParentWidget() const
  97. {
  98. return mParent->getParentWidget();
  99. }
  100. }