From 6db481c846c8dbbe7afb07dbaf2d2032440bcc79 Mon Sep 17 00:00:00 2001 From: sommer Date: Mon, 10 Jan 2011 18:51:20 +0000 Subject: [PATCH] =?utf8?q?committed=20stpatch20110110.diff=20by=20Jonas=20?= =?utf8?q?K=C3=BCmmerlin?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Viewport is restored properly after drawing lightmap (was set to 0,0,SCREEN_WIDTH,SCREEN_HEIGHT before) * Menu size calculation now minds size of current selected string in STRINGSELECT items -> overlapping bugs disappear * Magnification is saved in configuration file * default magnification is auto (maybe talk about that again) * auto magnification does now downscaling on resolutions smaller than 640x480 * magnification, aspect ratio and fullscreen resolution controls in options menu now display the current value git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6660 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/gui/menu.cpp | 3 +++ src/supertux/gameconfig.cpp | 6 ++++- src/supertux/menu/options_menu.cpp | 47 ++++++++++++++++++++++++++++++++++++++ src/video/gl/gl_lightmap.cpp | 18 ++++++++------- src/video/gl/gl_lightmap.hpp | 1 + src/video/gl/gl_renderer.cpp | 12 +++++++++- 6 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index b889ce777..6ce60ac74 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -624,6 +624,9 @@ Menu::get_width() const Resources::big_font->get_text_width(items[i]->input) + 16; if(items[i]->kind == MN_TOGGLE) w += 32; + if (items[i]->kind == MN_STRINGSELECT) + w += font->get_text_width(items[i]->list[items[i]->selected]) + 32; + if(w > menu_width) menu_width = w; diff --git a/src/supertux/gameconfig.cpp b/src/supertux/gameconfig.cpp index add3908f8..235198c67 100644 --- a/src/supertux/gameconfig.cpp +++ b/src/supertux/gameconfig.cpp @@ -30,7 +30,7 @@ Config::Config() : fullscreen_size(800, 600), window_size(800, 600), aspect_size(0, 0), // auto detect - magnification(1.0f), + magnification(0.0f), use_fullscreen(false), video(VideoSystem::AUTO_VIDEO), try_vsync(true), @@ -81,6 +81,8 @@ Config::load() config_video_lisp->get("aspect_width", aspect_size.width); config_video_lisp->get("aspect_height", aspect_size.height); + + config_video_lisp->get("magnification", magnification); } const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio"); @@ -124,6 +126,8 @@ Config::save() writer.write("aspect_width", aspect_size.width); writer.write("aspect_height", aspect_size.height); + + writer.write("magnification", magnification); writer.end_list("video"); diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index f01b40264..3948b0a09 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -81,6 +81,30 @@ OptionsMenu::OptionsMenu() : magnification->list.push_back("160%"); magnification->list.push_back("200%"); magnification->list.push_back("250%"); + if (g_config->magnification != 0.0f) //auto + { + std::ostringstream out; + out << (g_config->magnification*100) << "%"; + std::string magn = out.str(); + size_t count = 0; + for (std::vector::iterator i = magnification->list.begin(); i != magnification->list.end(); ++i) + { + if (*i == magn) + { + magnification->selected = count; + magn.clear(); + break; + } + + ++count; + } + if (!magn.empty()) //magnification not in our list but accept anyway + { + magnification->selected = magnification->list.size(); + magnification->list.push_back(magn); + } + } + SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL); @@ -115,6 +139,26 @@ OptionsMenu::OptionsMenu() : // lowest, so reverse them std::sort(fullscreen_res->list.begin(), fullscreen_res->list.end(), StringUtil::numeric_less); } + + std::ostringstream out; + out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height; + std::string fllscrn_sz = out.str(); + size_t cnt = 0; + for (std::vector::iterator i = fullscreen_res->list.begin(); i != fullscreen_res->list.end(); ++i) + { + if (*i == fllscrn_sz) + { + fllscrn_sz.clear(); + fullscreen_res->selected = cnt; + break; + } + ++cnt; + } + if (!fllscrn_sz.empty()) + { + fullscreen_res->selected = fullscreen_res->list.size(); + fullscreen_res->list.push_back(fllscrn_sz); + } MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio")); aspect->set_help(_("Adjust the aspect ratio")); @@ -131,13 +175,16 @@ OptionsMenu::OptionsMenu() : std::ostringstream out; out << g_config->aspect_size.width << ":" << g_config->aspect_size.height; std::string aspect_ratio = out.str(); + size_t cnt = 0; for(std::vector::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i) { if(*i == aspect_ratio) { aspect_ratio.clear(); + aspect->selected = cnt; break; } + ++cnt; } if (!aspect_ratio.empty()) diff --git a/src/video/gl/gl_lightmap.cpp b/src/video/gl/gl_lightmap.cpp index 30df72a64..5722d9217 100644 --- a/src/video/gl/gl_lightmap.cpp +++ b/src/video/gl/gl_lightmap.cpp @@ -51,8 +51,8 @@ GLLightmap::GLLightmap() : { screen = SDL_GetVideoSurface(); - lightmap_width = screen->w / LIGHTMAP_DIV; - lightmap_height = screen->h / LIGHTMAP_DIV; + lightmap_width = SCREEN_WIDTH / LIGHTMAP_DIV; + lightmap_height = SCREEN_HEIGHT / LIGHTMAP_DIV; unsigned int width = next_po2(lightmap_width); unsigned int height = next_po2(lightmap_height); @@ -70,7 +70,9 @@ GLLightmap::~GLLightmap() void GLLightmap::start_draw(const Color &ambient_color) { - glViewport(0, screen->h - lightmap_height, lightmap_width, lightmap_height); + + glGetFloatv(GL_VIEWPORT, old_viewport); //save viewport + glViewport(old_viewport[0], SCREEN_HEIGHT - lightmap_height + old_viewport[1], lightmap_width, lightmap_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); #ifdef GL_VERSION_ES_CM_1_0 @@ -90,9 +92,9 @@ GLLightmap::end_draw() { glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, lightmap->get_handle()); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, screen->h - lightmap_height, lightmap_width, lightmap_height); - - glViewport(0, 0, screen->w, screen->h); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, old_viewport[0], SCREEN_HEIGHT - lightmap_height + old_viewport[1], lightmap_width, lightmap_height); + + glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); #ifdef GL_VERSION_ES_CM_1_0 @@ -267,8 +269,8 @@ GLLightmap::get_light(const DrawingRequest& request) const for( int i = 0; i<3; i++) pixels[i] = 0.0f; //set to black - float posX = request.pos.x * lightmap_width / SCREEN_WIDTH; - float posY = screen->h - request.pos.y * lightmap_height / SCREEN_HEIGHT; + float posX = request.pos.x * lightmap_width / SCREEN_WIDTH + old_viewport[0]; + float posY = SCREEN_HEIGHT + old_viewport[1] - request.pos.y * lightmap_height / SCREEN_HEIGHT; glReadPixels((GLint) posX, (GLint) posY , 1, 1, GL_RGB, GL_FLOAT, pixels); *(getlightrequest->color_ptr) = Color( pixels[0], pixels[1], pixels[2]); } diff --git a/src/video/gl/gl_lightmap.hpp b/src/video/gl/gl_lightmap.hpp index 10ee5465d..af72e422e 100644 --- a/src/video/gl/gl_lightmap.hpp +++ b/src/video/gl/gl_lightmap.hpp @@ -48,6 +48,7 @@ private: int lightmap_height; float lightmap_uv_right; float lightmap_uv_bottom; + GLfloat old_viewport[4]; //holds vieport before redefining in start_draw - returned from glGet private: GLLightmap(const GLLightmap&); diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index 264278885..361f30a51 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -501,11 +501,12 @@ GLRenderer::apply_config() } Size max_size(1280, 800); + Size min_size(640, 480); if (g_config->magnification == 0.0f) // Magic value that means 'minfill' { // This scales SCREEN_WIDTH/SCREEN_HEIGHT so that they never excede - // max_size.width/max_size.height + // max_size.width/max_size.height resp. min_size.width/min_size.height if (SCREEN_WIDTH > max_size.width || SCREEN_HEIGHT > max_size.height) { float scale1 = float(max_size.width)/SCREEN_WIDTH; @@ -513,7 +514,16 @@ GLRenderer::apply_config() float scale = (scale1 < scale2) ? scale1 : scale2; SCREEN_WIDTH = static_cast(SCREEN_WIDTH * scale); SCREEN_HEIGHT = static_cast(SCREEN_HEIGHT * scale); + } + else if (SCREEN_WIDTH < min_size.width || SCREEN_HEIGHT < min_size.height) + { + float scale1 = float(min_size.width)/SCREEN_WIDTH; + float scale2 = float(min_size.height)/SCREEN_HEIGHT; + float scale = (scale1 < scale2) ? scale1 : scale2; + SCREEN_WIDTH = static_cast(SCREEN_WIDTH * scale); + SCREEN_HEIGHT = static_cast(SCREEN_HEIGHT * scale); } + glViewport(0, 0, screen_size.width, screen_size.height); } -- 2.11.0