BsEditorWindowManager.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. for (auto& windowToDestroy : mScheduledForDestruction)
  15. bs_delete(windowToDestroy);
  16. mScheduledForDestruction.clear();
  17. if(mMainWindow != nullptr)
  18. bs_delete(mMainWindow);
  19. }
  20. MainEditorWindow* EditorWindowManager::createMain(const RenderWindowPtr& parentRenderWindow)
  21. {
  22. if(mMainWindow == nullptr)
  23. mMainWindow = new (bs_alloc<MainEditorWindow>()) MainEditorWindow(parentRenderWindow);
  24. return mMainWindow;
  25. }
  26. EditorWindow* EditorWindowManager::create()
  27. {
  28. EditorWindow* newWindow = new (bs_alloc<EditorWindow>()) EditorWindow();
  29. mEditorWindows.push_back(newWindow);
  30. newWindow->initialize();
  31. return newWindow;
  32. }
  33. void EditorWindowManager::registerWindow(EditorWindowBase* window)
  34. {
  35. mEditorWindows.push_back(window);
  36. }
  37. void EditorWindowManager::destroy(EditorWindowBase* window)
  38. {
  39. auto iterFind = std::find(begin(mEditorWindows), end(mEditorWindows), window);
  40. if(iterFind == end(mEditorWindows))
  41. return;
  42. auto iterFind2 = std::find(begin(mScheduledForDestruction), end(mScheduledForDestruction), window);
  43. if(iterFind2 == end(mScheduledForDestruction))
  44. mScheduledForDestruction.push_back(window);
  45. mEditorWindows.erase(iterFind);
  46. }
  47. void EditorWindowManager::update()
  48. {
  49. // Editor window destroy is deferred to this point, otherwise we risk
  50. // destroying a window while it's still being used (situation that was happening with GUIManager)
  51. for(auto& windowToDestroy : mScheduledForDestruction)
  52. {
  53. bs_delete(windowToDestroy);
  54. }
  55. mScheduledForDestruction.clear();
  56. // Make a copy since other editors might be opened/closed from editor update() methods
  57. mEditorWindowsSnapshot = mEditorWindows;
  58. mMainWindow->update();
  59. for (auto& window : mEditorWindowsSnapshot)
  60. {
  61. window->update();
  62. }
  63. }
  64. }