BsEditorWidget.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. mX = x;
  35. mY = y;
  36. if(mContent != nullptr)
  37. mContent->setPosition(x, y);
  38. if(!onMoved.empty())
  39. onMoved(x, y);
  40. }
  41. void EditorWidgetBase::_setSize(UINT32 width, UINT32 height)
  42. {
  43. mWidth = width;
  44. mHeight = height;
  45. if(mContent != nullptr)
  46. mContent->setSize(width, height);
  47. if(!onResized.empty())
  48. onResized(width, height);
  49. }
  50. // Note: Must not be virtual as parent container uses it in constructor
  51. void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent)
  52. {
  53. if(mParent != parent)
  54. {
  55. if(parent != nullptr)
  56. {
  57. if(mContent == nullptr)
  58. mContent = GUIArea::create(parent->getParentWidget(), 0, 0, 0, 0, 10000);
  59. else
  60. mContent->changeParentWidget(&parent->getParentWidget());
  61. }
  62. else
  63. {
  64. if(mContent != nullptr)
  65. mContent->changeParentWidget(nullptr);
  66. }
  67. mParent = parent;
  68. if(!onParentChanged.empty())
  69. onParentChanged(mParent);
  70. }
  71. }
  72. void EditorWidgetBase::_disable()
  73. {
  74. mContent->disable();
  75. }
  76. void EditorWidgetBase::_enable()
  77. {
  78. mContent->enable();
  79. }
  80. GUIWidget& EditorWidgetBase::getParentWidget() const
  81. {
  82. return mParent->getParentWidget();
  83. }
  84. }