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) {
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);
}

17
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<Flag, unsigned int> 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

Loading…
Cancel
Save