Some more aspect ratio stuff
authorIngo Ruhnke <grumbel@gmx.de>
Fri, 23 May 2008 12:52:01 +0000 (12:52 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Fri, 23 May 2008 12:52:01 +0000 (12:52 +0000)
SVN-Revision: 5512

src/gameconfig.cpp
src/gameconfig.hpp
src/main.cpp
src/options_menu.cpp
src/video/gl_renderer.cpp

index 8d0dd80..728b2b8 100644 (file)
@@ -53,7 +53,6 @@ Config::Config()
   fullscreen_height = 600;
 
   magnification = 1.0f;
-  stretch_to_window = false;
 
   aspect_width  = 4;
   aspect_height = 3;
@@ -97,8 +96,6 @@ Config::load()
 
     config_video_lisp->get("aspect_width",  aspect_width);
     config_video_lisp->get("aspect_height", aspect_height);
-
-    config_video_lisp->get("stretch_to_window", stretch_to_window);
   }
 
   const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
@@ -143,8 +140,6 @@ Config::save()
   writer.write_int("aspect_width",  aspect_width);
   writer.write_int("aspect_height", aspect_height);
 
-  writer.write_bool("stretch_to_window", stretch_to_window);
-
   writer.end_list("video");
 
   writer.start_list("audio");
index 222823e..bdf8725 100644 (file)
@@ -49,7 +49,6 @@ public:
   int aspect_height;
   
   float magnification;
-  bool  stretch_to_window;
 
   bool use_fullscreen;
   VideoSystem video;
index c355c81..6acd08c 100644 (file)
@@ -313,24 +313,32 @@ static bool parse_commandline(int argc, char** argv)
         } 
       else 
         {
-          int aspect_width  = 4;
-          int aspect_height = 3;
-          if(sscanf(argv[i], "%d:%d", &aspect_width, &aspect_height) != 2) {
-            print_usage(argv[0]);
-            throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT");
-          } else {
-            float aspect_ratio = static_cast<double>(config->aspect_width) /
-              static_cast<double>(config->aspect_height);
-
-            // use aspect ratio to calculate logical resolution
-            if (aspect_ratio > 1) {
-              config->aspect_width  = static_cast<int> (600 * aspect_ratio + 0.5);
-              config->aspect_height = 600;
-            } else {
-              config->aspect_width  = 600;
-              config->aspect_height = static_cast<int> (600 * 1/aspect_ratio + 0.5);
+          int aspect_width  = 0;
+          int aspect_height = 0;
+          if (strcmp(argv[i], "auto") == 0)
+            {
+              aspect_width  = 0;
+              aspect_height = 0;
+            }
+          else if (sscanf(argv[i], "%d:%d", &aspect_width, &aspect_height) != 2) 
+            {
+              print_usage(argv[0]);
+              throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT or auto");
+            }
+          else 
+            {
+              float aspect_ratio = static_cast<double>(config->aspect_width) /
+                static_cast<double>(config->aspect_height);
+
+              // use aspect ratio to calculate logical resolution
+              if (aspect_ratio > 1) {
+                config->aspect_width  = static_cast<int> (600 * aspect_ratio + 0.5);
+                config->aspect_height = 600;
+              } else {
+                config->aspect_width  = 600;
+                config->aspect_height = static_cast<int> (600 * 1/aspect_ratio + 0.5);
+              }
             }
-          }
         }
     } else if(arg == "--show-fps") {
       config->show_fps = true;
index 0060f30..6a5b364 100644 (file)
@@ -36,7 +36,6 @@ enum OptionsMenuIDs {
   MNID_FULLSCREEN_RESOLUTION,
   MNID_MAGNIFICATION,
   MNID_ASPECTRATIO,
-  MNID_STRETCH_TO_WINDOW,
   MNID_PROFILES,
   MNID_SOUND,
   MNID_MUSIC
@@ -148,9 +147,6 @@ OptionsMenu::OptionsMenu()
   magnification->list.push_back("200%");
   magnification->list.push_back("250%");
 
-  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);
 
   if (modes == (SDL_Rect **)0) 
@@ -191,22 +187,25 @@ OptionsMenu::OptionsMenu()
   aspect->list.push_back("16:9");
   aspect->list.push_back("1368:768");
 
-  std::ostringstream out;
-  out << config->aspect_width << ":" << config->aspect_height;
-  std::string aspect_ratio = out.str();
-  for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
+  if (config->aspect_width != 0 && config->aspect_height != 0)
     {
-      if(*i == aspect_ratio)
+      std::ostringstream out;
+      out << config->aspect_width << ":" << config->aspect_height;
+      std::string aspect_ratio = out.str();
+      for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
         {
-          aspect_ratio.clear();
-          break;
+          if(*i == aspect_ratio)
+            {
+              aspect_ratio.clear();
+              break;
+            }
         }
-    }
 
-  if (!aspect_ratio.empty())
-    {
-      aspect->selected = aspect->list.size();
-      aspect->list.push_back(aspect_ratio);
+      if (!aspect_ratio.empty())
+        {
+          aspect->selected = aspect->list.size();
+          aspect->list.push_back(aspect_ratio);
+        }
     }
   
   if (sound_manager->is_audio_enabled()) {
index 86ef0c1..a2552b6 100644 (file)
@@ -605,7 +605,7 @@ Renderer::apply_config()
     {
       // This scales SCREEN_WIDTH/SCREEN_HEIGHT so that they never excede
       // max_width/max_height
-      if (config->stretch_to_window || (SCREEN_WIDTH > max_width || SCREEN_HEIGHT > max_height))
+      if (SCREEN_WIDTH > max_width || SCREEN_HEIGHT > max_height)
         {
           float scale1  = float(max_width)/SCREEN_WIDTH;
           float scale2  = float(max_height)/SCREEN_HEIGHT;
@@ -646,17 +646,10 @@ Renderer::apply_config()
                   << (h-nh)/2 << " "
                   << nw << "x" << nh << std::endl;
 
-      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));
-        }
+      glViewport(std::max(0, (w-nw)/2), 
+                 std::max(0, (h-nh)/2), 
+                 std::min(nw, w),
+                 std::min(nh, h));
     }
 
   if (0)