BsEditorWidget.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // Note: Must not be virtual as parent container uses it in constructor
  63. void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent)
  64. {
  65. if(mParent != parent)
  66. {
  67. if(parent != nullptr)
  68. {
  69. if(mContent == nullptr)
  70. mContent = GUIArea::create(parent->getParentWidget(), 0, 0, 0, 0, 10000);
  71. else
  72. mContent->changeParentWidget(&parent->getParentWidget());
  73. }
  74. else
  75. {
  76. if(mContent != nullptr)
  77. mContent->changeParentWidget(nullptr);
  78. }
  79. mParent = parent;
  80. if(!onParentChanged.empty())
  81. onParentChanged(mParent);
  82. }
  83. }
  84. void EditorWidgetBase::_disable()
  85. {
  86. mContent->disable();
  87. }
  88. void EditorWidgetBase::_enable()
  89. {
  90. mContent->enable();
  91. }
  92. GUIWidget& EditorWidgetBase::getParentWidget() const
  93. {
  94. return mParent->getParentWidget();
  95. }
  96. }