From 756c1242ad87fc749923ccb5dccdd0de1adffae9 Mon Sep 17 00:00:00 2001 From: Konstantinos Chatzilygeroudis Date: Thu, 7 Nov 2019 13:17:51 +0100 Subject: [PATCH] GlfwApplication: add mainLoopIteration similar to Sdl2Application --- src/Magnum/Platform/GlfwApplication.cpp | 19 ++++++++++++------- src/Magnum/Platform/GlfwApplication.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index bb566f15e..bc73a5e23 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -603,16 +603,21 @@ void GlfwApplication::setSwapInterval(const Int interval) { int GlfwApplication::exec() { CORRADE_ASSERT(_window, "Platform::GlfwApplication::exec(): no window opened", {}); - while(!glfwWindowShouldClose(_window)) { - if(_flags & Flag::Redraw) { - _flags &= ~Flag::Redraw; - drawEvent(); - } - glfwPollEvents(); - } + while(mainLoopIteration()) {} + return _exitCode; } +bool GlfwApplication::mainLoopIteration() { + if(_flags & Flag::Redraw) { + _flags &= ~Flag::Redraw; + drawEvent(); + } + glfwPollEvents(); + + return !glfwWindowShouldClose(_window); +} + namespace { constexpr Int CursorMap[] { diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 0d0d9135a..fcef716a1 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -238,6 +238,18 @@ class GlfwApplication { */ int exec(); + /** + * @brief Run one iteration of application main loop + * @return @cpp false @ce if @ref exit() was called and the application + * should exit, @cpp true @ce otherwise + * + * Called internally from @ref exec(). If you want to have better + * control over how the main loop behaves, you can call this function + * yourself from your own `main()` function instead of it being called + * automatically from @ref exec(). + */ + bool mainLoopIteration(); + /** * @brief Exit application main loop * @param exitCode The exit code the application should return