60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#pragma once
|
||
|
||
#include <extra2d/core/module.h>
|
||
#include <extra2d/platform/glfw/glfw_window.h>
|
||
#include <functional>
|
||
#include <string>
|
||
|
||
namespace extra2d {
|
||
|
||
/**
|
||
* @brief 窗口模块配置结构
|
||
*/
|
||
struct WindowCfg {
|
||
std::string title;
|
||
int w;
|
||
int h;
|
||
bool vsync;
|
||
int priority;
|
||
|
||
WindowCfg()
|
||
: title("Extra2D"), w(1280), h(720), vsync(true), priority(0) {}
|
||
};
|
||
|
||
/**
|
||
* @brief 窗口模块
|
||
* 管理窗口创建和生命周期
|
||
*/
|
||
class WindowModule : public Module {
|
||
public:
|
||
/**
|
||
* @brief 构造函数(Lambda 配置)
|
||
* @param configFn 配置函数
|
||
*/
|
||
explicit WindowModule(std::function<void(WindowCfg &)> configFn);
|
||
|
||
/**
|
||
* @brief 析构函数
|
||
*/
|
||
~WindowModule() override;
|
||
|
||
bool init() override;
|
||
void shutdown() override;
|
||
bool ok() const override { return initialized_; }
|
||
const char *name() const override { return "window"; }
|
||
int priority() const override { return cfg_.priority; }
|
||
|
||
/**
|
||
* @brief 获取窗口
|
||
* @return 窗口指针
|
||
*/
|
||
GLFWWindow *win() const { return win_.get(); }
|
||
|
||
private:
|
||
WindowCfg cfg_;
|
||
Unique<GLFWWindow> win_;
|
||
bool initialized_ = false;
|
||
};
|
||
|
||
} // namespace extra2d
|