hyporo-cpp/source/hpr/window_system/window_system.cpp

66 lines
1.3 KiB
C++
Raw Normal View History

2022-10-27 22:27:50 +05:00
#include "window_system.hpp"
#include "glfw/window_system.hpp"
namespace hpr::gpu
{
WindowSystem::WindowSystem() :
WindowContext {Provider::Unknown}
{}
WindowSystem::WindowSystem(Provider provider) :
WindowContext {provider}
{}
WindowSystem::~WindowSystem() = default;
2022-10-28 21:16:03 +05:00
WindowSystem* WindowSystem::create(Provider provider)
2022-10-27 22:27:50 +05:00
{
if (provider == Provider::Unknown)
throw std::invalid_argument("Cannot create window system from 'Unknown' provider");
if (provider == Provider::GLFW)
2022-10-28 21:16:03 +05:00
return new glfw::WindowSystem;
2022-10-27 22:27:50 +05:00
else
throw std::invalid_argument("Unsupported window system");
}
void WindowSystem::destroy(WindowSystem*& ws)
{
delete ws;
ws = nullptr;
}
2022-10-28 21:16:03 +05:00
Window* WindowSystem::window(int index)
2022-10-27 22:27:50 +05:00
{
return p_windows[index];
}
void WindowSystem::closeWindow(Window* window)
{
window->close();
}
void WindowSystem::destroyWindow(Window* window)
{
2022-11-18 21:50:49 +05:00
for (auto n = 0; n < p_windows.size(); ++n)
if (p_windows[n] == window)
p_windows.remove(n);
2022-10-28 21:16:03 +05:00
window->close();
window = nullptr;
2022-10-27 22:27:50 +05:00
}
2022-10-28 21:16:03 +05:00
Monitor* WindowSystem::monitor(int index)
2022-10-27 22:27:50 +05:00
{
return p_monitors[index];
}
void WindowSystem::destroyMonitor(Monitor* monitor)
{
2022-11-18 21:50:49 +05:00
for (auto n = 0; n < p_monitors.size(); ++n)
if (p_monitors[n] == monitor)
p_monitors.remove(n);
2022-10-27 22:27:50 +05:00
}
}