diff -Nru supertux-0.5.2/debian/changelog supertux-0.5.2/debian/changelog --- supertux-0.5.2/debian/changelog 2018-07-28 14:48:07.000000000 +0000 +++ supertux-0.5.2/debian/changelog 2018-07-29 14:48:22.000000000 +0000 @@ -1,8 +1,8 @@ -supertux (0.5.2-0~git201807281448+7~ubuntu14.04.1) trusty; urgency=low +supertux (0.5.2-0~git201807291448+7~ubuntu14.04.1) trusty; urgency=low * Auto build. - -- Launchpad Package Builder Sat, 28 Jul 2018 14:48:07 +0000 + -- Launchpad Package Builder Sun, 29 Jul 2018 14:48:22 +0000 supertux (0.5.2-0) UNRELEASED; urgency=low diff -Nru supertux-0.5.2/debian/git-build-recipe.manifest supertux-0.5.2/debian/git-build-recipe.manifest --- supertux-0.5.2/debian/git-build-recipe.manifest 2018-07-28 14:48:07.000000000 +0000 +++ supertux-0.5.2/debian/git-build-recipe.manifest 2018-07-29 14:48:22.000000000 +0000 @@ -1,5 +1,5 @@ -# git-build-recipe format 0.4 deb-version {debupstream}-0~git201807281448+7 -lp:~supertux-dev/supertux/+git/github-clone git-commit:03fa21478bb4b97c7ee57a433e429eac9db4c582 +# git-build-recipe format 0.4 deb-version {debupstream}-0~git201807291448+7 +lp:~supertux-dev/supertux/+git/github-clone git-commit:c2b0a76d0bca3d4f83ca940fb442d3edce2826f5 nest-part packaging lp:~supertux-dev/supertux/+git/supertux-debian debian debian git-commit:f1d1e6a1cf9785846130d71ceada631eb63bf3b3 nest physfs lp:~supertux-dev/supertux/+git/external-physfs external/physfs git-commit:bbaa39973d1e6a1d6638af9573996f765bd80fe2 nest sexp-cpp lp:~supertux-dev/supertux/+git/external-sexp-cpp external/sexp-cpp git-commit:472d896512f3637e820e9486c02de852ef8f678b diff -Nru supertux-0.5.2/.pc/.quilt_patches supertux-0.5.2/.pc/.quilt_patches --- supertux-0.5.2/.pc/.quilt_patches 2018-07-28 14:48:07.000000000 +0000 +++ supertux-0.5.2/.pc/.quilt_patches 2018-07-29 14:48:22.000000000 +0000 @@ -1 +1 @@ -/home/buildd/build-RECIPEBRANCHBUILD-1614883/chroot-autobuild/home/buildd/work/tree/recipe/debian/patches +/home/buildd/build-RECIPEBRANCHBUILD-1615236/chroot-autobuild/home/buildd/work/tree/recipe/debian/patches diff -Nru supertux-0.5.2/.pc/.quilt_series supertux-0.5.2/.pc/.quilt_series --- supertux-0.5.2/.pc/.quilt_series 2018-07-28 14:48:07.000000000 +0000 +++ supertux-0.5.2/.pc/.quilt_series 2018-07-29 14:48:22.000000000 +0000 @@ -1 +1 @@ -/home/buildd/build-RECIPEBRANCHBUILD-1614883/chroot-autobuild/home/buildd/work/tree/recipe/debian/patches/series +/home/buildd/build-RECIPEBRANCHBUILD-1615236/chroot-autobuild/home/buildd/work/tree/recipe/debian/patches/series diff -Nru supertux-0.5.2/src/editor/editor.cpp supertux-0.5.2/src/editor/editor.cpp --- supertux-0.5.2/src/editor/editor.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/editor/editor.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -51,6 +51,8 @@ #include "video/compositor.hpp" #include "video/drawing_context.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" Editor::Editor() : level(), diff -Nru supertux-0.5.2/src/editor/input_center.cpp supertux-0.5.2/src/editor/input_center.cpp --- supertux-0.5.2/src/editor/input_center.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/editor/input_center.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -30,6 +30,7 @@ #include "supertux/sector.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" bool EditorInputCenter::render_background = true; bool EditorInputCenter::render_grid = true; @@ -630,7 +631,7 @@ case SDL_MOUSEMOTION: { - mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); update_pos(); if (dragging) { switch (Editor::current()->get_tileselect_input_type()) { diff -Nru supertux-0.5.2/src/editor/input_gui.cpp supertux-0.5.2/src/editor/input_gui.cpp --- supertux-0.5.2/src/editor/input_gui.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/editor/input_gui.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -32,6 +32,7 @@ #include "video/drawing_context.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" EditorInputGui::EditorInputGui() : tiles(new TileSelection()), @@ -341,7 +342,7 @@ case SDL_MOUSEMOTION: { - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); float x = mouse_pos.x - Xpos; float y = mouse_pos.y - Ypos; if (x < 0) { diff -Nru supertux-0.5.2/src/editor/layers_gui.cpp supertux-0.5.2/src/editor/layers_gui.cpp --- supertux-0.5.2/src/editor/layers_gui.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/editor/layers_gui.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -31,6 +31,7 @@ #include "video/drawing_context.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" EditorLayersGui::EditorLayersGui() : layers(), @@ -159,7 +160,7 @@ case SDL_MOUSEMOTION: { - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); float x = mouse_pos.x - Xpos; float y = mouse_pos.y - Ypos; if (y < 0 || x > Width) { diff -Nru supertux-0.5.2/src/editor/scroller.cpp supertux-0.5.2/src/editor/scroller.cpp --- supertux-0.5.2/src/editor/scroller.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/editor/scroller.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,7 @@ #include "video/drawing_context.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" namespace { @@ -125,7 +126,7 @@ { if (!rendered) return false; - mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); if (mouse_pos.x < SIZE && mouse_pos.y < SIZE) { scrolling_vec = mouse_pos - Vector(MIDDLE, MIDDLE); if (scrolling_vec.x != 0 || scrolling_vec.y != 0) { diff -Nru supertux-0.5.2/src/gui/dialog.cpp supertux-0.5.2/src/gui/dialog.cpp --- supertux-0.5.2/src/gui/dialog.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/gui/dialog.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -26,6 +26,7 @@ #include "video/drawing_context.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" Dialog::Dialog(bool passive) : m_text(), @@ -114,7 +115,7 @@ case SDL_MOUSEBUTTONDOWN: if(ev.button.button == SDL_BUTTON_LEFT) { - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); int new_button = get_button_at(mouse_pos); if (new_button != -1) { @@ -126,7 +127,7 @@ case SDL_MOUSEMOTION: { - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); int new_button = get_button_at(mouse_pos); if (new_button != -1) { diff -Nru supertux-0.5.2/src/gui/menu.cpp supertux-0.5.2/src/gui/menu.cpp --- supertux-0.5.2/src/gui/menu.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/gui/menu.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -28,6 +28,7 @@ #include "video/drawing_context.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" static const float MENU_REPEAT_INITIAL = 0.4f; static const float MENU_REPEAT_RATE = 0.1f; @@ -537,7 +538,7 @@ case SDL_MOUSEBUTTONDOWN: if(ev.button.button == SDL_BUTTON_LEFT) { - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); int x = int(mouse_pos.x); int y = int(mouse_pos.y); @@ -553,7 +554,7 @@ case SDL_MOUSEMOTION: { - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); float x = mouse_pos.x; float y = mouse_pos.y; diff -Nru supertux-0.5.2/src/gui/mousecursor.cpp supertux-0.5.2/src/gui/mousecursor.cpp --- supertux-0.5.2/src/gui/mousecursor.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/gui/mousecursor.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,7 @@ #include "video/renderer.hpp" #include "video/surface.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" MouseCursor* MouseCursor::current_ = 0; @@ -63,7 +64,7 @@ int y; Uint8 ispressed = SDL_GetMouseState(&x, &y); - Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(x, y); + Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(x, y); x = int(mouse_pos.x); y = int(mouse_pos.y); diff -Nru supertux-0.5.2/src/object/bullet.cpp supertux-0.5.2/src/object/bullet.cpp --- supertux-0.5.2/src/object/bullet.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/bullet.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,8 @@ #include "sprite/sprite_manager.hpp" #include "supertux/direction.hpp" #include "supertux/sector.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" namespace { const float BULLET_XM = 600; diff -Nru supertux-0.5.2/src/object/camera.cpp supertux-0.5.2/src/object/camera.cpp --- supertux-0.5.2/src/object/camera.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/camera.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -27,6 +27,8 @@ #include "util/reader_mapping.hpp" #include "util/writer.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" /* this is the fractional distance toward the peek position to move each frame; lower is slower, diff -Nru supertux-0.5.2/src/object/falling_coin.cpp supertux-0.5.2/src/object/falling_coin.cpp --- supertux-0.5.2/src/object/falling_coin.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/falling_coin.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -19,6 +19,8 @@ #include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" #include "supertux/globals.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) : physic(), diff -Nru supertux-0.5.2/src/object/fireworks.cpp supertux-0.5.2/src/object/fireworks.cpp --- supertux-0.5.2/src/object/fireworks.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/fireworks.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,8 @@ #include "object/particles.hpp" #include "supertux/sector.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" Fireworks::Fireworks() : timer() diff -Nru supertux-0.5.2/src/object/ghost_particle_system.cpp supertux-0.5.2/src/object/ghost_particle_system.cpp --- supertux-0.5.2/src/object/ghost_particle_system.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/ghost_particle_system.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,8 @@ #include "math/random_generator.hpp" #include "supertux/globals.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" //FIXME: Sometimes both ghosts have the same image // Ghosts don't change their movement pattern - not random diff -Nru supertux-0.5.2/src/object/gradient.cpp supertux-0.5.2/src/object/gradient.cpp --- supertux-0.5.2/src/object/gradient.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/gradient.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,8 @@ #include "util/reader.hpp" #include "util/reader_mapping.hpp" #include "util/writer.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" Gradient::Gradient() : ExposedObject(this), diff -Nru supertux-0.5.2/src/object/magicblock.cpp supertux-0.5.2/src/object/magicblock.cpp --- supertux-0.5.2/src/object/magicblock.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/magicblock.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -27,6 +27,8 @@ #include "supertux/constants.hpp" #include "supertux/sector.hpp" #include "util/reader_mapping.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" namespace { const float MIN_INTENSITY = 0.8f; diff -Nru supertux-0.5.2/src/object/particles.cpp supertux-0.5.2/src/object/particles.cpp --- supertux-0.5.2/src/object/particles.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/particles.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,8 @@ #include "object/camera.hpp" #include "supertux/sector.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" //TODO: remove this function in favor of the one below Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, diff -Nru supertux-0.5.2/src/object/particlesystem.cpp supertux-0.5.2/src/object/particlesystem.cpp --- supertux-0.5.2/src/object/particlesystem.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/particlesystem.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -23,6 +23,8 @@ #include "util/reader_mapping.hpp" #include "util/writer.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" ParticleSystem::ParticleSystem(float max_particle_size_) : ExposedObject(this), diff -Nru supertux-0.5.2/src/object/particlesystem_interactive.cpp supertux-0.5.2/src/object/particlesystem_interactive.cpp --- supertux-0.5.2/src/object/particlesystem_interactive.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/particlesystem_interactive.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -23,6 +23,8 @@ #include "supertux/sector.hpp" #include "supertux/tile.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" //TODO: Find a way to make rain collide with objects like bonus blocks // Add an option to set rain strength diff -Nru supertux-0.5.2/src/object/rain_particle_system.cpp supertux-0.5.2/src/object/rain_particle_system.cpp --- supertux-0.5.2/src/object/rain_particle_system.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/rain_particle_system.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -23,6 +23,8 @@ #include "object/rainsplash.hpp" #include "supertux/sector.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" RainParticleSystem::RainParticleSystem() { diff -Nru supertux-0.5.2/src/object/snow_particle_system.cpp supertux-0.5.2/src/object/snow_particle_system.cpp --- supertux-0.5.2/src/object/snow_particle_system.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/snow_particle_system.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -22,6 +22,8 @@ #include "math/random_generator.hpp" #include "supertux/sector.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" // TODO: tweak values namespace SNOW { diff -Nru supertux-0.5.2/src/object/sprite_particle.cpp supertux-0.5.2/src/object/sprite_particle.cpp --- supertux-0.5.2/src/object/sprite_particle.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/object/sprite_particle.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -21,6 +21,8 @@ #include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" #include "supertux/sector.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" SpriteParticle::SpriteParticle(const std::string& sprite_name, const std::string& action, const Vector& position_, AnchorPoint anchor, const Vector& velocity_, const Vector& acceleration_, diff -Nru supertux-0.5.2/src/scripting/functions.cpp supertux-0.5.2/src/scripting/functions.cpp --- supertux-0.5.2/src/scripting/functions.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/scripting/functions.cpp 2018-07-29 14:48:12.000000000 +0000 @@ -34,6 +34,7 @@ #include "supertux/tile.hpp" #include "video/renderer.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" #include "worldmap/tux.hpp" #include "worldmap/worldmap.hpp" diff -Nru supertux-0.5.2/src/supertux/globals.cpp supertux-0.5.2/src/supertux/globals.cpp --- supertux-0.5.2/src/supertux/globals.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/globals.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -18,9 +18,6 @@ #include "supertux/gameconfig.hpp" -int SCREEN_WIDTH; -int SCREEN_HEIGHT; - std::unique_ptr g_config; float game_time = 0; diff -Nru supertux-0.5.2/src/supertux/globals.hpp supertux-0.5.2/src/supertux/globals.hpp --- supertux-0.5.2/src/supertux/globals.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/globals.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -21,15 +21,11 @@ class Config; -/** The width of the display (this is a logical value, not the - physical value, since aspect_ration and projection_area might - shrink or scale things) */ -extern int SCREEN_WIDTH; - -/** The width of the display (this is a logical value, not the - physical value, since aspect_ration and projection_area might - shrink or scale things) */ -extern int SCREEN_HEIGHT; +// This is meant to be temporarily. Code should not use +// SCREEN_WIDTH/HEIGHT, but instead use context.get_width()/height() +// inside the draw() call. +#define SCREEN_WIDTH (VideoSystem::current()->get_viewport().get_screen_width()) +#define SCREEN_HEIGHT (VideoSystem::current()->get_viewport().get_screen_height()) extern std::unique_ptr g_config; diff -Nru supertux-0.5.2/src/supertux/menu/main_menu.cpp supertux-0.5.2/src/supertux/menu/main_menu.cpp --- supertux-0.5.2/src/supertux/menu/main_menu.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/menu/main_menu.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -26,6 +26,8 @@ #include "supertux/menu/menu_storage.hpp" #include "supertux/screen_manager.hpp" #include "supertux/textscroller.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" MainMenu::MainMenu() { diff -Nru supertux-0.5.2/src/supertux/sector.cpp supertux-0.5.2/src/supertux/sector.cpp --- supertux-0.5.2/src/supertux/sector.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/sector.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -42,6 +42,8 @@ #include "supertux/tile.hpp" #include "util/file_system.hpp" #include "util/writer.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" Sector* Sector::_current = 0; diff -Nru supertux-0.5.2/src/supertux/shrinkfade.cpp supertux-0.5.2/src/supertux/shrinkfade.cpp --- supertux-0.5.2/src/supertux/shrinkfade.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/shrinkfade.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -18,6 +18,8 @@ #include "supertux/globals.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" ShrinkFade::ShrinkFade(const Vector& dest_, float fade_time_) : dest(dest_), diff -Nru supertux-0.5.2/src/supertux/statistics.cpp supertux-0.5.2/src/supertux/statistics.cpp --- supertux-0.5.2/src/supertux/statistics.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/statistics.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -29,6 +29,8 @@ #include "util/log.hpp" #include "video/drawing_context.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" namespace { const int nv_coins = std::numeric_limits::min(); diff -Nru supertux-0.5.2/src/supertux/textscroller.cpp supertux-0.5.2/src/supertux/textscroller.cpp --- supertux-0.5.2/src/supertux/textscroller.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/supertux/textscroller.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -31,6 +31,8 @@ #include "video/compositor.hpp" #include "video/drawing_context.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" static const float DEFAULT_SPEED = 20; static const float LEFT_BORDER = 50; diff -Nru supertux-0.5.2/src/trigger/climbable.cpp supertux-0.5.2/src/trigger/climbable.cpp --- supertux-0.5.2/src/trigger/climbable.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/trigger/climbable.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -21,6 +21,8 @@ #include "supertux/resources.hpp" #include "util/reader_mapping.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" namespace { const float GRACE_DX = 8; // how far off may the player's bounding-box be x-wise diff -Nru supertux-0.5.2/src/trigger/secretarea_trigger.cpp supertux-0.5.2/src/trigger/secretarea_trigger.cpp --- supertux-0.5.2/src/trigger/secretarea_trigger.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/trigger/secretarea_trigger.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -23,6 +23,8 @@ #include "supertux/sector.hpp" #include "util/reader_mapping.hpp" #include "video/drawing_context.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" static const float MESSAGE_TIME=3.5; diff -Nru supertux-0.5.2/src/video/canvas.hpp supertux-0.5.2/src/video/canvas.hpp --- supertux-0.5.2/src/video/canvas.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/canvas.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -98,10 +98,7 @@ int layer); void draw_text(FontPtr font, const std::string& text, const Vector& position, FontAlignment alignment, int layer, Color color = Color(1.0,1.0,1.0)); - - /** Draws text on screen center (feed Vector.x with a 0). This is - the same as draw_text() with a SCREEN_WIDTH/2 position and - alignment set to LEFT_ALIGN */ + /** Draw text to the center of the screen */ void draw_center_text(FontPtr font, const std::string& text, const Vector& position, int layer, Color color = Color(1.0,1.0,1.0)); void draw_gradient(const Color& from, const Color& to, int layer, const GradientDirection& direction, const Rectf& region); diff -Nru supertux-0.5.2/src/video/drawing_context.cpp supertux-0.5.2/src/video/drawing_context.cpp --- supertux-0.5.2/src/video/drawing_context.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/drawing_context.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -25,12 +25,15 @@ #include "video/renderer.hpp" #include "video/surface.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" DrawingContext::DrawingContext(VideoSystem& video_system_, obstack& obst, bool overlay) : m_video_system(video_system_), m_obst(obst), m_overlay(overlay), - m_viewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), + m_viewport(0, 0, + m_video_system.get_viewport().get_screen_width(), + m_video_system.get_viewport().get_screen_height()), m_ambient_color(Color::WHITE), m_transform_stack(1), m_colormap_canvas(DrawingTarget::COLORMAP, *this, m_obst), diff -Nru supertux-0.5.2/src/video/gl/gl_lightmap.cpp supertux-0.5.2/src/video/gl/gl_lightmap.cpp --- supertux-0.5.2/src/video/gl/gl_lightmap.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_lightmap.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -33,6 +33,7 @@ GLLightmap::GLLightmap(GLVideoSystem& video_system) : m_video_system(video_system), + m_painter(), m_lightmap(), m_lightmap_width(), m_lightmap_height(), @@ -134,43 +135,43 @@ void GLLightmap::draw_surface(const DrawingRequest& request) { - GLPainter::draw_surface(request); + m_painter.draw_surface(request); } void GLLightmap::draw_surface_part(const DrawingRequest& request) { - GLPainter::draw_surface_part(request); + m_painter.draw_surface_part(request); } void GLLightmap::draw_gradient(const DrawingRequest& request) { - GLPainter::draw_gradient(request); + m_painter.draw_gradient(request); } void GLLightmap::draw_filled_rect(const DrawingRequest& request) { - GLPainter::draw_filled_rect(request); + m_painter.draw_filled_rect(request); } void GLLightmap::draw_inverse_ellipse(const DrawingRequest& request) { - GLPainter::draw_inverse_ellipse(request); + m_painter.draw_inverse_ellipse(request); } void GLLightmap::draw_line(const DrawingRequest& request) { - GLPainter::draw_line(request); + m_painter.draw_line(request); } void GLLightmap::draw_triangle(const DrawingRequest& request) { - GLPainter::draw_triangle(request); + m_painter.draw_triangle(request); } void diff -Nru supertux-0.5.2/src/video/gl/gl_lightmap.hpp supertux-0.5.2/src/video/gl/gl_lightmap.hpp --- supertux-0.5.2/src/video/gl/gl_lightmap.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_lightmap.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -19,8 +19,9 @@ #include -#include "video/lightmap.hpp" +#include "video/gl/gl_painter.hpp" #include "video/glutil.hpp" +#include "video/lightmap.hpp" class GLTexture; class GLVideoSystem; @@ -57,6 +58,7 @@ private: GLVideoSystem& m_video_system; + GLPainter m_painter; std::shared_ptr m_lightmap; int m_lightmap_width; diff -Nru supertux-0.5.2/src/video/gl/gl_painter.cpp supertux-0.5.2/src/video/gl/gl_painter.cpp --- supertux-0.5.2/src/video/gl/gl_painter.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_painter.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -23,6 +23,8 @@ #include "video/drawing_request.hpp" #include "video/gl/gl_surface_data.hpp" #include "video/gl/gl_texture.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" GLuint GLPainter::s_last_texture = static_cast(-1); diff -Nru supertux-0.5.2/src/video/gl/gl_painter.hpp supertux-0.5.2/src/video/gl/gl_painter.hpp --- supertux-0.5.2/src/video/gl/gl_painter.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_painter.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -34,15 +34,15 @@ static GLuint s_last_texture; public: - GLPainter(); + GLPainter() {} - static void draw_surface(const DrawingRequest& request); - static void draw_surface_part(const DrawingRequest& request); - static void draw_gradient(const DrawingRequest& request); - static void draw_filled_rect(const DrawingRequest& request); - static void draw_inverse_ellipse(const DrawingRequest& request); - static void draw_line(const DrawingRequest& request); - static void draw_triangle(const DrawingRequest& request); + void draw_surface(const DrawingRequest& request); + void draw_surface_part(const DrawingRequest& request); + void draw_gradient(const DrawingRequest& request); + void draw_filled_rect(const DrawingRequest& request); + void draw_inverse_ellipse(const DrawingRequest& request); + void draw_line(const DrawingRequest& request); + void draw_triangle(const DrawingRequest& request); private: GLPainter(const GLPainter&) = delete; diff -Nru supertux-0.5.2/src/video/gl/gl_renderer.cpp supertux-0.5.2/src/video/gl/gl_renderer.cpp --- supertux-0.5.2/src/video/gl/gl_renderer.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_renderer.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -21,15 +21,12 @@ #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" #include "util/log.hpp" -#include "video/gl/gl_painter.hpp" #include "video/gl/gl_video_system.hpp" #include "video/glutil.hpp" -#include "video/util.hpp" GLRenderer::GLRenderer(GLVideoSystem& video_system) : m_video_system(video_system), - m_viewport(), - m_scale(1.0f, 1.0f) + m_painter() { } @@ -47,6 +44,27 @@ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + const Rect& viewport = m_video_system.get_viewport().get_rect(); + const Vector& scale = m_video_system.get_viewport().get_scale(); + + glViewport(viewport.left, viewport.top, + viewport.get_width(), viewport.get_height()); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glOrtho(0, + viewport.get_width() / scale.x, + viewport.get_height() / scale.y, + 0, + -1, + 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, 0); + check_gl_error("Setting up view matrices"); } void @@ -57,43 +75,43 @@ void GLRenderer::draw_surface(const DrawingRequest& request) { - GLPainter::draw_surface(request); + m_painter.draw_surface(request); } void GLRenderer::draw_surface_part(const DrawingRequest& request) { - GLPainter::draw_surface_part(request); + m_painter.draw_surface_part(request); } void GLRenderer::draw_gradient(const DrawingRequest& request) { - GLPainter::draw_gradient(request); + m_painter.draw_gradient(request); } void GLRenderer::draw_filled_rect(const DrawingRequest& request) { - GLPainter::draw_filled_rect(request); + m_painter.draw_filled_rect(request); } void GLRenderer::draw_inverse_ellipse(const DrawingRequest& request) { - GLPainter::draw_inverse_ellipse(request); + m_painter.draw_inverse_ellipse(request); } void GLRenderer::draw_line(const DrawingRequest& request) { - GLPainter::draw_line(request); + m_painter.draw_line(request); } void GLRenderer::draw_triangle(const DrawingRequest& request) { - GLPainter::draw_triangle(request); + m_painter.draw_triangle(request); } void @@ -103,13 +121,6 @@ glClear(GL_COLOR_BUFFER_BIT); } -Vector -GLRenderer::to_logical(int physical_x, int physical_y) const -{ - return Vector(static_cast(physical_x - m_viewport.x) / m_scale.x, - static_cast(physical_y - m_viewport.y) / m_scale.y); -} - void GLRenderer::set_clip_rect(const Rect& rect) { @@ -128,28 +139,4 @@ glDisable(GL_SCISSOR_TEST); } -void -GLRenderer::set_viewport(const SDL_Rect& viewport, const Vector& scale) -{ - m_viewport = viewport; - m_scale = scale; - - glViewport(m_viewport.x, m_viewport.y, m_viewport.w, m_viewport.h); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(0, - m_viewport.w / m_scale.x, - m_viewport.h / m_scale.y, - 0, - -1, - 1); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, 0, 0); - check_gl_error("Setting up view matrices"); -} - /* EOF */ diff -Nru supertux-0.5.2/src/video/gl/gl_renderer.hpp supertux-0.5.2/src/video/gl/gl_renderer.hpp --- supertux-0.5.2/src/video/gl/gl_renderer.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_renderer.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -20,6 +20,7 @@ #include #include "math/vector.hpp" +#include "video/gl/gl_painter.hpp" #include "video/renderer.hpp" class GLVideoSystem; @@ -45,18 +46,12 @@ virtual void draw_triangle(const DrawingRequest& request) override; virtual void clear(const Color& color) override; - Vector to_logical(int physical_x, int physical_y) const override; - virtual void set_clip_rect(const Rect& rect) override; virtual void clear_clip_rect() override; - void set_viewport(const SDL_Rect& viewport, const Vector& scale); - SDL_Rect get_viewport() const { return m_viewport; } - private: GLVideoSystem& m_video_system; - SDL_Rect m_viewport; - Vector m_scale; + GLPainter m_painter; private: GLRenderer(const GLRenderer&) = delete; diff -Nru supertux-0.5.2/src/video/gl/gl_video_system.cpp supertux-0.5.2/src/video/gl/gl_video_system.cpp --- supertux-0.5.2/src/video/gl/gl_video_system.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_video_system.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -34,7 +34,6 @@ #include "video/gl/gl_renderer.hpp" #include "video/gl/gl_surface_data.hpp" #include "video/gl/gl_texture.hpp" -#include "video/util.hpp" GLVideoSystem::GLVideoSystem() : m_texture_manager(), @@ -43,7 +42,7 @@ m_window(), m_glcontext(), m_desktop_size(), - m_fullscreen_active() + m_viewport() { SDL_DisplayMode mode; SDL_GetCurrentDisplayMode(0, &mode); @@ -118,11 +117,6 @@ m_glcontext = SDL_GL_CreateContext(m_window); - SCREEN_WIDTH = size.width; - SCREEN_HEIGHT = size.height; - - m_fullscreen_active = g_config->use_fullscreen; - if(g_config->try_vsync) { /* we want vsync for smooth scrolling */ if (SDL_GL_SetSwapInterval(-1) != 0) @@ -200,31 +194,9 @@ ((g_config->fullscreen_size == Size(0, 0)) ? m_desktop_size : g_config->fullscreen_size) : g_config->window_size; - float pixel_aspect_ratio = 1.0f; - if (g_config->aspect_size != Size(0, 0)) - { - pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size, - g_config->aspect_size); - } - else if (g_config->use_fullscreen) - { - pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size, - target_size); - } - - SDL_Rect viewport; - Vector scale; - calculate_viewport(s_min_size, s_max_size, - target_size, - pixel_aspect_ratio, - g_config->magnification, - scale, - viewport); + m_viewport = Viewport::from_size(target_size, m_desktop_size); - SCREEN_WIDTH = static_cast(viewport.w / scale.x); - SCREEN_HEIGHT = static_cast(viewport.h / scale.y); - - if (viewport.x != 0 || viewport.y != 0) + if (m_viewport.needs_clear_screen()) { // Clear both buffers so that we get a clean black border without junk m_renderer->clear(Color::BLACK); @@ -232,8 +204,6 @@ m_renderer->clear(Color::BLACK); flip(); } - - m_renderer->set_viewport(viewport, scale); } void diff -Nru supertux-0.5.2/src/video/gl/gl_video_system.hpp supertux-0.5.2/src/video/gl/gl_video_system.hpp --- supertux-0.5.2/src/video/gl/gl_video_system.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/gl/gl_video_system.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -22,6 +22,7 @@ #include "math/size.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" class GLRenderer; class GLLightmap; @@ -42,6 +43,7 @@ virtual SurfaceData* new_surface_data(const Surface& surface) override; virtual void free_surface_data(SurfaceData* surface_data) override; + virtual const Viewport& get_viewport() const override { return m_viewport; } virtual void apply_config() override; virtual void flip() override; virtual void on_resize(int w, int h) override; @@ -66,7 +68,7 @@ SDL_Window* m_window; SDL_GLContext m_glcontext; Size m_desktop_size; - bool m_fullscreen_active; + Viewport m_viewport; private: GLVideoSystem(const GLVideoSystem&) = delete; diff -Nru supertux-0.5.2/src/video/renderer.cpp supertux-0.5.2/src/video/renderer.cpp --- supertux-0.5.2/src/video/renderer.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/renderer.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "video/renderer.hpp" - -Renderer::Renderer() -{ -} - -Renderer::~Renderer() -{ -} - -/* EOF */ diff -Nru supertux-0.5.2/src/video/renderer.hpp supertux-0.5.2/src/video/renderer.hpp --- supertux-0.5.2/src/video/renderer.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/renderer.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -17,6 +17,7 @@ #ifndef HEADER_SUPERTUX_VIDEO_RENDERER_HPP #define HEADER_SUPERTUX_VIDEO_RENDERER_HPP +#include "math/rect.hpp" #include "math/vector.hpp" #include "video/color.hpp" @@ -27,8 +28,7 @@ class Renderer { public: - Renderer(); - virtual ~Renderer(); + virtual ~Renderer() {} virtual void start_draw() = 0; virtual void end_draw() = 0; @@ -42,8 +42,6 @@ virtual void draw_triangle(const DrawingRequest& request) = 0; virtual void clear(const Color& color) = 0; - virtual Vector to_logical(int physical_x, int physical_y) const = 0; - virtual void set_clip_rect(const Rect& rect) = 0; virtual void clear_clip_rect() = 0; }; diff -Nru supertux-0.5.2/src/video/sdl/sdl_lightmap.cpp supertux-0.5.2/src/video/sdl/sdl_lightmap.cpp --- supertux-0.5.2/src/video/sdl/sdl_lightmap.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_lightmap.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -22,9 +22,12 @@ #include "video/sdl/sdl_renderer.hpp" #include "video/sdl/sdl_painter.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" -SDLLightmap::SDLLightmap(SDL_Renderer* renderer) : +SDLLightmap::SDLLightmap(SDLVideoSystem& video_system, SDL_Renderer* renderer) : + m_video_system(video_system), m_renderer(renderer), + m_painter(), m_texture(), m_width(), m_height(), @@ -72,43 +75,43 @@ void SDLLightmap::draw_surface(const DrawingRequest& request) { - SDLPainter::draw_surface(m_renderer, request); + m_painter.draw_surface(m_renderer, request); } void SDLLightmap::draw_surface_part(const DrawingRequest& request) { - SDLPainter::draw_surface_part(m_renderer, request); + m_painter.draw_surface_part(m_renderer, request); } void SDLLightmap::draw_gradient(const DrawingRequest& request) { - SDLPainter::draw_gradient(m_renderer, request); + m_painter.draw_gradient(m_renderer, request); } void SDLLightmap::draw_filled_rect(const DrawingRequest& request) { - SDLPainter::draw_filled_rect(m_renderer, request); + m_painter.draw_filled_rect(m_renderer, request); } void SDLLightmap::draw_inverse_ellipse(const DrawingRequest& request) { - SDLPainter::draw_inverse_ellipse(m_renderer, request); + m_painter.draw_inverse_ellipse(m_renderer, request); } void SDLLightmap::draw_line(const DrawingRequest& request) { - SDLPainter::draw_line(m_renderer, request); + m_painter.draw_line(m_renderer, request); } void SDLLightmap::draw_triangle(const DrawingRequest& request) { - SDLPainter::draw_triangle(m_renderer, request); + m_painter.draw_triangle(m_renderer, request); } void diff -Nru supertux-0.5.2/src/video/sdl/sdl_lightmap.hpp supertux-0.5.2/src/video/sdl/sdl_lightmap.hpp --- supertux-0.5.2/src/video/sdl/sdl_lightmap.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_lightmap.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -22,7 +22,10 @@ #include #include +#include "video/sdl/sdl_painter.hpp" + class Color; +class SDLVideoSystem; struct DrawingRequest; struct SDL_Renderer; struct SDL_Texture; @@ -30,7 +33,7 @@ class SDLLightmap : public Lightmap { public: - SDLLightmap(SDL_Renderer* renderer); + SDLLightmap(SDLVideoSystem& video_system, SDL_Renderer* renderer); ~SDLLightmap(); virtual void start_draw() override; @@ -52,7 +55,9 @@ virtual void render() override; private: + SDLVideoSystem& m_video_system; SDL_Renderer* m_renderer; + SDLPainter m_painter; SDL_Texture* m_texture; int m_width; int m_height; diff -Nru supertux-0.5.2/src/video/sdl/sdl_painter.cpp supertux-0.5.2/src/video/sdl/sdl_painter.cpp --- supertux-0.5.2/src/video/sdl/sdl_painter.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_painter.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -24,6 +24,8 @@ #include "video/drawing_request.hpp" #include "video/sdl/sdl_texture.hpp" #include "video/surface.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" namespace { diff -Nru supertux-0.5.2/src/video/sdl/sdl_painter.hpp supertux-0.5.2/src/video/sdl/sdl_painter.hpp --- supertux-0.5.2/src/video/sdl/sdl_painter.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_painter.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -23,13 +23,15 @@ class SDLPainter { public: - static void draw_surface(SDL_Renderer* renderer, const DrawingRequest& request); - static void draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& request); - static void draw_gradient(SDL_Renderer* renderer, const DrawingRequest& request); - static void draw_filled_rect(SDL_Renderer* renderer, const DrawingRequest& request); - static void draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& request); - static void draw_line(SDL_Renderer* renderer, const DrawingRequest& request); - static void draw_triangle(SDL_Renderer* renderer, const DrawingRequest& request); + SDLPainter() {} + + void draw_surface(SDL_Renderer* renderer, const DrawingRequest& request); + void draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& request); + void draw_gradient(SDL_Renderer* renderer, const DrawingRequest& request); + void draw_filled_rect(SDL_Renderer* renderer, const DrawingRequest& request); + void draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& request); + void draw_line(SDL_Renderer* renderer, const DrawingRequest& request); + void draw_triangle(SDL_Renderer* renderer, const DrawingRequest& request); private: SDLPainter(const SDLPainter&); diff -Nru supertux-0.5.2/src/video/sdl/sdl_renderer.cpp supertux-0.5.2/src/video/sdl/sdl_renderer.cpp --- supertux-0.5.2/src/video/sdl/sdl_renderer.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_renderer.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -22,12 +22,12 @@ #include "supertux/globals.hpp" #include "util/log.hpp" #include "video/sdl/sdl_painter.hpp" -#include "video/util.hpp" +#include "video/sdl/sdl_video_system.hpp" -SDLRenderer::SDLRenderer(SDL_Renderer* renderer) : +SDLRenderer::SDLRenderer(SDLVideoSystem& video_system, SDL_Renderer* renderer) : + m_video_system(video_system), m_renderer(renderer), - m_viewport(), - m_scale(1.0f, 1.0f), + m_painter(), m_cliprect() { SDL_RendererInfo info; @@ -60,7 +60,17 @@ void SDLRenderer::start_draw() { - SDL_RenderSetScale(m_renderer, m_scale.x, m_scale.y); + const Rect& viewport = m_video_system.get_viewport().get_rect(); + const Vector& scale = m_video_system.get_viewport().get_scale(); + + SDL_Rect sdl_viewport = { viewport.left, viewport.top, + viewport.get_width(), viewport.get_height() }; + + // SetViewport() works in scaled screen coordinates, so we have to + // reset it to 1.0, 1.0 to get meaningful results + SDL_RenderSetScale(m_renderer, 1.0f, 1.0f); + SDL_RenderSetViewport(m_renderer, &sdl_viewport); + SDL_RenderSetScale(m_renderer, scale.x, scale.y); } void @@ -71,43 +81,43 @@ void SDLRenderer::draw_surface(const DrawingRequest& request) { - SDLPainter::draw_surface(m_renderer, request); + m_painter.draw_surface(m_renderer, request); } void SDLRenderer::draw_surface_part(const DrawingRequest& request) { - SDLPainter::draw_surface_part(m_renderer, request); + m_painter.draw_surface_part(m_renderer, request); } void SDLRenderer::draw_gradient(const DrawingRequest& request) { - SDLPainter::draw_gradient(m_renderer, request); + m_painter.draw_gradient(m_renderer, request); } void SDLRenderer::draw_filled_rect(const DrawingRequest& request) { - SDLPainter::draw_filled_rect(m_renderer, request); + m_painter.draw_filled_rect(m_renderer, request); } void SDLRenderer::draw_inverse_ellipse(const DrawingRequest& request) { - SDLPainter::draw_inverse_ellipse(m_renderer, request); + m_painter.draw_inverse_ellipse(m_renderer, request); } void SDLRenderer::draw_line(const DrawingRequest& request) { - SDLPainter::draw_line(m_renderer, request); + m_painter.draw_line(m_renderer, request); } void SDLRenderer::draw_triangle(const DrawingRequest& request) { - SDLPainter::draw_triangle(m_renderer, request); + m_painter.draw_triangle(m_renderer, request); } void @@ -160,24 +170,4 @@ SDL_RenderPresent(m_renderer); } -Vector -SDLRenderer::to_logical(int physical_x, int physical_y) const -{ - return Vector(static_cast(physical_x - m_viewport.x) / m_scale.x, - static_cast(physical_y - m_viewport.y) / m_scale.y); -} - -void -SDLRenderer::set_viewport(const SDL_Rect& viewport, const Vector& scale) -{ - m_viewport = viewport; - m_scale = scale; - - // SetViewport() works in scaled screen coordinates, so we have to - // reset it to 1.0, 1.0 to get meaningful results - SDL_RenderSetScale(m_renderer, 1.0f, 1.0f); - SDL_RenderSetViewport(m_renderer, &m_viewport); - SDL_RenderSetScale(m_renderer, m_scale.x, m_scale.y); -} - /* EOF */ diff -Nru supertux-0.5.2/src/video/sdl/sdl_renderer.hpp supertux-0.5.2/src/video/sdl/sdl_renderer.hpp --- supertux-0.5.2/src/video/sdl/sdl_renderer.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_renderer.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -22,11 +22,14 @@ #include "math/size.hpp" #include "video/renderer.hpp" +#include "video/sdl/sdl_painter.hpp" + +class SDLVideoSystem; class SDLRenderer : public Renderer { public: - SDLRenderer(SDL_Renderer* renderer); + SDLRenderer(SDLVideoSystem& video_system, SDL_Renderer* renderer); ~SDLRenderer(); virtual void start_draw() override; @@ -44,18 +47,13 @@ virtual void set_clip_rect(const Rect& rect) override; virtual void clear_clip_rect() override; - virtual Vector to_logical(int physical_x, int physical_y) const override; - void flip(); SDL_Renderer* get_sdl_renderer() const { return m_renderer; }; - void set_viewport(const SDL_Rect& viewport, const Vector& scale); - SDL_Rect get_viewport() const { return m_viewport; } - private: + SDLVideoSystem& m_video_system; SDL_Renderer* m_renderer; - SDL_Rect m_viewport; - Vector m_scale; + SDLPainter m_painter; boost::optional m_cliprect; private: diff -Nru supertux-0.5.2/src/video/sdl/sdl_video_system.cpp supertux-0.5.2/src/video/sdl/sdl_video_system.cpp --- supertux-0.5.2/src/video/sdl/sdl_video_system.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_video_system.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -24,7 +24,6 @@ #include "supertux/gameconfig.hpp" #include "util/log.hpp" #include "video/renderer.hpp" -#include "video/util.hpp" #include "video/sdl/sdl_lightmap.hpp" #include "video/sdl/sdl_renderer.hpp" #include "video/sdl/sdl_surface_data.hpp" @@ -34,6 +33,7 @@ m_sdl_window(), m_sdl_renderer(), m_desktop_size(), + m_viewport(), m_renderer(), m_lightmap(), m_texture_manager() @@ -69,14 +69,6 @@ } } - SCREEN_WIDTH = width; - SCREEN_HEIGHT = height; - - // m_viewport.x = 0; - // m_viewport.y = 0; - // m_viewport.w = width; - // m_viewport.h = height; - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); int ret = SDL_CreateWindowAndRenderer(width, height, flags, &m_sdl_window, &m_sdl_renderer); @@ -90,8 +82,8 @@ g_config->window_size = Size(width, height); - m_renderer.reset(new SDLRenderer(m_sdl_renderer)); - m_lightmap.reset(new SDLLightmap(m_sdl_renderer)); + m_renderer.reset(new SDLRenderer(*this, m_sdl_renderer)); + m_lightmap.reset(new SDLLightmap(*this, m_sdl_renderer)); m_texture_manager.reset(new TextureManager); apply_config(); @@ -107,7 +99,23 @@ SDLVideoSystem::apply_config() { apply_video_mode(); - apply_viewport(); + + { // apply_viewport + Size target_size = (g_config->use_fullscreen && g_config->fullscreen_size != Size(0, 0)) ? + g_config->fullscreen_size : + g_config->window_size; + + m_viewport = Viewport::from_size(target_size, m_desktop_size); + + if (m_viewport.needs_clear_screen()) + { + // Clear the screen to avoid garbage in unreachable areas after we + m_renderer->clear(Color::BLACK); + m_renderer->flip(); + m_renderer->clear(Color::BLACK); + m_renderer->flip(); + } + } } void @@ -165,49 +173,6 @@ } } -void -SDLVideoSystem::apply_viewport() -{ - Size target_size = (g_config->use_fullscreen && g_config->fullscreen_size != Size(0, 0)) ? - g_config->fullscreen_size : - g_config->window_size; - - float pixel_aspect_ratio = 1.0f; - if (g_config->aspect_size != Size(0, 0)) - { - pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size, - g_config->aspect_size); - } - else if (g_config->use_fullscreen) - { - pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size, - target_size); - } - - // calculate the viewport - SDL_Rect viewport; - Vector scale; - calculate_viewport(s_min_size, s_max_size, - target_size, - pixel_aspect_ratio, - g_config->magnification, - scale, viewport); - - SCREEN_WIDTH = static_cast(viewport.w / scale.x); - SCREEN_HEIGHT = static_cast(viewport.h / scale.y); - - if (viewport.x != 0 || viewport.y != 0) - { - // Clear the screen to avoid garbage in unreachable areas after we - m_renderer->clear(Color::BLACK); - m_renderer->flip(); - m_renderer->clear(Color::BLACK); - m_renderer->flip(); - } - - m_renderer->set_viewport(viewport, scale); -} - Renderer& SDLVideoSystem::get_renderer() const { @@ -245,7 +210,7 @@ apply_config(); - m_lightmap.reset(new SDLLightmap(m_sdl_renderer)); + m_lightmap.reset(new SDLLightmap(*this, m_sdl_renderer)); } void diff -Nru supertux-0.5.2/src/video/sdl/sdl_video_system.hpp supertux-0.5.2/src/video/sdl/sdl_video_system.hpp --- supertux-0.5.2/src/video/sdl/sdl_video_system.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/sdl/sdl_video_system.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -22,6 +22,7 @@ #include "math/size.hpp" #include "video/video_system.hpp" +#include "video/viewport.hpp" class SDLLightmap; class SDLRenderer; @@ -36,10 +37,11 @@ virtual Renderer& get_renderer() const override; virtual Lightmap& get_lightmap() const override; - virtual TexturePtr new_texture(SDL_Surface *image) override; + virtual TexturePtr new_texture(SDL_Surface* image) override; virtual SurfaceData* new_surface_data(const Surface& surface) override; virtual void free_surface_data(SurfaceData* surface_data) override; + virtual const Viewport& get_viewport() const override { return m_viewport; } virtual void apply_config() override; virtual void flip() override; virtual void on_resize(int w, int h) override; @@ -52,12 +54,12 @@ private: void apply_video_mode(); - void apply_viewport(); private: SDL_Window* m_sdl_window; SDL_Renderer* m_sdl_renderer; Size m_desktop_size; + Viewport m_viewport; std::unique_ptr m_renderer; std::unique_ptr m_lightmap; std::unique_ptr m_texture_manager; diff -Nru supertux-0.5.2/src/video/util.cpp supertux-0.5.2/src/video/util.cpp --- supertux-0.5.2/src/video/util.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/util.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,146 +0,0 @@ -// SuperTux -// Copyright (C) 2014 Ingo Ruhnke -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "video/util.hpp" - -#include -#include - -#include "math/size.hpp" -#include "math/vector.hpp" - -namespace { - -inline Size -apply_pixel_aspect_ratio_pre(const Size& window_size, float pixel_aspect_ratio) -{ - if (true) - { - return Size(window_size.width * pixel_aspect_ratio, - window_size.height); - } - else - { - return Size(window_size.width, - window_size.height * pixel_aspect_ratio); - } -} - -inline void -apply_pixel_aspect_ratio_post(const Size& real_window_size, const Size& window_size, float scale, - SDL_Rect& out_viewport, Vector& out_scale) -{ - Vector transform(static_cast(real_window_size.width) / window_size.width, - static_cast(real_window_size.height) / window_size.height); - - out_viewport.x *= transform.x; - out_viewport.y *= transform.y; - - out_viewport.w *= transform.x; - out_viewport.h *= transform.y; - - out_scale.x = scale * transform.x; - out_scale.y = scale * transform.y; - -} - -inline float -calculate_scale(const Size& min_size, const Size& max_size, - const Size& window_size, - float magnification) -{ - float scale = magnification; - if (scale == 0.0f) // magic value - { - scale = 1.0f; - - // Find the minimum magnification that is needed to fill the screen - if (window_size.width > max_size.width || - window_size.height > max_size.height) - { - scale = std::max(static_cast(window_size.width) / max_size.width, - static_cast(window_size.height) / max_size.height); - } - - // If the resulting area would violate min_size, scale it down - if (window_size.width / scale < min_size.width || - window_size.height / scale < min_size.height) - { - scale = std::min(static_cast(window_size.width) / min_size.width, - static_cast(window_size.height) / min_size.height); - } - } - - return scale; -} - -inline SDL_Rect -calculate_viewport(const Size& max_size, const Size& window_size, float scale) -{ - SDL_Rect viewport; - - viewport.w = std::min(window_size.width, - static_cast(scale * max_size.width)); - viewport.h = std::min(window_size.height, - static_cast(scale * max_size.height)); - - // Center the viewport in the window - viewport.x = std::max(0, (window_size.width - viewport.w) / 2); - viewport.y = std::max(0, (window_size.height - viewport.h) / 2); - - return viewport; -} - -} // namespace - -void calculate_viewport(const Size& min_size, const Size& max_size, - const Size& real_window_size, - float pixel_aspect_ratio, float magnification, - Vector& out_scale, - SDL_Rect& out_viewport) -{ - // Transform the real window_size by the aspect ratio, then do - // calculations on that virtual window_size - Size window_size = apply_pixel_aspect_ratio_pre(real_window_size, pixel_aspect_ratio); - - float scale = calculate_scale(min_size, max_size, window_size, magnification); - - // Calculate the new viewport size - out_viewport = calculate_viewport(max_size, window_size, scale); - - // Transform the virtual window_size back into real window coordinates - apply_pixel_aspect_ratio_post(real_window_size, window_size, scale, - out_viewport, out_scale); -} - -float calculate_pixel_aspect_ratio(const Size& source, const Size& target) -{ - float source_aspect = 16.0f / 9.0f; // random guess - if (source != Size(0, 0)) - { - source_aspect = - static_cast(source.width) / - static_cast(source.height); - } - - float target_aspect = - static_cast(target.width) / - static_cast(target.height); - - return target_aspect / source_aspect; -} - -/* EOF */ diff -Nru supertux-0.5.2/src/video/util.hpp supertux-0.5.2/src/video/util.hpp --- supertux-0.5.2/src/video/util.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/util.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -// SuperTux -// Copyright (C) 2013 Ingo Ruhnke -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#ifndef HEADER_SUPERTUX_VIDEO_UTIL_HPP -#define HEADER_SUPERTUX_VIDEO_UTIL_HPP - -class Size; -class Vector; -struct SDL_Rect; - -void calculate_viewport(const Size& min_size, const Size& max_size, - const Size& real_window_size, - float pixel_aspect_ratio, float magnification, - Vector& out_scale, - SDL_Rect& out_viewport); - -float calculate_pixel_aspect_ratio(const Size& source, const Size& target); - -#endif - -/* EOF */ diff -Nru supertux-0.5.2/src/video/video_system.cpp supertux-0.5.2/src/video/video_system.cpp --- supertux-0.5.2/src/video/video_system.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/video_system.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -26,12 +26,6 @@ # include "video/gl/gl_video_system.hpp" #endif -// Minimum and maximum size of the virtual screen, note that the -// maximum must not exceed X/Y_OFFSCREEN_DISTANCE or enemies end up -// spawning on screen instead of off-screen. -const Size VideoSystem::s_max_size(1280, 800); -const Size VideoSystem::s_min_size(640, 480); - std::unique_ptr VideoSystem::create(VideoSystem::Enum video_system) { diff -Nru supertux-0.5.2/src/video/video_system.hpp supertux-0.5.2/src/video/video_system.hpp --- supertux-0.5.2/src/video/video_system.hpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/video/video_system.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -28,6 +28,8 @@ class Renderer; class Surface; class SurfaceData; +class Viewport; +class Viewport; struct SDL_Surface; class VideoSystem : public Currenton @@ -51,10 +53,12 @@ virtual Renderer& get_renderer() const = 0; virtual Lightmap& get_lightmap() const = 0; + virtual TexturePtr new_texture(SDL_Surface *image) = 0; virtual SurfaceData* new_surface_data(const Surface &surface) = 0; virtual void free_surface_data(SurfaceData* surface_data) = 0; + virtual const Viewport& get_viewport() const = 0; virtual void apply_config() = 0; virtual void flip() = 0; virtual void on_resize(int w, int h) = 0; @@ -64,10 +68,6 @@ virtual void set_icon(SDL_Surface* icon) = 0; virtual void do_take_screenshot() = 0; -protected: - static const Size s_max_size; - static const Size s_min_size; - private: VideoSystem(const VideoSystem&) = delete; VideoSystem& operator=(const VideoSystem&) = delete; diff -Nru supertux-0.5.2/src/video/viewport.cpp supertux-0.5.2/src/video/viewport.cpp --- supertux-0.5.2/src/video/viewport.cpp 1970-01-01 00:00:00.000000000 +0000 +++ supertux-0.5.2/src/video/viewport.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -0,0 +1,219 @@ +// SuperTux +// Copyright (C) 2016 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "viewport.hpp" + +#include + +#include "math/rect.hpp" +#include "math/size.hpp" +#include "math/vector.hpp" +#include "supertux/gameconfig.hpp" +#include "supertux/globals.hpp" + +// Minimum and maximum size of the virtual screen, note that the +// maximum must not exceed X/Y_OFFSCREEN_DISTANCE or enemies end up +// spawning on screen instead of off-screen. +const Size Viewport::s_max_size(1280, 800); +const Size Viewport::s_min_size(640, 480); + +namespace { + +inline Size +apply_pixel_aspect_ratio_pre(const Size& window_size, float pixel_aspect_ratio) +{ + if (true) + { + return Size(window_size.width * pixel_aspect_ratio, + window_size.height); + } + else + { + return Size(window_size.width, + window_size.height * pixel_aspect_ratio); + } +} + +inline void +apply_pixel_aspect_ratio_post(const Size& real_window_size, const Size& window_size, float scale, + Rect& out_viewport, Vector& out_scale) +{ + Vector transform(static_cast(real_window_size.width) / window_size.width, + static_cast(real_window_size.height) / window_size.height); + + out_viewport.left *= transform.x; + out_viewport.top *= transform.y; + out_viewport.right *= transform.x; + out_viewport.bottom *= transform.y; + + out_scale.x = scale * transform.x; + out_scale.y = scale * transform.y; +} + +inline float +calculate_scale(const Size& min_size, const Size& max_size, + const Size& window_size, + float magnification) +{ + float scale = magnification; + if (scale == 0.0f) // magic value + { + scale = 1.0f; + + // Find the minimum magnification that is needed to fill the screen + if (window_size.width > max_size.width || + window_size.height > max_size.height) + { + scale = std::max(static_cast(window_size.width) / max_size.width, + static_cast(window_size.height) / max_size.height); + } + + // If the resulting area would violate min_size, scale it down + if (window_size.width / scale < min_size.width || + window_size.height / scale < min_size.height) + { + scale = std::min(static_cast(window_size.width) / min_size.width, + static_cast(window_size.height) / min_size.height); + } + } + + return scale; +} + +inline Rect +calculate_viewport(const Size& max_size, const Size& window_size, float scale) +{ + int viewport_width = std::min(window_size.width, + static_cast(scale * max_size.width)); + int viewport_height = std::min(window_size.height, + static_cast(scale * max_size.height)); + + // Center the viewport in the window + Rect viewport; + + viewport.left = std::max(0, (window_size.width - viewport_width) / 2); + viewport.top = std::max(0, (window_size.height - viewport_height) / 2); + + viewport.right = viewport.left + viewport_width; + viewport.bottom = viewport.top + viewport_height; + + return viewport; +} + +void calculate_viewport(const Size& min_size, const Size& max_size, + const Size& real_window_size, + float pixel_aspect_ratio, float magnification, + Vector& out_scale, + Rect& out_viewport) +{ + // Transform the real window_size by the aspect ratio, then do + // calculations on that virtual window_size + Size window_size = apply_pixel_aspect_ratio_pre(real_window_size, pixel_aspect_ratio); + + float scale = calculate_scale(min_size, max_size, window_size, magnification); + + // Calculate the new viewport size + out_viewport = calculate_viewport(max_size, window_size, scale); + + // Transform the virtual window_size back into real window coordinates + apply_pixel_aspect_ratio_post(real_window_size, window_size, scale, + out_viewport, out_scale); +} + +float calculate_pixel_aspect_ratio(const Size& source, const Size& target) +{ + float source_aspect = 16.0f / 9.0f; // random guess + if (source != Size(0, 0)) + { + source_aspect = + static_cast(source.width) / + static_cast(source.height); + } + + float target_aspect = + static_cast(target.width) / + static_cast(target.height); + + return target_aspect / source_aspect; +} + +} // namespace + +Viewport +Viewport::from_size(const Size& target_size, const Size& desktop_size) +{ + float pixel_aspect_ratio = 1.0f; + if (g_config->aspect_size != Size(0, 0)) + { + pixel_aspect_ratio = calculate_pixel_aspect_ratio(desktop_size, + g_config->aspect_size); + } + else if (g_config->use_fullscreen) + { + pixel_aspect_ratio = calculate_pixel_aspect_ratio(desktop_size, + target_size); + } + + // calculate the viewport + Rect viewport; + Vector scale; + calculate_viewport(s_min_size, s_max_size, + target_size, + pixel_aspect_ratio, + g_config->magnification, + scale, viewport); + + return Viewport(viewport, scale); +} + +Viewport::Viewport() : + m_rect(), + m_scale() +{ +} + +Viewport::Viewport(const Rect& rect, const Vector& scale) : + m_rect(rect), + m_scale(scale) +{ +} + +int +Viewport::get_screen_width() const +{ + return static_cast(m_rect.get_width() / m_scale.x); +} + +int +Viewport::get_screen_height() const +{ + return static_cast(m_rect.get_height() / m_scale.y); +} + +Vector +Viewport::to_logical(int physical_x, int physical_y) const +{ + return Vector(static_cast(physical_x - m_rect.left) / m_scale.x, + static_cast(physical_y - m_rect.top) / m_scale.y); +} + +bool +Viewport::needs_clear_screen() const +{ + return (m_rect.left != 0 || m_rect.top != 0); +} + +/* EOF */ diff -Nru supertux-0.5.2/src/video/viewport.hpp supertux-0.5.2/src/video/viewport.hpp --- supertux-0.5.2/src/video/viewport.hpp 1970-01-01 00:00:00.000000000 +0000 +++ supertux-0.5.2/src/video/viewport.hpp 2018-07-29 14:48:13.000000000 +0000 @@ -0,0 +1,65 @@ +// SuperTux +// Copyright (C) 2016 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_VIDEO_VIEWPORT_HPP +#define HEADER_SUPERTUX_VIDEO_VIEWPORT_HPP + +#include "math/rect.hpp" +#include "math/vector.hpp" + +class Viewport +{ +private: +public: + static Viewport from_size(const Size& target_size, const Size& desktop_size); + +public: + Viewport(); + Viewport(const Rect& rect, const Vector& scale); + + /** The size of the viewport in window coordinates */ + Rect get_rect() const { return m_rect; } + + /** The amount by which the content of the viewport is scaled */ + Vector get_scale() const { return m_scale; } + + /** The width of the resulting logical screen */ + int get_screen_width() const; + + /** The height of the resulting logical screen */ + int get_screen_height() const; + + /** Converts window coordinates into logical screen coordinates */ + Vector to_logical(int physical_x, int physical_y) const; + + /** True if the logical screen doens't cover the whole window */ + bool needs_clear_screen() const; + +private: + /** The minimum logical screen size that is allowed */ + static const Size s_max_size; + + /** The maximum logical screen size that is allowed */ + static const Size s_min_size; + +private: + Rect m_rect; + Vector m_scale; +}; + +#endif + +/* EOF */ diff -Nru supertux-0.5.2/src/worldmap/worldmap.cpp supertux-0.5.2/src/worldmap/worldmap.cpp --- supertux-0.5.2/src/worldmap/worldmap.cpp 2018-07-28 14:47:59.000000000 +0000 +++ supertux-0.5.2/src/worldmap/worldmap.cpp 2018-07-29 14:48:13.000000000 +0000 @@ -45,12 +45,15 @@ #include "util/reader_document.hpp" #include "util/reader_mapping.hpp" #include "video/compositor.hpp" +#include "video/video_system.hpp" #include "worldmap/level.hpp" #include "worldmap/spawn_point.hpp" #include "worldmap/special_tile.hpp" #include "worldmap/sprite_change.hpp" #include "worldmap/teleporter.hpp" #include "worldmap/tux.hpp" +#include "video/video_system.hpp" +#include "video/viewport.hpp" static const float CAMERA_PAN_SPEED = 5.0;