BsEditorWindowManager.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "BsEditorWindowManager.h"
  2. #include "BsEditorWindow.h"
  3. using namespace CamelotFramework;
  4. using namespace BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. EditorWindowManager::~EditorWindowManager()
  8. {
  9. while(mEditorWindows.size() > 0)
  10. destroy(mEditorWindows[0]);
  11. }
  12. EditorWindow* EditorWindowManager::create()
  13. {
  14. EditorWindow* newWindow = new (cm_alloc<EditorWindow>()) EditorWindow();
  15. mEditorWindows.push_back(newWindow);
  16. newWindow->initialize();
  17. return newWindow;
  18. }
  19. void EditorWindowManager::destroy(EditorWindowBase* window)
  20. {
  21. auto iterFind = std::find(begin(mEditorWindows), end(mEditorWindows), window);
  22. if(iterFind == end(mEditorWindows))
  23. CM_EXCEPT(InternalErrorException, "Trying to destroy an editor window that's not registered in the window manager.");
  24. auto iterFind2 = std::find(begin(mScheduledForDestruction), end(mScheduledForDestruction), window);
  25. if(iterFind2 == end(mScheduledForDestruction))
  26. mScheduledForDestruction.push_back(window);
  27. mEditorWindows.erase(iterFind);
  28. }
  29. void EditorWindowManager::update()
  30. {
  31. // Editor window destroy is deferred to this point, otherwise we risk
  32. // destroying a window while it's still being used (situation that was happening with GUIManager)
  33. for(auto& windowToDestroy : mScheduledForDestruction)
  34. {
  35. cm_delete(windowToDestroy);
  36. }
  37. mScheduledForDestruction.clear();
  38. }
  39. }