BsEditorWindowManager.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "BsEditorWindowManager.h"
  2. #include "BsEditorWindow.h"
  3. #include "BsMainEditorWindow.h"
  4. namespace BansheeEngine
  5. {
  6. EditorWindowManager::EditorWindowManager()
  7. :mMainWindow(nullptr)
  8. {
  9. }
  10. EditorWindowManager::~EditorWindowManager()
  11. {
  12. while(mEditorWindows.size() > 0)
  13. destroy(mEditorWindows[0]);
  14. if(mMainWindow != nullptr)
  15. cm_delete(mMainWindow);
  16. }
  17. MainEditorWindow* EditorWindowManager::createMain(const RenderWindowPtr& parentRenderWindow)
  18. {
  19. if(mMainWindow == nullptr)
  20. mMainWindow = new (cm_alloc<MainEditorWindow>()) MainEditorWindow(parentRenderWindow);
  21. return mMainWindow;
  22. }
  23. EditorWindow* EditorWindowManager::create()
  24. {
  25. EditorWindow* newWindow = new (cm_alloc<EditorWindow>()) EditorWindow();
  26. mEditorWindows.push_back(newWindow);
  27. newWindow->initialize();
  28. return newWindow;
  29. }
  30. void EditorWindowManager::destroy(EditorWindowBase* window)
  31. {
  32. auto iterFind = std::find(begin(mEditorWindows), end(mEditorWindows), window);
  33. if(iterFind == end(mEditorWindows))
  34. return;
  35. auto iterFind2 = std::find(begin(mScheduledForDestruction), end(mScheduledForDestruction), window);
  36. if(iterFind2 == end(mScheduledForDestruction))
  37. mScheduledForDestruction.push_back(window);
  38. mEditorWindows.erase(iterFind);
  39. }
  40. void EditorWindowManager::update()
  41. {
  42. // Editor window destroy is deferred to this point, otherwise we risk
  43. // destroying a window while it's still being used (situation that was happening with GUIManager)
  44. for(auto& windowToDestroy : mScheduledForDestruction)
  45. {
  46. cm_delete(windowToDestroy);
  47. }
  48. mScheduledForDestruction.clear();
  49. mMainWindow->update();
  50. for(auto& window : mEditorWindows)
  51. {
  52. window->update();
  53. }
  54. }
  55. }