From 7acb68d111feb20aaeaf578635765e570a2b50aa Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Sun, 17 Apr 2022 11:18:38 +0100 Subject: [PATCH] poll for window closing events --- fggl/app.cpp | 2 ++ fggl/gfx/window.cpp | 7 +++++++ include/fggl/gfx/window.hpp | 6 +++++- include/fggl/gfx/windowing.hpp | 6 +++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fggl/app.cpp b/fggl/app.cpp index ee3c294..8f3e3d6 100644 --- a/fggl/app.cpp +++ b/fggl/app.cpp @@ -49,6 +49,8 @@ namespace fggl { m_window->frameEnd(); m_modules->onFrameEnd(); + + m_running = m_running && !m_window->wantClose(); } } diff --git a/fggl/gfx/window.cpp b/fggl/gfx/window.cpp index c5097c3..a3cd411 100644 --- a/fggl/gfx/window.cpp +++ b/fggl/gfx/window.cpp @@ -250,9 +250,16 @@ void GlfwWindow::activate() const { assert( m_window != nullptr ); glfwMakeContextCurrent(m_window); } + fggl::math::vec2i GlfwWindow::frameSize() const { assert( m_window != nullptr ); math::vec2i size; glfwGetFramebufferSize(m_window, &size.x, &size.y); return size; } + +bool GlfwWindow::wantClose() const { + assert( m_window != nullptr ); + return glfwWindowShouldClose(m_window) == GLFW_TRUE; +} + diff --git a/include/fggl/gfx/window.hpp b/include/fggl/gfx/window.hpp index 73c8408..3b24e29 100644 --- a/include/fggl/gfx/window.hpp +++ b/include/fggl/gfx/window.hpp @@ -49,7 +49,11 @@ namespace fggl::gfx { GlfwWindow(Window &) = delete; GlfwWindow(Window &&) = delete; - virtual math::vec2i frameSize() const override; + [[nodiscard]] + math::vec2i frameSize() const override; + + [[nodiscard]] + bool wantClose() const override; // window <-> opengl stuff void activate() const override; diff --git a/include/fggl/gfx/windowing.hpp b/include/fggl/gfx/windowing.hpp index 6405553..33e9f07 100644 --- a/include/fggl/gfx/windowing.hpp +++ b/include/fggl/gfx/windowing.hpp @@ -26,10 +26,14 @@ namespace fggl::gfx { m_graphics = std::make_unique<T>(*this); } - // window-related + // window-related getters [[nodiscard]] virtual math::vec2i frameSize() const = 0; + [[nodiscard]] + virtual bool wantClose() const = 0; + + // window callbacks virtual void frameStart() = 0; virtual void frameEnd() = 0; -- GitLab