Browse Source

GlfwApplication: add mainLoopIteration similar to Sdl2Application

pull/387/head
Konstantinos Chatzilygeroudis 7 years ago
parent
commit
756c1242ad
  1. 11
      src/Magnum/Platform/GlfwApplication.cpp
  2. 12
      src/Magnum/Platform/GlfwApplication.h

11
src/Magnum/Platform/GlfwApplication.cpp

@ -603,14 +603,19 @@ void GlfwApplication::setSwapInterval(const Int interval) {
int GlfwApplication::exec() { int GlfwApplication::exec() {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::exec(): no window opened", {}); CORRADE_ASSERT(_window, "Platform::GlfwApplication::exec(): no window opened", {});
while(!glfwWindowShouldClose(_window)) { while(mainLoopIteration()) {}
return _exitCode;
}
bool GlfwApplication::mainLoopIteration() {
if(_flags & Flag::Redraw) { if(_flags & Flag::Redraw) {
_flags &= ~Flag::Redraw; _flags &= ~Flag::Redraw;
drawEvent(); drawEvent();
} }
glfwPollEvents(); glfwPollEvents();
}
return _exitCode; return !glfwWindowShouldClose(_window);
} }
namespace { namespace {

12
src/Magnum/Platform/GlfwApplication.h

@ -238,6 +238,18 @@ class GlfwApplication {
*/ */
int exec(); 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 * @brief Exit application main loop
* @param exitCode The exit code the application should return * @param exitCode The exit code the application should return

Loading…
Cancel
Save