From: Ingo Ruhnke Date: Thu, 15 May 2008 04:00:03 +0000 (+0000) Subject: Some more messing around with aspect-ratio, window resize and stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=20b1c27dacf592c4f82fa8772d135ca9b7375d45;p=supertux.git Some more messing around with aspect-ratio, window resize and stuff SVN-Revision: 5479 --- diff --git a/src/gameconfig.cpp b/src/gameconfig.cpp index d3c589678..728b2b838 100644 --- a/src/gameconfig.cpp +++ b/src/gameconfig.cpp @@ -52,9 +52,7 @@ Config::Config() 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::load() 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 @@ Config::save() 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); diff --git a/src/gameconfig.hpp b/src/gameconfig.hpp index 6c3df206d..bdf8725eb 100644 --- a/src/gameconfig.hpp +++ b/src/gameconfig.hpp @@ -44,16 +44,11 @@ public: 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; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index dda904861..3db37460e 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -161,6 +161,19 @@ Menu::set_current(Menu* menu) // 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::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) diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index 7c6605cb9..6eea51d03 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -103,6 +103,8 @@ public: static void push_current(Menu* pmenu); + static void recalc_pos(); + /** Return the current active menu or NULL if none is active */ static Menu* current() { diff --git a/src/main.cpp b/src/main.cpp index c05f57992..0b269b7ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -275,10 +275,6 @@ static bool parse_commandline(int argc, char** argv) 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 @@ static bool parse_commandline(int argc, char** argv) } else { - config->projection_width = width; - config->projection_height = height; - config->window_width = width; config->window_height = height; @@ -419,9 +412,9 @@ void init_video() } #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 @@ void init_video() 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() diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 6ea17aaee..1f341508e 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -196,6 +196,7 @@ MainLoop::process_events() case SDL_VIDEORESIZE: Renderer::instance()->resize(event.resize.w, event.resize.h); + Menu::recalc_pos(); break; case SDL_KEYDOWN: diff --git a/src/options_menu.cpp b/src/options_menu.cpp index 0847417bf..7c91e4a73 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -122,34 +122,52 @@ OptionsMenu::OptionsMenu() 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 @@ OptionsMenu::menu_action(MenuItem* item) { 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; diff --git a/src/video/gl_renderer.cpp b/src/video/gl_renderer.cpp index 3632471ad..7683774b6 100644 --- a/src/video/gl_renderer.cpp +++ b/src/video/gl_renderer.cpp @@ -520,7 +520,13 @@ Renderer::resize(int w, int h) 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 @@ Renderer::apply_config() 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,14 +560,29 @@ Renderer::apply_config() 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; + + 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; - // 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); + glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity();