[Supertux-Commit] r5426 - in trunk/supertux/src: . gui

grumbel at millhouse.dreamhost.com grumbel at millhouse.dreamhost.com
Wed May 7 04:15:37 PDT 2008


Author: grumbel
Date: 2008-05-07 04:15:36 -0700 (Wed, 07 May 2008)
New Revision: 5426

Modified:
   trunk/supertux/src/gameconfig.cpp
   trunk/supertux/src/gameconfig.hpp
   trunk/supertux/src/gui/menu.cpp
   trunk/supertux/src/main.cpp
   trunk/supertux/src/options_menu.cpp
Log:
When custom aspect ratio is set, add it to the list in the option menu, also save aspect_width/aspect_height instead of aspect_ratio to the config file

Modified: trunk/supertux/src/gameconfig.cpp
===================================================================
--- trunk/supertux/src/gameconfig.cpp	2008-05-06 13:32:47 UTC (rev 5425)
+++ trunk/supertux/src/gameconfig.cpp	2008-05-07 11:15:36 UTC (rev 5426)
@@ -47,7 +47,9 @@
 
   screenwidth = 800;
   screenheight = 600;
-  aspect_ratio = -1;       // autodetect
+  
+  aspect_width  = 4;       // autodetect
+  aspect_height = 3;       // autodetect
 
   enable_script_debugger = false;
 
@@ -81,7 +83,8 @@
     config_video_lisp->get("vsync", try_vsync);
     config_video_lisp->get("width", screenwidth);
     config_video_lisp->get("height", screenheight);
-    config_video_lisp->get("aspect_ratio", aspect_ratio);
+    config_video_lisp->get("aspect_width",  aspect_width);
+    config_video_lisp->get("aspect_height", aspect_height);
   }
 
   const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
@@ -113,7 +116,8 @@
   writer.write_bool("vsync", try_vsync);
   writer.write_int("width", screenwidth);
   writer.write_int("height", screenheight);
-  writer.write_float("aspect_ratio", aspect_ratio);
+  writer.write_float("aspect_width",  aspect_width);
+  writer.write_float("aspect_height", aspect_height);
   writer.end_list("video");
 
   writer.start_list("audio");

Modified: trunk/supertux/src/gameconfig.hpp
===================================================================
--- trunk/supertux/src/gameconfig.hpp	2008-05-06 13:32:47 UTC (rev 5425)
+++ trunk/supertux/src/gameconfig.hpp	2008-05-07 11:15:36 UTC (rev 5426)
@@ -42,7 +42,8 @@
    */
   int screenwidth;
   int screenheight;
-  float aspect_ratio;
+  int aspect_width;
+  int aspect_height;
 
   bool use_fullscreen;
   VideoSystem video;

Modified: trunk/supertux/src/gui/menu.cpp
===================================================================
--- trunk/supertux/src/gui/menu.cpp	2008-05-06 13:32:47 UTC (rev 5425)
+++ trunk/supertux/src/gui/menu.cpp	2008-05-07 11:15:36 UTC (rev 5426)
@@ -251,7 +251,7 @@
 void
 Menu::set_pos(float x, float y, float rw, float rh)
 {
-  pos_x = x + get_width() * rw;
+  pos_x = x + get_width()  * rw;
   pos_y = y + get_height() * rh;
 }
 

Modified: trunk/supertux/src/main.cpp
===================================================================
--- trunk/supertux/src/main.cpp	2008-05-06 13:32:47 UTC (rev 5425)
+++ trunk/supertux/src/main.cpp	2008-05-07 11:15:36 UTC (rev 5426)
@@ -289,7 +289,8 @@
       config->use_fullscreen = true;
     } else if(arg == "--default" || arg == "-d") {
       config->use_fullscreen = false;
-      config->aspect_ratio = -1;
+      config->aspect_width  = -1;
+      config->aspect_height = -1;
       config->screenwidth = 800;
       config->screenheight = 600;
     } else if(arg == "--window" || arg == "-w") {
@@ -308,18 +309,11 @@
       if(i+1 >= argc) {
         print_usage(argv[0]);
         throw std::runtime_error("Need to specify a parameter for aspect switch");
-      }
-      if(strcasecmp(argv[i+1], "auto") == 0) {
-        i++;
-        config->aspect_ratio = -1;
       } else {
-        int aspect_width, aspect_height;
-        if(sscanf(argv[++i], "%d:%d", &aspect_width, &aspect_height) != 2) {
+        if(sscanf(argv[++i], "%d:%d", &config->aspect_width, &config->aspect_height) != 2) {
           print_usage(argv[0]);
           throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT");
         }
-        config->aspect_ratio = static_cast<double>(aspect_width) /
-                               static_cast<double>(aspect_height);
       }
     } else if(arg == "--show-fps") {
       config->show_fps = true;
@@ -400,25 +394,10 @@
     desktop_height = info->current_h;
   }
 #endif
+  
+  double aspect_ratio = static_cast<double>(config->aspect_width) /
+                               static_cast<double>(config->aspect_height);
 
-  double aspect_ratio = config->aspect_ratio;
-
-  // try to guess aspect ratio of monitor if needed
-  if (aspect_ratio <= 0) {
-// TODO: commented out because 
-// 1) it tends to guess wrong if widescreen-monitors don't stretch 800x600 to fit, but just display black borders
-// 2) aspect ratios other than 4:3 are largely untested
-/*
-    if(config->use_fullscreen && desktop_width > 0) {
-      aspect_ratio = static_cast<double>(desktop_width) / static_cast<double>(desktop_height);
-    } else {
-*/
-      aspect_ratio = 4.0 / 3.0;
-/*
-    }
-*/
-  }
-
   // use aspect ratio to calculate logical resolution
   if (aspect_ratio > 1) {
     SCREEN_WIDTH  = static_cast<int> (600 * aspect_ratio + 0.5);

Modified: trunk/supertux/src/options_menu.cpp
===================================================================
--- trunk/supertux/src/options_menu.cpp	2008-05-06 13:32:47 UTC (rev 5425)
+++ trunk/supertux/src/options_menu.cpp	2008-05-07 11:15:36 UTC (rev 5426)
@@ -18,6 +18,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <config.h>
+#include <math.h> //for log10()
 
 #include "profile_menu.hpp"
 #include "options_menu.hpp"
@@ -123,13 +124,32 @@
   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
     ->set_help(_("Let the game cover the whole screen"));
 
-  MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ration"));
+  MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
   aspect->set_help(_("Adjust the aspect ratio"));
+  
   aspect->list.push_back("16:9");
   aspect->list.push_back("16:10");
   aspect->list.push_back("4:3");
   aspect->list.push_back("5:4");
 
+  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(*i == aspect_ratio)
+        {
+          aspect_ratio.clear();
+          break;
+        }
+    }
+
+  if (!aspect_ratio.empty())
+    {
+      aspect->selected = aspect->list.size();
+      aspect->list.push_back(aspect_ratio);
+    }
+  
   if (sound_manager->is_audio_enabled()) {
     add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled)
       ->set_help(_("Disable all sound effects in the game"));
@@ -159,26 +179,26 @@
   switch (item->id) {
     case MNID_ASPECTRATIO:
       { // FIXME: Really crude and ugly here, move to video or so
-        int   aspect_width;
-        int   aspect_height;
-
-        if(sscanf(item->list[item->selected].c_str(), "%d:%d", &aspect_width, &aspect_height) == 2) 
+        if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2) 
           {
-            config->aspect_ratio = static_cast<double>(aspect_width) /
-              static_cast<double>(aspect_height);
+            float aspect_ratio = static_cast<double>(config->aspect_width) /
+              static_cast<double>(config->aspect_height);
 
-            if (config->aspect_ratio > 1) {
-              SCREEN_WIDTH  = static_cast<int> (600 * config->aspect_ratio + 0.5);
+            if (aspect_ratio > 1) {
+              SCREEN_WIDTH  = static_cast<int> (600 * aspect_ratio + 0.5);
               SCREEN_HEIGHT = 600;
             } else {
               SCREEN_WIDTH  = 600;
-              SCREEN_HEIGHT = static_cast<int> (600 * 1/config->aspect_ratio + 0.5);
+              SCREEN_HEIGHT = static_cast<int> (600 * 1/aspect_ratio + 0.5);
             }
 
             glMatrixMode(GL_PROJECTION);
             glLoadIdentity();
             glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
             std::cout << __FILE__ << ":" << __LINE__ << ": change aspect ratio to " << item->list[item->selected] << std::endl;
+
+            // Reposition the menu to be in the center of the screen again
+            set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
           }
       }
       break;




More information about the Supertux-Commit mailing list