Browse Source

GlfwApplication: add mainLoopIteration similar to Sdl2Application

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

19
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[] {

12
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

Loading…
Cancel
Save