59 lines
1.0 KiB
C++
59 lines
1.0 KiB
C++
#include <extra2d/core/service_locator.h>
|
|
#include <extra2d/platform/window_module.h>
|
|
#include <extra2d/services/logger_service.h>
|
|
|
|
#include <extra2d/platform/glfw/glfw_window.h>
|
|
|
|
#ifdef __SWITCH__
|
|
#include <switch.h>
|
|
#endif
|
|
|
|
namespace extra2d {
|
|
|
|
WindowModule::WindowModule(std::function<void(WindowCfg &)> configFn) {
|
|
configFn(cfg_);
|
|
}
|
|
|
|
WindowModule::~WindowModule() {
|
|
if (initialized_) {
|
|
shutdown();
|
|
}
|
|
}
|
|
|
|
bool WindowModule::init() {
|
|
if (initialized_)
|
|
return true;
|
|
|
|
E2D_INFO("正在创建 GLFW 窗口,尺寸 {}x{}", cfg_.w, cfg_.h);
|
|
|
|
win_ = ptr::makeUnique<GLFWWindow>();
|
|
if (!win_) {
|
|
E2D_ERROR("创建窗口失败");
|
|
return false;
|
|
}
|
|
|
|
if (!win_->create(cfg_.title, cfg_.w, cfg_.h, cfg_.vsync)) {
|
|
E2D_ERROR("创建窗口失败");
|
|
shutdown();
|
|
return false;
|
|
}
|
|
|
|
E2D_INFO("窗口创建成功");
|
|
initialized_ = true;
|
|
return true;
|
|
}
|
|
|
|
void WindowModule::shutdown() {
|
|
if (!initialized_)
|
|
return;
|
|
|
|
if (win_) {
|
|
win_->destroy();
|
|
win_.reset();
|
|
}
|
|
|
|
initialized_ = false;
|
|
}
|
|
|
|
} // namespace extra2d
|