91 lines
No EOL
2.3 KiB
C++
91 lines
No EOL
2.3 KiB
C++
module;
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
export module VUI:WindowManager;
|
|
|
|
import :Window;
|
|
import :PlatformWindow;
|
|
import :Time;
|
|
|
|
namespace VUI {
|
|
|
|
export struct WindowManager {
|
|
static Ref<Window> Create(uint32_t width, uint32_t height,
|
|
const std::string &title);
|
|
static Ref<Window> Create(const WindowSpecification &);
|
|
static void Manage(const Ref<Window> &window);
|
|
|
|
static void Update();
|
|
static void Close(Ref<Window> &);
|
|
static void CloseByTitle(const std::string &title);
|
|
static void CloseAll();
|
|
static bool HasOpenWindows();
|
|
|
|
protected:
|
|
std::vector<Ref<Window>> m_Windows{};
|
|
friend Window;
|
|
};
|
|
|
|
static WindowManager s_WindowManager = {};
|
|
|
|
Ref<Window> WindowManager::Create(uint32_t width, uint32_t height,
|
|
const std::string &title) {
|
|
return Create(WindowSpecification{width, height, title});
|
|
}
|
|
|
|
Ref<Window> WindowManager::Create(const WindowSpecification &specification) {
|
|
if (GetTimeOffset() == 0)
|
|
SetTime(0);
|
|
|
|
auto window = Windowing::CreateWindowRef();
|
|
window->m_Specification = specification;
|
|
window->m_WindowHandle = s_Handle++;
|
|
window->createWindow();
|
|
Manage(window);
|
|
return window;
|
|
}
|
|
|
|
void WindowManager::Manage(const Ref<Window> &window) {
|
|
s_WindowManager.m_Windows.push_back(window);
|
|
}
|
|
|
|
void WindowManager::Update() {
|
|
Input::PostFrameUpdate();
|
|
UpdateDeltaTime();
|
|
for (auto &window : s_WindowManager.m_Windows) {
|
|
window->pullEvents();
|
|
}
|
|
std::erase_if(s_WindowManager.m_Windows,
|
|
[](Ref<Window> &window) { return !window->isOpen(); });
|
|
}
|
|
|
|
void WindowManager::Close(Ref<Window> &refWindow) {
|
|
if (!refWindow)
|
|
return;
|
|
refWindow->close();
|
|
std::erase_if(s_WindowManager.m_Windows, [&refWindow](auto &window) {
|
|
return !window->isOpen() || window == refWindow;
|
|
});
|
|
}
|
|
void WindowManager::CloseByTitle(const std::string &title) {
|
|
std::erase_if(s_WindowManager.m_Windows, [&title](Ref<Window> &window) {
|
|
if (window->getTitle() == title) {
|
|
window->close();
|
|
}
|
|
return !window->isOpen();
|
|
});
|
|
}
|
|
void WindowManager::CloseAll() {
|
|
for (auto &window : s_WindowManager.m_Windows) {
|
|
window->close();
|
|
}
|
|
s_WindowManager.m_Windows.clear();
|
|
}
|
|
bool WindowManager::HasOpenWindows() {
|
|
return !s_WindowManager.m_Windows.empty();
|
|
}
|
|
|
|
} // namespace VUI
|