BsEditorWindowManager.cpp 1.9 KB

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