From 7859699944d51056966c2f2415d1ade230c375a9 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 30 Jan 2009 12:54:38 -0700 Subject: Some style cleanups to the image class. TODO: Find a way to fix the subimage class so that when OpenGL isn't enabled, GUI opacities can still be applied. Signed-off-by: Ira Rice --- src/resources/image.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src/resources') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index c3310849..7a7e6ac8 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -167,7 +167,8 @@ Image *Image::load(SDL_Surface *tmpImage) tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, 32, rmask, gmask, bmask, amask); - if (!tmpImage) { + if (!tmpImage) + { logger->log("Error, image convert failed: out of memory"); return NULL; } @@ -178,9 +179,8 @@ Image *Image::load(SDL_Surface *tmpImage) glGenTextures(1, &texture); glBindTexture(mTextureType, texture); - if (SDL_MUSTLOCK(tmpImage)) { + if (SDL_MUSTLOCK(tmpImage)) SDL_LockSurface(tmpImage); - } glTexImage2D( mTextureType, 0, 4, @@ -255,14 +255,13 @@ Image *Image::load(SDL_Surface *tmpImage) SDL_Surface *image; // Convert the surface to the current display format - if (hasAlpha) { + if (hasAlpha) image = SDL_DisplayFormatAlpha(tmpImage); - } - else { + else image = SDL_DisplayFormat(tmpImage); - } - if (!image) { + if (!image) + { logger->log("Error: Image convert failed."); return NULL; } @@ -274,14 +273,16 @@ void Image::unload() { mLoaded = false; - if (mImage) { + if (mImage) + { // Free the image surface. SDL_FreeSurface(mImage); mImage = NULL; } #ifdef USE_OPENGL - if (mGLImage) { + if (mGLImage) + { glDeleteTextures(1, &mGLImage); mGLImage = 0; } @@ -292,10 +293,9 @@ Image *Image::getSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image #ifdef USE_OPENGL - if (mUseOpenGL) { + if (mUseOpenGL) return new SubImage(this, mGLImage, x, y, width, height, mTexWidth, mTexHeight); - } #endif return new SubImage(this, mImage, x, y, width, height); @@ -303,13 +303,13 @@ Image *Image::getSubImage(int x, int y, int width, int height) void Image::setAlpha(float a) { - if (mAlpha == a) { + if (mAlpha == a) return; - } mAlpha = a; - if (mImage) { + if (mImage) + { // Set the alpha value this image is drawn at SDL_SetAlpha(mImage, SDL_SRCALPHA, (int) (255 * mAlpha)); } @@ -321,14 +321,12 @@ float Image::getAlpha() } #ifdef USE_OPENGL -void -Image::setLoadAsOpenGL(bool useOpenGL) +void Image::setLoadAsOpenGL(bool useOpenGL) { Image::mUseOpenGL = useOpenGL; } -int -Image::powerOfTwo(int input) +int Image::powerOfTwo(int input) { int value; if (mTextureType == GL_TEXTURE_2D) @@ -353,7 +351,8 @@ Image::powerOfTwo(int input) SubImage::SubImage(Image *parent, SDL_Surface *image, int x, int y, int width, int height): - Image(image), mParent(parent) + Image(image), + mParent(parent) { mParent->incRef(); @@ -368,7 +367,8 @@ SubImage::SubImage(Image *parent, SDL_Surface *image, SubImage::SubImage(Image *parent, GLuint image, int x, int y, int width, int height, int texWidth, int texHeight): - Image(image, width, height, texWidth, texHeight), mParent(parent) + Image(image, width, height, texWidth, texHeight), + mParent(parent) { mParent->incRef(); @@ -394,3 +394,4 @@ Image *SubImage::getSubImage(int x, int y, int w, int h) { return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); } + -- cgit v1.2.3-70-g09d2