diff options
author | Bertram <bertram@cegetel.net> | 2009-07-27 01:02:27 +0200 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2009-07-27 01:02:27 +0200 |
commit | fa1a3ab995f037ddf33817a1b2ce143130a457f8 (patch) | |
tree | 4cfc52364c271a9a318a2fee4b611514d7941476 /src/graphics.cpp | |
parent | 7bc30f545784b26594803b559f1d76d5434027ea (diff) | |
download | mana-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/graphics.cpp')
-rw-r--r-- | src/graphics.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp index b84e0bf6..75db11f4 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -221,6 +221,48 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) } } +void Graphics::drawRescaledImagePattern(Image *image, int x, int y, + int w, int h, int scaledWidth, int scaledHeight) +{ + // Check that preconditions for blitting are met. + if (!mScreen || !image) return; + if (!image->mImage) return; + + if (scaledHeight == 0 || scaledWidth == 0) return; + + Image *tmpImage = image->SDLgetScaledImage(scaledWidth, scaledHeight); + if (!tmpImage) return; + + const int iw = tmpImage->getWidth(); + const int ih = tmpImage->getHeight(); + + if (iw == 0 || ih == 0) return; + + for (int py = 0; py < h; py += ih) // Y position on pattern plane + { + int dh = (py + ih >= h) ? h - py : ih; + int srcY = tmpImage->mBounds.y; + int dstY = y + py + mClipStack.top().yOffset; + + for (int px = 0; px < w; px += iw) // X position on pattern plane + { + int dw = (px + iw >= w) ? w - px : iw; + int srcX = tmpImage->mBounds.x; + int dstX = x + px + mClipStack.top().xOffset; + + SDL_Rect dstRect; + SDL_Rect srcRect; + dstRect.x = dstX; dstRect.y = dstY; + srcRect.x = srcX; srcRect.y = srcY; + srcRect.w = dw; srcRect.h = dh; + + SDL_BlitSurface(tmpImage->mImage, &srcRect, mScreen, &dstRect); + } + } + + delete tmpImage; +} + void Graphics::drawImageRect(int x, int y, int w, int h, Image *topLeft, Image *topRight, Image *bottomLeft, Image *bottomRight, |