BsEditorWindowManager.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "EditorWindow/BsEditorWindowManager.h"
  4. #include "EditorWindow/BsEditorWindow.h"
  5. #include "EditorWindow/BsMainEditorWindow.h"
  6. namespace bs
  7. {
  8. EditorWindowManager::EditorWindowManager()
  9. :mMainWindow(nullptr)
  10. {
  11. }
  12. EditorWindowManager::~EditorWindowManager()
  13. {
  14. while(mEditorWindows.size() > 0)
  15. destroy(mEditorWindows[0]);
  16. for (auto& windowToDestroy : mScheduledForDestruction)
  17. bs_delete(windowToDestroy);
  18. mScheduledForDestruction.clear();
  19. if(mMainWindow != nullptr)
  20. bs_delete(mMainWindow);
  21. }
  22. MainEditorWindow* EditorWindowManager::createMain(const SPtr<RenderWindow>& parentRenderWindow)
  23. {
  24. if(mMainWindow == nullptr)
  25. mMainWindow = new (bs_alloc<MainEditorWindow>()) MainEditorWindow(parentRenderWindow);
  26. return mMainWindow;
  27. }
  28. EditorWindow* EditorWindowManager::create()
  29. {
  30. EditorWindow* newWindow = new (bs_alloc<EditorWindow>()) EditorWindow();
  31. mEditorWindows.push_back(newWindow);
  32. newWindow->initialize();
  33. return newWindow;
  34. }
  35. void EditorWindowManager::registerWindow(EditorWindowBase* window)
  36. {
  37. mEditorWindows.push_back(window);
  38. }
  39. void EditorWindowManager::destroy(EditorWindowBase* window)
  40. {
  41. auto iterFind = std::find(begin(mEditorWindows), end(mEditorWindows), window);
  42. if(iterFind == end(mEditorWindows))
  43. return;
  44. auto iterFind2 = std::find(begin(mScheduledForDestruction), end(mScheduledForDestruction), window);
  45. if(iterFind2 == end(mScheduledForDestruction))
  46. mScheduledForDestruction.push_back(window);
  47. mEditorWindows.erase(iterFind);
  48. }
  49. void EditorWindowManager::update()
  50. {
  51. // Editor window destroy is deferred to this point, otherwise we risk
  52. // destroying a window while it's still being used (situation that was happening with GUIManager)
  53. for(auto& windowToDestroy : mScheduledForDestruction)
  54. {
  55. bs_delete(windowToDestroy);
  56. }
  57. mScheduledForDestruction.clear();
  58. // Make a copy since other editors might be opened/closed from editor update() methods
  59. mEditorWindowsSnapshot = mEditorWindows;
  60. mMainWindow->update();
  61. for (auto& window : mEditorWindowsSnapshot)
  62. {
  63. window->update();
  64. }
  65. }
  66. bool EditorWindowManager::hasFocus() const
  67. {
  68. if (mMainWindow->hasFocus())
  69. return true;
  70. for(auto& window : mEditorWindows)
  71. {
  72. if (window->hasFocus())
  73. return true;
  74. }
  75. return false;
  76. }
  77. }