BsEditorWidget.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "BsEngineGUI.h"
  8. #include "BsGUIArea.h"
  9. #include "BsEditorWidgetContainer.h"
  10. #include "BsEditorWidgetManager.h"
  11. using namespace CamelotFramework;
  12. using namespace BansheeEngine;
  13. namespace BansheeEditor
  14. {
  15. EditorWidgetBase::EditorWidgetBase(const HString& displayName, const CM::String& name, EditorWidgetContainer& parentContainer)
  16. :mDisplayName(displayName), mName(name), mParent(nullptr), mContent(nullptr)
  17. {
  18. parentContainer.add(*this);
  19. }
  20. EditorWidgetBase::~EditorWidgetBase()
  21. {
  22. }
  23. void EditorWidgetBase::close()
  24. {
  25. EditorWidgetManager::instance().close(this);
  26. }
  27. void EditorWidgetBase::destroy(EditorWidgetBase* widget)
  28. {
  29. widget->~EditorWidgetBase();
  30. cm_free(widget);
  31. }
  32. void EditorWidgetBase::_setPosition(INT32 x, INT32 y)
  33. {
  34. if(mContent == nullptr)
  35. return;
  36. mContent->setPosition(x, y);
  37. }
  38. void EditorWidgetBase::_setSize(UINT32 width, UINT32 height)
  39. {
  40. if(mContent == nullptr)
  41. return;
  42. mContent->setSize(width, height);
  43. }
  44. // Note: Must not be virtual as parent container uses it in constructor
  45. void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent)
  46. {
  47. if(mParent != parent)
  48. {
  49. if(parent != nullptr)
  50. {
  51. if(mContent == nullptr)
  52. mContent = GUIArea::create(parent->getParentWidget(), 0, 0, 0, 0, 10000);
  53. else
  54. mContent->changeParentWidget(&parent->getParentWidget());
  55. }
  56. else
  57. {
  58. if(mContent != nullptr)
  59. mContent->changeParentWidget(nullptr);
  60. }
  61. mParent = parent;
  62. }
  63. }
  64. void EditorWidgetBase::_disable()
  65. {
  66. mContent->disable();
  67. }
  68. void EditorWidgetBase::_enable()
  69. {
  70. mContent->enable();
  71. }
  72. GUIWidget& EditorWidgetBase::getParentWidget() const
  73. {
  74. return mParent->getParentWidget();
  75. }
  76. }