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

grumbel at millhouse.dreamhost.com grumbel at millhouse.dreamhost.com
Wed May 14 21:00:05 PDT 2008


Author: grumbel
Date: 2008-05-14 21:00:03 -0700 (Wed, 14 May 2008)
New Revision: 5479

Modified:
   trunk/supertux/src/gameconfig.cpp
   trunk/supertux/src/gameconfig.hpp
   trunk/supertux/src/gui/menu.cpp
   trunk/supertux/src/gui/menu.hpp
   trunk/supertux/src/main.cpp
   trunk/supertux/src/mainloop.cpp
   trunk/supertux/src/options_menu.cpp
   trunk/supertux/src/video/gl_renderer.cpp
Log:
Some more messing around with aspect-ratio, window resize and stuff

Modified: trunk/supertux/src/gameconfig.cpp
===================================================================
--- trunk/supertux/src/gameconfig.cpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/gameconfig.cpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -52,9 +52,7 @@
   fullscreen_width  = 800;
   fullscreen_height = 600;
 
-  projection_width  = 800;
-  projection_height = 600;
-  scale_projection  = true;
+  magnification = 1.0f;
 
   aspect_width  = 4;
   aspect_height = 3;
@@ -96,10 +94,6 @@
     config_video_lisp->get("window_width",  window_width);
     config_video_lisp->get("window_height", window_height);
 
-    config_video_lisp->get("projection_width",  projection_width);
-    config_video_lisp->get("projection_height", projection_height);
-    config_video_lisp->get("scale_projection", scale_projection);
-
     config_video_lisp->get("aspect_width",  aspect_width);
     config_video_lisp->get("aspect_height", aspect_height);
   }
@@ -143,10 +137,6 @@
   writer.write_int("window_width",  window_width);
   writer.write_int("window_height", window_height);
 
-  writer.write_int("projection_width",  projection_width);
-  writer.write_int("projection_height", projection_height);
-  writer.write_bool("scale_projection",  scale_projection);
-
   writer.write_int("aspect_width",  aspect_width);
   writer.write_int("aspect_height", aspect_height);
 

Modified: trunk/supertux/src/gameconfig.hpp
===================================================================
--- trunk/supertux/src/gameconfig.hpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/gameconfig.hpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -44,16 +44,11 @@
   int window_width;
   int window_height;
 
-  // the projection area size before aspectratio is applied
-  int projection_width;
-  int projection_height;
-  
-  // scale the projection area or leave it at 1:1 pixel mapping
-  bool scale_projection;
-
   // the aspect ratio
   int aspect_width;
   int aspect_height;
+  
+  float magnification;
 
   bool use_fullscreen;
   VideoSystem video;

Modified: trunk/supertux/src/gui/menu.cpp
===================================================================
--- trunk/supertux/src/gui/menu.cpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/gui/menu.cpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -161,6 +161,19 @@
   // just to be sure...
   main_controller->reset();
 }
+
+void
+Menu::recalc_pos()
+{
+  if (current_)
+    current_->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
+
+  for(std::vector<Menu*>::iterator i = last_menus.begin(); i != last_menus.end(); ++i)
+    {
+      // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls
+      (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
+    }
+}
 
 MenuItem::MenuItem(MenuItemKind _kind, int _id)
   : kind(_kind) , id(_id)

Modified: trunk/supertux/src/gui/menu.hpp
===================================================================
--- trunk/supertux/src/gui/menu.hpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/gui/menu.hpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -103,6 +103,8 @@
 
   static void push_current(Menu* pmenu);
 
+  static void recalc_pos();
+
   /** Return the current active menu or NULL if none is active */
   static Menu* current()
   {

Modified: trunk/supertux/src/main.cpp
===================================================================
--- trunk/supertux/src/main.cpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/main.cpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -275,10 +275,6 @@
       config->fullscreen_width  = 800;
       config->fullscreen_height = 600;
 
-      config->projection_width  = 800;
-      config->projection_height = 600;
-      config->scale_projection = true;
-
       config->aspect_width  = 4;
       config->aspect_height = 3;
       
@@ -301,9 +297,6 @@
             }
           else
             {
-              config->projection_width  = width;
-              config->projection_height = height;
-
               config->window_width  = width;
               config->window_height = height;
 
@@ -419,9 +412,9 @@
   }
 #endif
   
-  // FIXME: Add aspect handling
-  SCREEN_WIDTH  = config->projection_width;
-  SCREEN_HEIGHT = config->projection_height;
+  // FIXME: Add something here
+  SCREEN_WIDTH  = 800;
+  SCREEN_HEIGHT = 600;
 
   context_pointer->init_renderer();
   screen = SDL_GetVideoSurface();
@@ -448,10 +441,9 @@
   SDL_ShowCursor(0);
 
   log_info << (config->use_fullscreen?"fullscreen ":"window ")
-           << " Window: " << config->window_width << "x" << config->window_height
+           << " Window: "     << config->window_width     << "x" << config->window_height
            << " Fullscreen: " << config->fullscreen_width << "x" << config->fullscreen_height
-           << " Projection: " << config->projection_width << "x" << config->projection_height
-           << " Area: "   << config->aspect_width << "x" << config->aspect_height << std::endl;
+           << " Area: "       << config->aspect_width     << "x" << config->aspect_height << std::endl;
 }
 
 static void init_audio()

Modified: trunk/supertux/src/mainloop.cpp
===================================================================
--- trunk/supertux/src/mainloop.cpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/mainloop.cpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -196,6 +196,7 @@
               
           case SDL_VIDEORESIZE:
             Renderer::instance()->resize(event.resize.w, event.resize.h);
+            Menu::recalc_pos();
             break;
             
           case SDL_KEYDOWN:

Modified: trunk/supertux/src/options_menu.cpp
===================================================================
--- trunk/supertux/src/options_menu.cpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/options_menu.cpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -122,35 +122,53 @@
   add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled)
     ->set_help(_("Display the profile menu when the game is newly started"));
   
-  // FIXME: Implement me: if (get_parent() == main_menu)
   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
     ->set_help(_("Let the game cover the whole screen"));
 
+  MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
+  fullscreen_res->set_help(_("Change the Resolution to be used in Fullscreen Mode, you have to toggle fullscreen mode to let this change take effect"));
+
   MenuItem* maginfication = add_string_select(MNID_MAGINFICATION, _("Maginfication"));
   maginfication->set_help(_("Change the magnification, to small values will result in a black border around the screen"));
 
-  maginfication->list.push_back("-2");
-  maginfication->list.push_back("-1");
-  maginfication->list.push_back("0");
-  maginfication->list.push_back("1");
-  maginfication->list.push_back("2");
+  maginfication->list.push_back("0.5");
+  maginfication->list.push_back("0.625");
+  maginfication->list.push_back("0.8");
+  maginfication->list.push_back("1.0");
+  maginfication->list.push_back("1.25");
+  maginfication->list.push_back("1.6");
+  maginfication->list.push_back("2.0");
 
-  MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
-  fullscreen_res->set_help(_("Change the Resolution to be used in Fullscreen Mode, you have to toggle fullscreen mode to let this change take effect"));
+  SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
 
-  // FIXME: Hardcoded values are evil, these should be queried from the Xorg server
-  fullscreen_res->list.push_back("640x480");
-  fullscreen_res->list.push_back("800x600");
-  fullscreen_res->list.push_back("1024x768");
-  fullscreen_res->list.push_back("1152x864");
-  fullscreen_res->list.push_back("1280x960");
-  fullscreen_res->list.push_back("1280x1024");
-  fullscreen_res->list.push_back("1440x900");
-  fullscreen_res->list.push_back("1680x1050");
-  fullscreen_res->list.push_back("1600x1200");
-  fullscreen_res->list.push_back("1920x1080");
-  fullscreen_res->list.push_back("1920x1200");
+  if (modes == (SDL_Rect **)0) 
+    { // No resolutions at all available, bad
 
+    }
+  else if(modes == (SDL_Rect **)-1) 
+    { // All resolutions sould work, so we fall back to hardcoded defaults
+      fullscreen_res->list.push_back("640x480");
+      fullscreen_res->list.push_back("800x600");
+      fullscreen_res->list.push_back("1024x768");
+      fullscreen_res->list.push_back("1152x864");
+      fullscreen_res->list.push_back("1280x960");
+      fullscreen_res->list.push_back("1280x1024");
+      fullscreen_res->list.push_back("1440x900");
+      fullscreen_res->list.push_back("1680x1050");
+      fullscreen_res->list.push_back("1600x1200");
+      fullscreen_res->list.push_back("1920x1080");
+      fullscreen_res->list.push_back("1920x1200");
+    }
+  else 
+    {
+      for(int i = 0; modes[i]; ++i)
+        {
+          std::ostringstream out;          
+          out << modes[i]->w << "x" << modes[i]->h;
+          fullscreen_res->list.push_back(out.str());
+        }
+    }
+
   MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
   aspect->set_help(_("Adjust the aspect ratio"));
   
@@ -205,18 +223,31 @@
 {
   switch (item->id) {
     case MNID_ASPECTRATIO:
-      { // FIXME: Really crude and ugly here, move to video or so
+      { 
         if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2)
           {
             Renderer::instance()->apply_config();
-
-            // Reposition the menu to be in the center of the screen again
-            // FIXME: We need to relayout the whole menu stack! Not just current
-            set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
+            Menu::recalc_pos();
           }
       }
       break;
 
+    case MNID_MAGINFICATION:
+      if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1)
+        {
+          Renderer::instance()->apply_config();
+          Menu::recalc_pos();
+        }
+      break;
+
+    case MNID_FULLSCREEN_RESOLUTION:
+      if(sscanf(item->list[item->selected].c_str(), "%dx%d", &config->fullscreen_width, &config->fullscreen_height) == 2)
+        {
+          Renderer::instance()->apply_config();
+          Menu::recalc_pos();
+        }      
+      break;
+
     case MNID_FULLSCREEN:
       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
         config->use_fullscreen = !config->use_fullscreen;

Modified: trunk/supertux/src/video/gl_renderer.cpp
===================================================================
--- trunk/supertux/src/video/gl_renderer.cpp	2008-05-15 01:06:44 UTC (rev 5478)
+++ trunk/supertux/src/video/gl_renderer.cpp	2008-05-15 04:00:03 UTC (rev 5479)
@@ -520,7 +520,13 @@
 void
 Renderer::apply_config()
 {    
-  std::cout << "Applying Config: " << config->aspect_width << ":" << config->aspect_height << std::endl;
+  std::cout << "Applying Config:" 
+            << "\n  Desktop: " << desktop_width << "x" << desktop_height
+            << "\n  Window:  " << config->window_width << "x" << config->window_height
+            << "\n  FullRes: " << config->fullscreen_width << "x" << config->fullscreen_height
+            << "\n  Aspect:  " << config->aspect_width << ":" << config->aspect_height
+            << "\n  Magnif:  " << config->magnification
+            << std::endl;
 
   int w,h;
   float target_aspect  = float(config->aspect_width) / float(config->aspect_height);
@@ -543,9 +549,6 @@
       h = config->window_height;
     }
 
-  std::cout 
-    << " -> " << w << "x" << h << " -> " << target_aspect << " " << desktop_aspect << std::endl;
-
   if (target_aspect > 1.0f)
     {
       SCREEN_WIDTH  = w * (target_aspect / desktop_aspect);
@@ -557,15 +560,30 @@
       SCREEN_HEIGHT = h  * (target_aspect / desktop_aspect);
     }
 
-  // Limit must take aspect into account
-  //SCREEN_WIDTH  = std::min(w, 1024);
-  //SCREEN_HEIGHT = std::min(h, 768);
+  SCREEN_WIDTH  *= config->magnification;  
+  SCREEN_HEIGHT *= config->magnification;  
 
-  // Position the Viewport in the center of the window
-  glViewport(std::max(0, (config->window_width  - w)/2),
-             std::max(0, (config->window_height - h)/2),
-             w, h);
+  int max_width  = 1600;
+  int max_height = 1200;
+  
+  // A little wonky
+  if (SCREEN_WIDTH > max_width)
+    {
+      float scale = float(max_width)/SCREEN_WIDTH;
+      SCREEN_WIDTH  *= scale;
+      SCREEN_HEIGHT *= scale;
+    }
+  else if (SCREEN_HEIGHT > max_height)
+    {
+      float scale = float(max_height)/SCREEN_HEIGHT;
+      SCREEN_WIDTH  *= scale;
+      SCREEN_HEIGHT *= scale;
+    }
+  
+  std::cout << " -> " << SCREEN_WIDTH << "x" << SCREEN_HEIGHT << std::endl;
 
+  glViewport(0, 0, w, h);
+
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);    




More information about the Supertux-Commit mailing list