From fa1a3ab995f037ddf33817a1b2ce143130a457f8 Mon Sep 17 00:00:00 2001 From: Bertram Date: Mon, 27 Jul 2009 01:02:27 +0200 Subject: Added the ability to ask a ambient layer to keep its ratio when the resolution isn't the default. You'll have to add this in map properties, for instance if you're want to keep ratio on overlay 0: ... ... --- src/resources/ambientoverlay.cpp | 42 +++++++++++++++++++++++++++++++++++----- src/resources/ambientoverlay.h | 5 ++++- 2 files changed, 41 insertions(+), 6 deletions(-) (limited to 'src/resources') diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index 93c7c3e1..8c851e2e 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -22,16 +22,41 @@ #include "resources/ambientoverlay.h" #include "resources/image.h" - +#include "resources/resourcemanager.h" #include "graphics.h" AmbientOverlay::AmbientOverlay(Image *img, float parallax, - float speedX, float speedY): + float speedX, float speedY, bool keepRatio): mImage(img), mParallax(parallax), mPosX(0), mPosY(0), - mSpeedX(speedX), mSpeedY(speedY) + mSpeedX(speedX), mSpeedY(speedY), + mKeepRatio(keepRatio) { - mImage->incRef(); + + if (keepRatio && !mImage->isAnOpenGLOne() + && defaultScreenWidth != 0 + && defaultScreenHeight != 0 + && graphics->getWidth() != defaultScreenWidth + && graphics->getHeight() != defaultScreenHeight) + { + // Rescale the overlay to keep the ratio as if we were on + // the default resolution... + Image *rescaledOverlay = mImage->SDLgetScaledImage( + (int) mImage->getWidth() / defaultScreenWidth * graphics->getWidth(), + (int) mImage->getHeight() / defaultScreenHeight * graphics->getHeight()); + + if (rescaledOverlay) + { + // Replace the resource with the new one... + std::string idPath = mImage->getIdPath() + "_rescaled"; + ResourceManager::getInstance()->addResource(idPath, rescaledOverlay); + mImage = rescaledOverlay; + } + else + mImage->incRef(); + } + else + mImage->incRef(); } AmbientOverlay::~AmbientOverlay() @@ -66,6 +91,13 @@ void AmbientOverlay::update(int timePassed, float dx, float dy) void AmbientOverlay::draw(Graphics *graphics, int x, int y) { - graphics->drawImagePattern(mImage, + if (!mImage->isAnOpenGLOne() || !mKeepRatio) + graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); + else + graphics->drawRescaledImagePattern(mImage, + (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY, + (int) mImage->getWidth() / defaultScreenWidth * graphics->getWidth(), + (int) mImage->getHeight() / defaultScreenHeight * graphics->getHeight()); + } diff --git a/src/resources/ambientoverlay.h b/src/resources/ambientoverlay.h index 756d0eb7..f2d2e588 100644 --- a/src/resources/ambientoverlay.h +++ b/src/resources/ambientoverlay.h @@ -35,9 +35,11 @@ class AmbientOverlay * @param parallax scroll factor based on camera position * @param speedX scrolling speed in x-direction * @param speedY scrolling speed in y-direction + * @param keepRatio rescale the image to keep + * the same ratio than in 800x600 resolution mode. */ AmbientOverlay(Image *img, float parallax, - float speedX, float speedY); + float speedX, float speedY, bool keepRatio = false); ~AmbientOverlay(); @@ -52,6 +54,7 @@ class AmbientOverlay float mPosY; /**< Current layer Y position. */ float mSpeedX; /**< Scrolling speed in X direction. */ float mSpeedY; /**< Scrolling speed in Y direction. */ + bool mKeepRatio; /**< Keep overlay ratio on every resolution */ }; #endif -- cgit v1.2.3-70-g09d2