From: Ingo Ruhnke Date: Wed, 7 May 2008 11:15:36 +0000 (+0000) Subject: When custom aspect ratio is set, add it to the list in the option menu, also save... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=bc94afa271ad5b59dc1c3e122f75b0354913edf8;p=supertux.git 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 SVN-Revision: 5426 --- diff --git a/src/gameconfig.cpp b/src/gameconfig.cpp index 38250118c..5236ba626 100644 --- a/src/gameconfig.cpp +++ b/src/gameconfig.cpp @@ -47,7 +47,9 @@ Config::Config() 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::load() 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 @@ Config::save() 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"); diff --git a/src/gameconfig.hpp b/src/gameconfig.hpp index bfd5ab956..775e45132 100644 --- a/src/gameconfig.hpp +++ b/src/gameconfig.hpp @@ -42,7 +42,8 @@ public: */ int screenwidth; int screenheight; - float aspect_ratio; + int aspect_width; + int aspect_height; bool use_fullscreen; VideoSystem video; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index c8ee876ad..b0394ac32 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -251,7 +251,7 @@ Menu::Menu() 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; } diff --git a/src/main.cpp b/src/main.cpp index 20ea6131a..c78e7fbab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -289,7 +289,8 @@ static bool parse_commandline(int argc, char** argv) 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 @@ static bool parse_commandline(int argc, char** argv) 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(aspect_width) / - static_cast(aspect_height); } } else if(arg == "--show-fps") { config->show_fps = true; @@ -400,24 +394,9 @@ void init_video() desktop_height = info->current_h; } #endif - - 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(desktop_width) / static_cast(desktop_height); - } else { -*/ - aspect_ratio = 4.0 / 3.0; -/* - } -*/ - } + + double aspect_ratio = static_cast(config->aspect_width) / + static_cast(config->aspect_height); // use aspect ratio to calculate logical resolution if (aspect_ratio > 1) { diff --git a/src/options_menu.cpp b/src/options_menu.cpp index 1bd8e70d0..f1234f8ab 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -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 +#include //for log10() #include "profile_menu.hpp" #include "options_menu.hpp" @@ -123,13 +124,32 @@ OptionsMenu::OptionsMenu() 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::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 @@ OptionsMenu::menu_action(MenuItem* item) 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(aspect_width) / - static_cast(aspect_height); + float aspect_ratio = static_cast(config->aspect_width) / + static_cast(config->aspect_height); - if (config->aspect_ratio > 1) { - SCREEN_WIDTH = static_cast (600 * config->aspect_ratio + 0.5); + if (aspect_ratio > 1) { + SCREEN_WIDTH = static_cast (600 * aspect_ratio + 0.5); SCREEN_HEIGHT = 600; } else { SCREEN_WIDTH = 600; - SCREEN_HEIGHT = static_cast (600 * 1/config->aspect_ratio + 0.5); + SCREEN_HEIGHT = static_cast (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;