Browse Source

Platform: added Sdl2Application::exit().

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
c113598845
  1. 12
      src/Platform/Sdl2Application.cpp
  2. 17
      src/Platform/Sdl2Application.h

12
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) { if(SDL_Init(SDL_INIT_VIDEO) < 0) {
Error() << "Cannot initialize SDL."; Error() << "Cannot initialize SDL.";
std::exit(1); std::exit(1);
@ -83,7 +83,7 @@ Sdl2Application::~Sdl2Application() {
} }
int Sdl2Application::exec() { int Sdl2Application::exec() {
for(;;) { while(!(flags & Flag::Exit)) {
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&event)) { while(SDL_PollEvent(&event)) {
@ -92,10 +92,10 @@ int Sdl2Application::exec() {
switch(event.window.event) { switch(event.window.event) {
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
viewportEvent({event.window.data1, event.window.data2}); viewportEvent({event.window.data1, event.window.data2});
_redraw = true; flags |= Flag::Redraw;
break; break;
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
_redraw = true; flags |= Flag::Redraw;
break; break;
} break; } break;
@ -127,8 +127,8 @@ int Sdl2Application::exec() {
} }
} }
if(_redraw) { if(flags & Flag::Redraw) {
_redraw = false; flags &= ~Flag::Redraw;
drawEvent(); drawEvent();
} else Corrade::Utility::sleep(5); } else Corrade::Utility::sleep(5);
} }

17
src/Platform/Sdl2Application.h

@ -80,6 +80,9 @@ class Sdl2Application {
*/ */
int exec(); int exec();
/** @brief Exit application main loop */
inline void exit() { flags |= Flag::Exit; }
protected: protected:
/** @{ @name Drawing functions */ /** @{ @name Drawing functions */
@ -94,7 +97,7 @@ class Sdl2Application {
inline void swapBuffers() { SDL_GL_SwapWindow(window); } inline void swapBuffers() { SDL_GL_SwapWindow(window); }
/** @copydoc GlutApplication::redraw() */ /** @copydoc GlutApplication::redraw() */
inline void redraw() { _redraw = true; } inline void redraw() { flags |= Flag::Redraw; }
/*@}*/ /*@}*/
@ -146,14 +149,24 @@ class Sdl2Application {
/*@}*/ /*@}*/
private: private:
enum class Flag: std::uint8_t {
Redraw = 1 << 0,
Exit = 1 << 1
};
typedef Corrade::Containers::EnumSet<Flag, unsigned int> Flags;
CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)
SDL_Window* window; SDL_Window* window;
SDL_GLContext context; SDL_GLContext context;
Context* c; Context* c;
bool _redraw; Flags flags;
}; };
CORRADE_ENUMSET_OPERATORS(Sdl2Application::Flags)
/** /**
@brief Base for input events @brief Base for input events

Loading…
Cancel
Save