Pause the game when window loses focus, fixes #513
[supertux.git] / src / supertux / screen_manager.cpp
index a2d2beb..decc603 100644 (file)
@@ -27,6 +27,7 @@
 #include "supertux/console.hpp"
 #include "supertux/constants.hpp"
 #include "supertux/gameconfig.hpp"
+#include "supertux/game_session.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/main.hpp"
 #include "supertux/menu/menu_storage.hpp"
@@ -128,7 +129,6 @@ ScreenManager::draw(DrawingContext& context)
   assert(!m_screen_stack.empty());
 
   static Uint32 fps_ticks = SDL_GetTicks();
-  static int frame_count = 0;
 
   m_screen_stack.back()->draw(context);
   m_menu_manager->draw(context);
@@ -156,6 +156,7 @@ ScreenManager::draw(DrawingContext& context)
   /* Calculate frames per second */
   if (g_config->show_fps)
   {
+    static int frame_count = 0;
     ++frame_count;
 
     if (SDL_GetTicks() - fps_ticks >= 500)
@@ -209,10 +210,16 @@ ScreenManager::process_events()
         switch(event.window.event)
         {
           case SDL_WINDOWEVENT_RESIZED:
-            VideoSystem::current()->get_renderer().resize(event.window.data1,
-                                                          event.window.data2);
+            VideoSystem::current()->resize(event.window.data1,
+                                           event.window.data2);
             m_menu_manager->on_window_resize();
             break;
+
+          case SDL_WINDOWEVENT_FOCUS_LOST:
+            if(GameSession::current() != NULL) {
+              GameSession::current()->toggle_pause();
+            }
+            break;
         }
         break;
 
@@ -224,7 +231,7 @@ ScreenManager::process_events()
         else if (event.key.keysym.sym == SDLK_F11)
         {
           g_config->use_fullscreen = !g_config->use_fullscreen;
-          VideoSystem::current()->get_renderer().apply_config();
+          VideoSystem::current()->apply_config();
           m_menu_manager->on_window_resize();
         }
         else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||