BsEditorWidget.cpp 2.3 KB

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