-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowManager.h
More file actions
77 lines (65 loc) · 1.74 KB
/
WindowManager.h
File metadata and controls
77 lines (65 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright (c) 2024-2025 Toksisitee. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, refer to license.md or https://opensource.org/licenses/MIT
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*/
#include <vector>
#include <memory>
#include <iostream>
#include <tuple>
#include "WindowBase.h"
class CWindowManager {
public:
CWindowManager() = default;
~CWindowManager()
{
DestroyAll();
}
template<typename T, typename... Args>
T* AddWindow( Args&&... args )
{
static_assert(std::is_base_of<CWindowBase, T>::value, "T must derive from CWindowBase");
auto&& tuple = std::forward_as_tuple( args... );
if ( GetWindow( std::get<1>( tuple ) ) == nullptr ) {
auto& pWnd = m_Windows.emplace_back( std::make_unique<T>( std::forward<Args>( args )... ) );
return static_cast<T*>(pWnd.get());
}
return nullptr;
}
void Render()
{
m_Windows.erase( std::remove_if( m_Windows.begin(), m_Windows.end(),
[]( const std::unique_ptr<CWindowBase>& pWnd ) {
if ( !pWnd->IsOpen() ) pWnd->Cleanup();
return !pWnd->IsOpen();
} ), m_Windows.end()
);
for ( auto& pWnd : m_Windows ) {
pWnd->RenderBegin();
pWnd->Render();
pWnd->RenderEnd();
}
}
void DestroyAll()
{
for ( auto& pWnd : m_Windows ) {
pWnd->Cleanup();
}
m_Windows.clear();
}
CWindowBase* GetWindow( const std::string& sWndName )
{
for ( auto& pWnd : m_Windows ) {
if ( pWnd->GetWindowName() == sWndName ) {
return pWnd.get();
}
}
return nullptr;
}
private:
std::vector<std::unique_ptr<CWindowBase>> m_Windows;
};
extern CWindowManager g_WndMngr;