[Supertux-Commit] r5511 - in trunk/supertux/src: . video

grumbel at millhouse.dreamhost.com grumbel at millhouse.dreamhost.com
Fri May 23 05:21:52 PDT 2008


Author: grumbel
Date: 2008-05-23 05:21:52 -0700 (Fri, 23 May 2008)
New Revision: 5511

Modified:
   trunk/supertux/src/gameconfig.cpp
   trunk/supertux/src/gameconfig.hpp
   trunk/supertux/src/options_menu.cpp
   trunk/supertux/src/video/gl_renderer.cpp
Log:
Some more aspect ratio stuff

Modified: trunk/supertux/src/gameconfig.cpp
===================================================================
--- trunk/supertux/src/gameconfig.cpp	2008-05-22 22:49:09 UTC (rev 5510)
+++ trunk/supertux/src/gameconfig.cpp	2008-05-23 12:21:52 UTC (rev 5511)
@@ -53,7 +53,7 @@
   fullscreen_height = 600;
 
   magnification = 1.0f;
-  fill_screen = false;
+  stretch_to_window = false;
 
   aspect_width  = 4;
   aspect_height = 3;
@@ -98,7 +98,7 @@
     config_video_lisp->get("aspect_width",  aspect_width);
     config_video_lisp->get("aspect_height", aspect_height);
 
-    config_video_lisp->get("fill_screen", fill_screen);
+    config_video_lisp->get("stretch_to_window", stretch_to_window);
   }
 
   const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
@@ -143,7 +143,7 @@
   writer.write_int("aspect_width",  aspect_width);
   writer.write_int("aspect_height", aspect_height);
 
-  writer.write_bool("fill_screen", fill_screen);
+  writer.write_bool("stretch_to_window", stretch_to_window);
 
   writer.end_list("video");
 

Modified: trunk/supertux/src/gameconfig.hpp
===================================================================
--- trunk/supertux/src/gameconfig.hpp	2008-05-22 22:49:09 UTC (rev 5510)
+++ trunk/supertux/src/gameconfig.hpp	2008-05-23 12:21:52 UTC (rev 5511)
@@ -49,7 +49,7 @@
   int aspect_height;
   
   float magnification;
-  bool  fill_screen;
+  bool  stretch_to_window;
 
   bool use_fullscreen;
   VideoSystem video;

Modified: trunk/supertux/src/options_menu.cpp
===================================================================
--- trunk/supertux/src/options_menu.cpp	2008-05-22 22:49:09 UTC (rev 5510)
+++ trunk/supertux/src/options_menu.cpp	2008-05-23 12:21:52 UTC (rev 5511)
@@ -36,7 +36,7 @@
   MNID_FULLSCREEN_RESOLUTION,
   MNID_MAGNIFICATION,
   MNID_ASPECTRATIO,
-  MNID_FILL_SCREEN,
+  MNID_STRETCH_TO_WINDOW,
   MNID_PROFILES,
   MNID_SOUND,
   MNID_MUSIC
@@ -137,6 +137,7 @@
 
   // These values go from screen:640/projection:1600 to
   // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600)
+  magnification->list.push_back("auto");
   magnification->list.push_back("40%");
   magnification->list.push_back("50%");
   magnification->list.push_back("62.5%");
@@ -147,8 +148,8 @@
   magnification->list.push_back("200%");
   magnification->list.push_back("250%");
 
-  add_toggle(MNID_FILL_SCREEN, _("Fill Screen"), config->fill_screen)
-    ->set_help(_("Stretch SuperTux to fill the screen instead of adding black bars"));
+  add_toggle(MNID_STRETCH_TO_WINDOW, _("Stretch to Window"), config->stretch_to_window)
+    ->set_help(_("Use the fullscreen resolution and stretch SuperTux to fill the given window"));
 
   SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
 
@@ -183,9 +184,9 @@
   MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
   aspect->set_help(_("Adjust the aspect ratio"));
   
-  aspect->list.push_back("screen");
-  aspect->list.push_back("4:3");
+  aspect->list.push_back("auto");
   aspect->list.push_back("5:4");
+  aspect->list.push_back("4:3");
   aspect->list.push_back("16:10");
   aspect->list.push_back("16:9");
   aspect->list.push_back("1368:768");
@@ -235,43 +236,38 @@
 OptionsMenu::menu_action(MenuItem* item)
 {
   switch (item->id) {
-    case MNID_FILL_SCREEN:
-      config->fill_screen = options_menu->is_toggled(MNID_FILL_SCREEN);
-      Renderer::instance()->apply_config();
-      Menu::recalc_pos();
-      config->save();
-      break;
-
     case MNID_ASPECTRATIO:
       { 
-        if (item->list[item->selected] == "screen")
+        if (item->list[item->selected] == "auto")
           {
-            // FIXME: Insert magic for 1:1 mapping, desktop_width/desktop_height
+            config->aspect_width  = 0; // Magic values
+            config->aspect_height = 0;
             Renderer::instance()->apply_config();
-            Menu::recalc_pos();            
+            Menu::recalc_pos();
           }
+        else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2)
+          {
+            Renderer::instance()->apply_config();
+            Menu::recalc_pos();
+          }
         else
-          {           
-            if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2)
-              {
-                Renderer::instance()->apply_config();
-                Menu::recalc_pos();
-              }
-            else
-              {
-                assert(!"This must not be reached");
-              }
+          {
+            assert(!"This must not be reached");
           }
       }
       break;
 
     case MNID_MAGNIFICATION:
-      if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1)
+      if (item->list[item->selected] == "auto")
         {
+          config->magnification = 0.0f; // Magic value 
+        }
+      else if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1)
+        {
           config->magnification /= 100.0f;
-          Renderer::instance()->apply_config();
-          Menu::recalc_pos();
         }
+      Renderer::instance()->apply_config();
+      Menu::recalc_pos();
       break;
 
     case MNID_FULLSCREEN_RESOLUTION:

Modified: trunk/supertux/src/video/gl_renderer.cpp
===================================================================
--- trunk/supertux/src/video/gl_renderer.cpp	2008-05-22 22:49:09 UTC (rev 5510)
+++ trunk/supertux/src/video/gl_renderer.cpp	2008-05-23 12:21:52 UTC (rev 5511)
@@ -562,7 +562,11 @@
     }
 
   int w,h;
-  float target_aspect  = float(config->aspect_width) / float(config->aspect_height);
+  float target_aspect = float(desktop_width) / desktop_height;
+  
+  if (config->aspect_width != 0 && config->aspect_height != 0)
+    target_aspect = float(config->aspect_width) / float(config->aspect_height);
+
   float desktop_aspect = 4.0f / 3.0f; // random default fallback guess
   
   if (desktop_width != -1 && desktop_height != -1)
@@ -594,17 +598,14 @@
       SCREEN_HEIGHT = static_cast<int>(h  * (target_aspect / desktop_aspect));
     }
 
-  SCREEN_WIDTH  = static_cast<int>(SCREEN_WIDTH  / config->magnification);
-  SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT / config->magnification);
-
   int max_width  = 1600; // FIXME: Maybe 1920 is ok too
   int max_height = 1200;
 
-  if (config->fill_screen)
+  if (config->magnification == 0.0f) // Magic value that means 'minfill'
     {
       // This scales SCREEN_WIDTH/SCREEN_HEIGHT so that they never excede
       // max_width/max_height
-      if (SCREEN_WIDTH > max_width || SCREEN_HEIGHT > max_height)
+      if (config->stretch_to_window || (SCREEN_WIDTH > max_width || SCREEN_HEIGHT > max_height))
         {
           float scale1  = float(max_width)/SCREEN_WIDTH;
           float scale2  = float(max_height)/SCREEN_HEIGHT;
@@ -617,6 +618,9 @@
     }
   else
     {
+      SCREEN_WIDTH  = static_cast<int>(SCREEN_WIDTH  / config->magnification);
+      SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT / config->magnification);
+
       // This works by adding black borders around the screen to limit
       // SCREEN_WIDTH/SCREEN_HEIGHT to max_width/max_height
       int nw = w;
@@ -642,10 +646,17 @@
                   << (h-nh)/2 << " "
                   << nw << "x" << nh << std::endl;
 
-      glViewport(std::max(0, (w-nw)/2), 
-                 std::max(0, (h-nh)/2), 
-                 std::min(nw, w),
-                 std::min(nh, h));
+      if (config->stretch_to_window)
+        {
+          glViewport(0, 0, w, h);
+        }
+      else
+        {
+          glViewport(std::max(0, (w-nw)/2), 
+                     std::max(0, (h-nh)/2), 
+                     std::min(nw, w),
+                     std::min(nh, h));
+        }
     }
 
   if (0)




More information about the Supertux-Commit mailing list