BsEditorWidget.cpp 2.1 KB

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