diff options
author | Bertram <bertram@cegetel.net> | 2009-07-24 22:59:13 +0200 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2009-07-24 22:59:13 +0200 |
commit | 8195e73cb801d56240beb966554a864729d9f20c (patch) | |
tree | f2a00036d15eaf70cb9abe4930b4199b1e5eae05 /src/resources/image.cpp | |
parent | ea6f492198a03cffc3be47df000fa16dfc3b262f (diff) | |
download | mana-8195e73cb801d56240beb966554a864729d9f20c.tar.gz mana-8195e73cb801d56240beb966554a864729d9f20c.tar.bz2 mana-8195e73cb801d56240beb966554a864729d9f20c.tar.xz mana-8195e73cb801d56240beb966554a864729d9f20c.zip |
Made the wallpaper be rescaled when necessary under SDL and OpenGL.
The SDL methods to rescale the wallpaper has been optimized to permit rescaling
at load time while OpenGL draws directly rescaled. Does someone know how to smooth
the rescaled image under OpenGL?
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r-- | src/resources/image.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 0c542a8b..66f87ccb 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -26,6 +26,7 @@ #include "log.h" #include <SDL_image.h> +#include "resources/sdlrescalefacility.h" #ifdef USE_OPENGL bool Image::mUseOpenGL = false; @@ -289,6 +290,15 @@ void Image::unload() #endif } +bool Image::isAnOpenGLOne() const +{ +#ifdef USE_OPENGL + return mUseOpenGL; +#else + return false; +#endif +} + Image *Image::getSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image @@ -395,6 +405,34 @@ float Image::getAlpha() const return mAlpha; } +Image* Image::SDLgetScaledImage(unsigned int width, unsigned int height) +{ + // No scaling on incorrect new values. + if (width == 0 || height == 0) + return NULL; + + // No scaling when there is ... no different given size ... + if (width == getWidth() && height == getHeight()) + return NULL; + + Image* scaledImage = NULL; + SDL_Surface* scaledSurface = NULL; + + if (mImage) + { + scaledSurface = _SDLzoomSurface(mImage, + (double) width / getWidth(), + (double) height / getHeight(), + 1); + + // The load function takes of the SDL<->OpenGL implementation + // and about freeing the given SDL_surface*. + if (scaledSurface) + scaledImage = load(scaledSurface); + } + return scaledImage; +} + #ifdef USE_OPENGL void Image::setLoadAsOpenGL(bool useOpenGL) { @@ -469,4 +507,3 @@ Image *SubImage::getSubImage(int x, int y, int w, int h) { return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); } - |