summaryrefslogtreecommitdiff
path: root/src/resources/ambientoverlay.cpp
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2009-07-27 01:02:27 +0200
committerBertram <bertram@cegetel.net>2009-07-27 01:02:27 +0200
commitfa1a3ab995f037ddf33817a1b2ce143130a457f8 (patch)
tree4cfc52364c271a9a318a2fee4b611514d7941476 /src/resources/ambientoverlay.cpp
parent7bc30f545784b26594803b559f1d76d5434027ea (diff)
downloadMana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.tar.gz
Mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.tar.bz2
Mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.tar.xz
Mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.zip
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: <map version="1.0" orientation="orthogonal" width="128" height="128" tilewidth="32" tileheight="32"> <properties> ... <property name="overlay0keepratio" value="true"/> ... </properties> </map>
Diffstat (limited to 'src/resources/ambientoverlay.cpp')
-rw-r--r--src/resources/ambientoverlay.cpp42
1 files changed, 37 insertions, 5 deletions
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());
+
}