Switched magnification to percentage, added black-border as alternative to scale
authorIngo Ruhnke <grumbel@gmx.de>
Thu, 15 May 2008 06:33:38 +0000 (06:33 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Thu, 15 May 2008 06:33:38 +0000 (06:33 +0000)
SVN-Revision: 5480

src/options_menu.cpp
src/video/gl_renderer.cpp

index 7c91e4a..d94402e 100644 (file)
@@ -129,15 +129,18 @@ OptionsMenu::OptionsMenu()
   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("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");
+  maginfication->set_help(_("Change the magnification of the game area"));
+
+  // These values go from screen:640/projection:1600 to screen:1600/projection:640
+  maginfication->list.push_back("40%");
+  maginfication->list.push_back("50%");
+  maginfication->list.push_back("62.5%");
+  maginfication->list.push_back("80%");
+  maginfication->list.push_back("100%");
+  maginfication->list.push_back("125%");
+  maginfication->list.push_back("160%");
+  maginfication->list.push_back("200%");
+  maginfication->list.push_back("250%");
 
   SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
 
@@ -235,6 +238,7 @@ OptionsMenu::menu_action(MenuItem* item)
     case MNID_MAGINFICATION:
       if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1)
         {
+          config->magnification /= 100.0f;
           Renderer::instance()->apply_config();
           Menu::recalc_pos();
         }
index 7683774..79c6a6c 100644 (file)
@@ -560,29 +560,59 @@ Renderer::apply_config()
       SCREEN_HEIGHT = h  * (target_aspect / desktop_aspect);
     }
 
-  SCREEN_WIDTH  *= config->magnification;  
-  SCREEN_HEIGHT *= config->magnification;  
+  SCREEN_WIDTH  /= config->magnification;  
+  SCREEN_HEIGHT /= config->magnification;  
 
-  int max_width  = 1600;
+  int max_width  = 1600; // FIXME: Maybe 1920 is ok too
   int max_height = 1200;
-  
-  // A little wonky
-  if (SCREEN_WIDTH > max_width)
+
+  if (0)
     {
-      float scale = float(max_width)/SCREEN_WIDTH;
-      SCREEN_WIDTH  *= scale;
-      SCREEN_HEIGHT *= scale;
+      // This scales SCREEN_WIDTH/SCREEN_HEIGHT so that they never excede
+      // max_width/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;
+          float scale = scale1 < scale2 ? scale1 : scale2;
+          SCREEN_WIDTH  *= scale;
+          SCREEN_HEIGHT *= scale;
+        }
+
+      glViewport(0, 0, w, h);
     }
-  else if (SCREEN_HEIGHT > max_height)
+  else
     {
-      float scale = float(max_height)/SCREEN_HEIGHT;
-      SCREEN_WIDTH  *= scale;
-      SCREEN_HEIGHT *= scale;
+      // This works by adding black borders around the screen to limit
+      // SCREEN_WIDTH/SCREEN_HEIGHT to max_width/max_height
+      int nw = w;
+      int nh = h;
+
+      if (SCREEN_WIDTH > max_width)
+        {
+          nw *= float(max_width)/SCREEN_WIDTH;
+          SCREEN_WIDTH = max_width;
+        }
+
+      if (SCREEN_HEIGHT > max_height)
+        {
+          nh *= float(max_height)/SCREEN_HEIGHT;
+          SCREEN_HEIGHT = max_height;
+        }
+
+      glClear(GL_COLOR_BUFFER_BIT);
+
+      std::cout << (w-nw)/2 << " "
+                << (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));
     }
-  
-  std::cout << " -> " << SCREEN_WIDTH << "x" << SCREEN_HEIGHT << std::endl;
 
-  glViewport(0, 0, w, h);
+  std::cout << "  -> " << SCREEN_WIDTH << "x" << SCREEN_HEIGHT << std::endl;
+
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();