| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "CmRenderWindowManager.h"
- namespace CamelotFramework
- {
- RenderWindowManager::RenderWindowManager()
- :mWindowInFocus(nullptr), mNewWindowInFocus(nullptr)
- {
- }
- RenderWindowPtr RenderWindowManager::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
- {
- RenderWindowPtr renderWindow = createImpl(desc, parentWindow);
- renderWindow->setThisPtr(renderWindow);
- renderWindow->initialize();
- {
- CM_LOCK_MUTEX(mWindowMutex);
- mCreatedWindows.push_back(renderWindow.get());
- }
-
- return renderWindow;
- }
- void RenderWindowManager::windowDestroyed(RenderWindow* window)
- {
- {
- CM_LOCK_MUTEX(mWindowMutex);
- auto iterFind = std::find(begin(mCreatedWindows), end(mCreatedWindows), window);
- if(iterFind == mCreatedWindows.end())
- CM_EXCEPT(InternalErrorException, "Trying to destroy a window that is not in the created windows list.");
- mCreatedWindows.erase(iterFind);
- }
- }
- void RenderWindowManager::windowFocusReceived(RenderWindow* window)
- {
- CM_LOCK_MUTEX(mWindowMutex);
- mNewWindowInFocus = window;
- }
- void RenderWindowManager::windowMovedOrResized(RenderWindow* window)
- {
- CM_LOCK_MUTEX(mWindowMutex);
- auto iterFind = std::find(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), window);
- if(iterFind == end(mMovedOrResizedWindows))
- mMovedOrResizedWindows.push_back(window);
- }
- void RenderWindowManager::update()
- {
- RenderWindow* newWinInFocus = nullptr;
- Vector<RenderWindow*>::type movedOrResizedWindows;
- {
- CM_LOCK_MUTEX(mWindowMutex);
- newWinInFocus = mNewWindowInFocus;
- movedOrResizedWindows = mMovedOrResizedWindows;
- mMovedOrResizedWindows.clear();
- }
- if(mWindowInFocus != newWinInFocus)
- {
- if(mWindowInFocus != nullptr)
- {
- if(!onFocusLost.empty())
- onFocusLost(*mWindowInFocus);
- }
- if(newWinInFocus != nullptr)
- {
- if(!onFocusGained.empty())
- onFocusGained(*newWinInFocus);
- }
- mWindowInFocus = newWinInFocus;
- }
- if(!onMovedOrResized.empty())
- {
- for(auto& window : movedOrResizedWindows)
- {
- onMovedOrResized(*window);
- }
- }
- }
- Vector<RenderWindow*>::type RenderWindowManager::getRenderWindows() const
- {
- CM_LOCK_MUTEX(mWindowMutex);
- return mCreatedWindows;
- }
- }
|