From c1135988451f373d097333b692e02ba1cdb3a142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Feb 2013 23:27:45 +0100 Subject: [PATCH] Platform: added Sdl2Application::exit(). --- src/Platform/Sdl2Application.cpp | 12 ++++++------ src/Platform/Sdl2Application.h | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index b423b5519..41a1b3876 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -40,7 +40,7 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { } -Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vector2i& size): _redraw(true) { +Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vector2i& size): flags(Flag::Redraw) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; std::exit(1); @@ -83,7 +83,7 @@ Sdl2Application::~Sdl2Application() { } int Sdl2Application::exec() { - for(;;) { + while(!(flags & Flag::Exit)) { SDL_Event event; while(SDL_PollEvent(&event)) { @@ -92,10 +92,10 @@ int Sdl2Application::exec() { switch(event.window.event) { case SDL_WINDOWEVENT_RESIZED: viewportEvent({event.window.data1, event.window.data2}); - _redraw = true; + flags |= Flag::Redraw; break; case SDL_WINDOWEVENT_EXPOSED: - _redraw = true; + flags |= Flag::Redraw; break; } break; @@ -127,8 +127,8 @@ int Sdl2Application::exec() { } } - if(_redraw) { - _redraw = false; + if(flags & Flag::Redraw) { + flags &= ~Flag::Redraw; drawEvent(); } else Corrade::Utility::sleep(5); } diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 00aad8e99..281f00231 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -80,6 +80,9 @@ class Sdl2Application { */ int exec(); + /** @brief Exit application main loop */ + inline void exit() { flags |= Flag::Exit; } + protected: /** @{ @name Drawing functions */ @@ -94,7 +97,7 @@ class Sdl2Application { inline void swapBuffers() { SDL_GL_SwapWindow(window); } /** @copydoc GlutApplication::redraw() */ - inline void redraw() { _redraw = true; } + inline void redraw() { flags |= Flag::Redraw; } /*@}*/ @@ -146,14 +149,24 @@ class Sdl2Application { /*@}*/ private: + enum class Flag: std::uint8_t { + Redraw = 1 << 0, + Exit = 1 << 1 + }; + + typedef Corrade::Containers::EnumSet Flags; + CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) + SDL_Window* window; SDL_GLContext context; Context* c; - bool _redraw; + Flags flags; }; +CORRADE_ENUMSET_OPERATORS(Sdl2Application::Flags) + /** @brief Base for input events