From: Ingo Ruhnke Date: Fri, 23 May 2008 12:52:01 +0000 (+0000) Subject: Some more aspect ratio stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ad8009a7af49684d472c9aede493c6306e3daca0;p=supertux.git Some more aspect ratio stuff SVN-Revision: 5512 --- diff --git a/src/gameconfig.cpp b/src/gameconfig.cpp index 8d0dd80cd..728b2b838 100644 --- a/src/gameconfig.cpp +++ b/src/gameconfig.cpp @@ -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"); diff --git a/src/gameconfig.hpp b/src/gameconfig.hpp index 222823e04..bdf8725eb 100644 --- a/src/gameconfig.hpp +++ b/src/gameconfig.hpp @@ -49,7 +49,6 @@ public: int aspect_height; float magnification; - bool stretch_to_window; bool use_fullscreen; VideoSystem video; diff --git a/src/main.cpp b/src/main.cpp index c355c811f..6acd08c5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(config->aspect_width) / - static_cast(config->aspect_height); - - // use aspect ratio to calculate logical resolution - if (aspect_ratio > 1) { - config->aspect_width = static_cast (600 * aspect_ratio + 0.5); - config->aspect_height = 600; - } else { - config->aspect_width = 600; - config->aspect_height = static_cast (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(config->aspect_width) / + static_cast(config->aspect_height); + + // use aspect ratio to calculate logical resolution + if (aspect_ratio > 1) { + config->aspect_width = static_cast (600 * aspect_ratio + 0.5); + config->aspect_height = 600; + } else { + config->aspect_width = 600; + config->aspect_height = static_cast (600 * 1/aspect_ratio + 0.5); + } } - } } } else if(arg == "--show-fps") { config->show_fps = true; diff --git a/src/options_menu.cpp b/src/options_menu.cpp index 0060f30c2..6a5b3649e 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -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::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::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()) { diff --git a/src/video/gl_renderer.cpp b/src/video/gl_renderer.cpp index 86ef0c1ca..a2552b6f2 100644 --- a/src/video/gl_renderer.cpp +++ b/src/video/gl_renderer.cpp @@ -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)