From: Ingo Ruhnke Date: Thu, 15 May 2008 06:33:38 +0000 (+0000) Subject: Switched magnification to percentage, added black-border as alternative to scale X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6b0c80bde84af0bf9323320d99f2fccd7c9eeedd;p=supertux.git Switched magnification to percentage, added black-border as alternative to scale SVN-Revision: 5480 --- diff --git a/src/options_menu.cpp b/src/options_menu.cpp index 7c91e4a73..d94402ef3 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -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(); } diff --git a/src/video/gl_renderer.cpp b/src/video/gl_renderer.cpp index 7683774b6..79c6a6c39 100644 --- a/src/video/gl_renderer.cpp +++ b/src/video/gl_renderer.cpp @@ -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();