diff --git a/Extra2D/include/extra2d/app/application.h b/Extra2D/include/extra2d/app/application.h index 3011a93..6412a13 100644 --- a/Extra2D/include/extra2d/app/application.h +++ b/Extra2D/include/extra2d/app/application.h @@ -8,7 +8,7 @@ namespace extra2d { -class IWindow; +class GLFWWindow; class RenderBackend; class WindowModule; class RenderModule; @@ -85,7 +85,7 @@ public: * @brief 获取窗口 * @return 窗口指针 */ - IWindow *window(); + GLFWWindow *window(); /** * @brief 获取渲染器 diff --git a/Extra2D/include/extra2d/extra2d.h b/Extra2D/include/extra2d/extra2d.h index 398b7e6..3b22b54 100644 --- a/Extra2D/include/extra2d/extra2d.h +++ b/Extra2D/include/extra2d/extra2d.h @@ -13,7 +13,7 @@ // Config removed - app info now in Application class // Platform -#include +#include #include #include diff --git a/Extra2D/include/extra2d/graphics/core/render_backend.h b/Extra2D/include/extra2d/graphics/core/render_backend.h index b12bcb4..eb9a1b2 100644 --- a/Extra2D/include/extra2d/graphics/core/render_backend.h +++ b/Extra2D/include/extra2d/graphics/core/render_backend.h @@ -9,7 +9,7 @@ namespace extra2d { // 前向声明 -class IWindow; +class GLFWWindow; class Texture; class FontAtlas; class Shader; @@ -26,7 +26,7 @@ public: // ------------------------------------------------------------------------ // 生命周期 // ------------------------------------------------------------------------ - virtual bool init(IWindow* window) = 0; + virtual bool init(GLFWWindow* window) = 0; virtual void shutdown() = 0; // ------------------------------------------------------------------------ diff --git a/Extra2D/include/extra2d/graphics/opengl/gl_renderer.h b/Extra2D/include/extra2d/graphics/opengl/gl_renderer.h index 609a6ca..cfcf4ba 100644 --- a/Extra2D/include/extra2d/graphics/opengl/gl_renderer.h +++ b/Extra2D/include/extra2d/graphics/opengl/gl_renderer.h @@ -15,7 +15,7 @@ namespace extra2d { // 前向声明 -class IWindow; +class GLFWWindow; class GLContext; class GLFramebuffer; @@ -28,7 +28,7 @@ public: ~GLRenderer() override; // RenderBackend 接口实现 - bool init(IWindow *window) override; + bool init(GLFWWindow *window) override; void shutdown() override; void beginFrame(const Color &clearColor) override; @@ -132,7 +132,7 @@ private: float r, g, b, a; }; - IWindow *window_; + GLFWWindow *window_; GLSpriteBatch spriteBatch_; Ptr shapeShader_; Ptr sdfFontShader_; // SDF字体专用着色器 diff --git a/Extra2D/include/extra2d/platform/glfw/glfw_window.h b/Extra2D/include/extra2d/platform/glfw/glfw_window.h index 7cb9ef4..b6d43e8 100644 --- a/Extra2D/include/extra2d/platform/glfw/glfw_window.h +++ b/Extra2D/include/extra2d/platform/glfw/glfw_window.h @@ -1,54 +1,187 @@ #pragma once -#include +#include +#include #include +#include +#include namespace extra2d { +/** + * @brief 光标形状 + */ +enum class Cursor { + Arrow, + IBeam, + Crosshair, + Hand, + HResize, + VResize, + Hidden +}; + /** * @brief GLFW 窗口实现 */ -class GLFWWindow : public IWindow { +class GLFWWindow { public: + using ResizeCb = std::function; + using CloseCb = std::function; + using FocusCb = std::function; + GLFWWindow(); - ~GLFWWindow() override; + ~GLFWWindow(); - bool create(const std::string& title, int width, int height, bool vsync = true) override; - void destroy() override; + /** + * @brief 创建窗口 + * @param title 窗口标题 + * @param width 窗口宽度 + * @param height 窗口高度 + * @param vsync 是否启用垂直同步 + * @return 创建是否成功 + */ + bool create(const std::string& title, int width, int height, bool vsync = true); - void poll() override; - void swap() override; - bool shouldClose() const override; - void close() override; + /** + * @brief 销毁窗口 + */ + void destroy(); - void setTitle(const std::string& title) override; - void setSize(int w, int h) override; - void setPos(int x, int y) override; - void setFullscreen(bool fs) override; - void setVSync(bool vsync) override; - void setVisible(bool visible) override; + /** + * @brief 轮询事件 + */ + void poll(); - int width() const override; - int height() const override; - Size size() const override; - Vec2 pos() const override; - bool fullscreen() const override; - bool vsync() const override; - bool focused() const override; - bool minimized() const override; + /** + * @brief 交换缓冲区 + */ + void swap(); - float scaleX() const override; - float scaleY() const override; + /** + * @brief 窗口是否应该关闭 + */ + bool shouldClose() const; - void setCursor(Cursor cursor) override; - void showCursor(bool show) override; - void lockCursor(bool lock) override; + /** + * @brief 设置窗口关闭标志 + */ + void close(); - void onResize(ResizeCb cb) override; - void onClose(CloseCb cb) override; - void onFocus(FocusCb cb) override; + /** + * @brief 设置窗口标题 + */ + void setTitle(const std::string& title); - void* native() const override; + /** + * @brief 设置窗口大小 + */ + void setSize(int w, int h); + + /** + * @brief 设置窗口位置 + */ + void setPos(int x, int y); + + /** + * @brief 设置全屏模式 + */ + void setFullscreen(bool fs); + + /** + * @brief 设置垂直同步 + */ + void setVSync(bool vsync); + + /** + * @brief 设置窗口可见性 + */ + void setVisible(bool visible); + + /** + * @brief 获取窗口宽度 + */ + int width() const { return width_; } + + /** + * @brief 获取窗口高度 + */ + int height() const { return height_; } + + /** + * @brief 获取窗口大小 + */ + Size size() const; + + /** + * @brief 获取窗口位置 + */ + Vec2 pos() const; + + /** + * @brief 是否全屏 + */ + bool fullscreen() const { return fullscreen_; } + + /** + * @brief 是否启用垂直同步 + */ + bool vsync() const { return vsync_; } + + /** + * @brief 窗口是否获得焦点 + */ + bool focused() const { return focused_; } + + /** + * @brief 窗口是否最小化 + */ + bool minimized() const { return minimized_; } + + /** + * @brief 获取内容缩放X + */ + float scaleX() const { return scaleX_; } + + /** + * @brief 获取内容缩放Y + */ + float scaleY() const { return scaleY_; } + + /** + * @brief 设置光标形状 + */ + void setCursor(Cursor cursor); + + /** + * @brief 显示/隐藏光标 + */ + void showCursor(bool show); + + /** + * @brief 锁定/解锁光标 + */ + void lockCursor(bool lock); + + /** + * @brief 设置大小改变回调 + */ + void onResize(ResizeCb cb) { resizeCb_ = cb; } + + /** + * @brief 设置关闭回调 + */ + void onClose(CloseCb cb) { closeCb_ = cb; } + + /** + * @brief 设置焦点改变回调 + */ + void onFocus(FocusCb cb) { focusCb_ = cb; } + + /** + * @brief 获取原生窗口句柄 + */ + void* native() const; /** * @brief 获取 GLFW 窗口句柄 diff --git a/Extra2D/include/extra2d/platform/iwindow.h b/Extra2D/include/extra2d/platform/iwindow.h deleted file mode 100644 index eee6822..0000000 --- a/Extra2D/include/extra2d/platform/iwindow.h +++ /dev/null @@ -1,197 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace extra2d { - -/** - * @brief 光标形状 - */ -enum class Cursor { - Arrow, - IBeam, - Crosshair, - Hand, - HResize, - VResize, - Hidden -}; - -/** - * @brief 窗口抽象接口 - * 所有平台窗口后端必须实现此接口 - */ -class IWindow { -public: - virtual ~IWindow() = default; - - /** - * @brief 创建窗口 - * @param title 窗口标题 - * @param width 窗口宽度 - * @param height 窗口高度 - * @param vsync 是否启用垂直同步 - * @return 创建是否成功 - */ - virtual bool create(const std::string& title, int width, int height, bool vsync = true) = 0; - - /** - * @brief 销毁窗口 - */ - virtual void destroy() = 0; - - /** - * @brief 轮询事件 - */ - virtual void poll() = 0; - - /** - * @brief 交换缓冲区 - */ - virtual void swap() = 0; - - /** - * @brief 窗口是否应该关闭 - */ - virtual bool shouldClose() const = 0; - - /** - * @brief 设置窗口关闭标志 - */ - virtual void close() = 0; - - /** - * @brief 设置窗口标题 - */ - virtual void setTitle(const std::string& title) = 0; - - /** - * @brief 设置窗口大小 - */ - virtual void setSize(int w, int h) = 0; - - /** - * @brief 设置窗口位置 - */ - virtual void setPos(int x, int y) = 0; - - /** - * @brief 设置全屏模式 - */ - virtual void setFullscreen(bool fs) = 0; - - /** - * @brief 设置垂直同步 - */ - virtual void setVSync(bool vsync) = 0; - - /** - * @brief 设置窗口可见性 - */ - virtual void setVisible(bool visible) = 0; - - /** - * @brief 获取窗口宽度 - */ - virtual int width() const = 0; - - /** - * @brief 获取窗口高度 - */ - virtual int height() const = 0; - - /** - * @brief 获取窗口大小 - */ - virtual Size size() const = 0; - - /** - * @brief 获取窗口位置 - */ - virtual Vec2 pos() const = 0; - - /** - * @brief 是否全屏 - */ - virtual bool fullscreen() const = 0; - - /** - * @brief 是否启用垂直同步 - */ - virtual bool vsync() const = 0; - - /** - * @brief 窗口是否获得焦点 - */ - virtual bool focused() const = 0; - - /** - * @brief 窗口是否最小化 - */ - virtual bool minimized() const = 0; - - /** - * @brief 获取内容缩放X - */ - virtual float scaleX() const = 0; - - /** - * @brief 获取内容缩放Y - */ - virtual float scaleY() const = 0; - - /** - * @brief 设置光标形状 - */ - virtual void setCursor(Cursor cursor) = 0; - - /** - * @brief 显示/隐藏光标 - */ - virtual void showCursor(bool show) = 0; - - /** - * @brief 锁定/解锁光标 - */ - virtual void lockCursor(bool lock) = 0; - - /** - * @brief 窗口大小改变回调 - */ - using ResizeCb = std::function; - - /** - * @brief 窗口关闭回调 - */ - using CloseCb = std::function; - - /** - * @brief 窗口焦点改变回调 - */ - using FocusCb = std::function; - - /** - * @brief 设置大小改变回调 - */ - virtual void onResize(ResizeCb cb) = 0; - - /** - * @brief 设置关闭回调 - */ - virtual void onClose(CloseCb cb) = 0; - - /** - * @brief 设置焦点改变回调 - */ - virtual void onFocus(FocusCb cb) = 0; - - /** - * @brief 获取原生窗口句柄 - */ - virtual void* native() const = 0; -}; - -} // namespace extra2d diff --git a/Extra2D/include/extra2d/platform/window_module.h b/Extra2D/include/extra2d/platform/window_module.h index f4b7db3..b5407f7 100644 --- a/Extra2D/include/extra2d/platform/window_module.h +++ b/Extra2D/include/extra2d/platform/window_module.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -48,11 +48,11 @@ public: * @brief 获取窗口 * @return 窗口指针 */ - IWindow *win() const { return win_.get(); } + GLFWWindow *win() const { return win_.get(); } private: WindowCfg cfg_; - UniquePtr win_; + UniquePtr win_; bool initialized_ = false; }; diff --git a/Extra2D/src/app/application.cpp b/Extra2D/src/app/application.cpp index 6c1922b..203beff 100644 --- a/Extra2D/src/app/application.cpp +++ b/Extra2D/src/app/application.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -213,7 +213,7 @@ void Application::render() { winMod->win()->swap(); } -IWindow *Application::window() { +GLFWWindow *Application::window() { auto *winMod = get(); return winMod ? winMod->win() : nullptr; } diff --git a/Extra2D/src/graphics/opengl/gl_renderer.cpp b/Extra2D/src/graphics/opengl/gl_renderer.cpp index 6a2ce5b..e5edef0 100644 --- a/Extra2D/src/graphics/opengl/gl_renderer.cpp +++ b/Extra2D/src/graphics/opengl/gl_renderer.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -45,7 +45,7 @@ GLRenderer::~GLRenderer() { shutdown(); } * @param window 窗口指针 * @return 初始化成功返回true,失败返回false */ -bool GLRenderer::init(IWindow *window) { +bool GLRenderer::init(GLFWWindow *window) { window_ = window; // 初始化 OpenGL 上下文(Switch 平台已通过 SDL2 + EGL 初始化,GLContext diff --git a/Extra2D/src/platform/glfw/glfw_window.cpp b/Extra2D/src/platform/glfw/glfw_window.cpp index 63b1b5a..dc4f195 100644 --- a/Extra2D/src/platform/glfw/glfw_window.cpp +++ b/Extra2D/src/platform/glfw/glfw_window.cpp @@ -200,10 +200,6 @@ void GLFWWindow::setVisible(bool visible) { #endif } -int GLFWWindow::width() const { return width_; } - -int GLFWWindow::height() const { return height_; } - Size GLFWWindow::size() const { return Size(static_cast(width_), static_cast(height_)); } @@ -218,18 +214,6 @@ Vec2 GLFWWindow::pos() const { return Vec2(static_cast(x), static_cast(y)); } -bool GLFWWindow::fullscreen() const { return fullscreen_; } - -bool GLFWWindow::vsync() const { return vsync_; } - -bool GLFWWindow::focused() const { return focused_; } - -bool GLFWWindow::minimized() const { return minimized_; } - -float GLFWWindow::scaleX() const { return scaleX_; } - -float GLFWWindow::scaleY() const { return scaleY_; } - void GLFWWindow::setCursor(Cursor cursor) { #ifndef __SWITCH__ if (!glfwWindow_) @@ -299,12 +283,6 @@ void GLFWWindow::lockCursor(bool lock) { #endif } -void GLFWWindow::onResize(ResizeCb cb) { resizeCb_ = cb; } - -void GLFWWindow::onClose(CloseCb cb) { closeCb_ = cb; } - -void GLFWWindow::onFocus(FocusCb cb) { focusCb_ = cb; } - void *GLFWWindow::native() const { return glfwWindow_; } bool GLFWWindow::initGLFW() { diff --git a/Extra2D/src/scene/transition_box_scene.cpp b/Extra2D/src/scene/transition_box_scene.cpp index e4e0fe0..53f31fa 100644 --- a/Extra2D/src/scene/transition_box_scene.cpp +++ b/Extra2D/src/scene/transition_box_scene.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include diff --git a/Extra2D/src/scene/transition_fade_scene.cpp b/Extra2D/src/scene/transition_fade_scene.cpp index ef26fec..24e6bf6 100644 --- a/Extra2D/src/scene/transition_fade_scene.cpp +++ b/Extra2D/src/scene/transition_fade_scene.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include