From: Wolfgang Becker Date: Fri, 12 Jan 2007 20:10:58 +0000 (+0000) Subject: Widescreen-Patch by Klaus Denker. It includes a new X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b3df78c0b5dcf53a730bd4372aa11e3f5636606f;p=supertux.git Widescreen-Patch by Klaus Denker. It includes a new command-line-parameter "--aspect" or "-a". It defaults to 4:3 but can be changed to any other ratio. SCREEN_WIDTH and SCREEN_HEIGHT are calculated from these aspect-values. SVN-Revision: 4555 --- diff --git a/man/man6/supertux.6 b/man/man6/supertux.6 index 97f33fd13..d42e335e6 100644 --- a/man/man6/supertux.6 +++ b/man/man6/supertux.6 @@ -25,7 +25,10 @@ Run in fullscreen mode Run in window mode .TP .B \-g, \-\-geometry WIDTHxHEIGHT -Run SuperTux in given resolution +Run SuperTux in given resolution (eg. \-g 800x600) +.TP +.B \-a, \-\-aspect WIDTH:HEIGHT +Run SuperTux with given aspect ratio (eg. \-a 4:3) .TP .B \-\-disable\-sfx Disable sound effects diff --git a/src/gameconfig.cpp b/src/gameconfig.cpp index 9c95946cd..43f2ce0a0 100644 --- a/src/gameconfig.cpp +++ b/src/gameconfig.cpp @@ -44,6 +44,8 @@ Config::Config() screenwidth = 800; screenheight = 600; + aspectwidth = 4; + aspectheight = 3; enable_script_debugger = false; } @@ -70,6 +72,8 @@ Config::load() config_video_lisp->get("fullscreen", use_fullscreen); config_video_lisp->get("width", screenwidth); config_video_lisp->get("height", screenheight); + config_video_lisp->get("aspectwidth", aspectwidth); + config_video_lisp->get("aspectheight", aspectheight); } const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio"); @@ -98,6 +102,8 @@ Config::save() writer.write_bool("fullscreen", use_fullscreen); writer.write_int("width", screenwidth); writer.write_int("height", screenheight); + writer.write_int("aspectwidth", aspectwidth); + writer.write_int("aspectheight", aspectheight); writer.end_list("video"); writer.start_list("audio"); diff --git a/src/gameconfig.hpp b/src/gameconfig.hpp index 8a6dcc520..86145e929 100644 --- a/src/gameconfig.hpp +++ b/src/gameconfig.hpp @@ -36,6 +36,8 @@ public: */ int screenwidth; int screenheight; + int aspectwidth; + int aspectheight; bool use_fullscreen; bool show_fps; diff --git a/src/main.cpp b/src/main.cpp index 1a0796109..a8aab0649 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,6 +61,9 @@ SDL_Surface* screen = 0; JoystickKeyboardController* main_controller = 0; TinyGetText::DictionaryManager dictionary_manager; +int SCREEN_WIDTH; +int SCREEN_HEIGHT; + static void init_config() { config = new Config(); @@ -210,6 +213,7 @@ static void print_usage(const char* argv0) " -f, --fullscreen Run in fullscreen mode\n" " -w, --window Run in window mode\n" " -g, --geometry WIDTHxHEIGHT Run SuperTux in given resolution\n" + " -a, --aspect WIDTH:HEIGHT Run SuperTux with given aspect ratio\n" " --disable-sfx Disable sound effects\n" " --disable-music Disable music\n" " --help Show this help message\n" @@ -265,6 +269,16 @@ static bool parse_commandline(int argc, char** argv) print_usage(argv[0]); throw std::runtime_error("Invalid geometry spec, should be WIDTHxHEIGHT"); } + } else if(arg == "--aspect" || arg == "-a") { + if(i+1 >= argc) { + print_usage(argv[0]); + throw std::runtime_error("Need to specify a parameter for aspect switch"); + } + if(sscanf(argv[++i], "%d:%d", &config->aspectwidth, &config->aspectheight) + != 2) { + print_usage(argv[0]); + throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT"); + } } else if(arg == "--show-fps") { config->show_fps = true; } else if(arg == "--no-show-fps") { @@ -371,6 +385,16 @@ void init_video() } #endif + // use aspect ratio to calculate logical resolution + if (config->aspectwidth > config->aspectheight) { + SCREEN_HEIGHT=600; + SCREEN_WIDTH=600*config->aspectwidth/config->aspectheight; + } + else { + SCREEN_WIDTH=600; + SCREEN_HEIGHT=600*config->aspectheight/config->aspectwidth; + } + // setup opengl state and transform glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); @@ -382,7 +406,7 @@ void init_video() glMatrixMode(GL_PROJECTION); glLoadIdentity(); // logical resolution here not real monitor resolution - glOrtho(0, 800, 600, 0, -1.0, 1.0); + glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, 0); diff --git a/src/main.hpp b/src/main.hpp index 93c03d941..e64b01fea 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -24,9 +24,9 @@ void init_video(); void wait_for_event(float min_delay, float max_delay); /// The width of the display (this is a logical value, not the physical value) -static const float SCREEN_WIDTH = 800; +extern int SCREEN_WIDTH; /// The height of the display (this is a logical value, not the physical value) -static const float SCREEN_HEIGHT = 600; +extern int SCREEN_HEIGHT; // global variables class JoystickKeyboardController; diff --git a/src/textscroller.cpp b/src/textscroller.cpp index 972a29d5e..2db45c9b1 100644 --- a/src/textscroller.cpp +++ b/src/textscroller.cpp @@ -118,7 +118,9 @@ TextScroller::update(float elapsed_time) void TextScroller::draw(DrawingContext& context) { - context.draw_surface(background.get(), Vector(0,0), 0); + context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), + Color(0.6f, 0.7f, 0.8f, 0.5f), 0); + context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0); float y = SCREEN_HEIGHT - scroll; for(size_t i = 0; i < lines.size(); i++) { @@ -164,8 +166,8 @@ InfoBox::~InfoBox() void InfoBox::draw(DrawingContext& context) { - float x1 = 200; - float y1 = 100; + float x1 = SCREEN_WIDTH/2-200; + float y1 = SCREEN_HEIGHT/2-200; float width = 400; float height = 200;