Browse Source

Platform: improve {Glfw,Sdl2}Application::exit().

Now, it's possible to specify a custom exit code.
pull/332/head
Guillaume Jacquemin 7 years ago
parent
commit
f4b6130ab0
  1. 2
      src/Magnum/Platform/GlfwApplication.cpp
  2. 9
      src/Magnum/Platform/GlfwApplication.h
  3. 5
      src/Magnum/Platform/Sdl2Application.cpp
  4. 5
      src/Magnum/Platform/Sdl2Application.h

2
src/Magnum/Platform/GlfwApplication.cpp

@ -558,7 +558,7 @@ int GlfwApplication::exec() {
} }
glfwPollEvents(); glfwPollEvents();
} }
return 0; return _exitCode;
} }
auto GlfwApplication::MouseMoveEvent::buttons() -> Buttons { auto GlfwApplication::MouseMoveEvent::buttons() -> Buttons {

9
src/Magnum/Platform/GlfwApplication.h

@ -232,9 +232,13 @@ class GlfwApplication {
*/ */
int exec(); int exec();
/** @brief Exit application main loop */ /**
void exit() { * @brief Exit application main loop
* @param exitCode The exit code the application should return
*/
void exit(int exitCode = 0) {
glfwSetWindowShouldClose(_window, true); glfwSetWindowShouldClose(_window, true);
_exitCode = exitCode;
} }
/** /**
@ -547,6 +551,7 @@ class GlfwApplication {
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
Containers::Pointer<Platform::GLContext> _context; Containers::Pointer<Platform::GLContext> _context;
#endif #endif
int _exitCode;
}; };
CORRADE_ENUMSET_OPERATORS(GlfwApplication::Flags) CORRADE_ENUMSET_OPERATORS(GlfwApplication::Flags)

5
src/Magnum/Platform/Sdl2Application.cpp

@ -627,15 +627,16 @@ int Sdl2Application::exec() {
static_cast<Sdl2Application*>(arg)->mainLoopIteration(); static_cast<Sdl2Application*>(arg)->mainLoopIteration();
}, this, 0, true); }, this, 0, true);
#endif #endif
return 0; return _exitCode;
} }
void Sdl2Application::exit() { void Sdl2Application::exit(int exitCode) {
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
_flags |= Flag::Exit; _flags |= Flag::Exit;
#else #else
emscripten_cancel_main_loop(); emscripten_cancel_main_loop();
#endif #endif
_exitCode = exitCode;
} }
void Sdl2Application::mainLoopIteration() { void Sdl2Application::mainLoopIteration() {

5
src/Magnum/Platform/Sdl2Application.h

@ -509,10 +509,11 @@ class Sdl2Application {
/** /**
* @brief Exit application main loop * @brief Exit application main loop
* @param exitCode The exit code the application should return
* *
* Stops main loop started by @ref exec(). * Stops main loop started by @ref exec().
*/ */
void exit(); void exit(int exitCode = 0);
/** /**
* @brief Run one iteration of application main loop * @brief Run one iteration of application main loop
@ -1013,6 +1014,8 @@ class Sdl2Application {
#endif #endif
Flags _flags; Flags _flags;
int _exitCode;
}; };
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL

Loading…
Cancel
Save