🎉 begin project
This commit is contained in:
commit
8da6ddc689
29 changed files with 1261 additions and 0 deletions
91
Source/Core/WindowManager.cppm
Normal file
91
Source/Core/WindowManager.cppm
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue