From 821732ebbc2760ec98e0097f38a962c67285d421 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 13 Feb 2005 14:10:15 +0000 Subject: Allow preservation of alpha channel when loading image resources, which is used to load alpha blended mouse cursor, which is now drawn instead of using the system cursor. --- src/resources/image.cpp | 11 +++++++++-- src/resources/image.h | 7 ++++++- src/resources/resource.h | 3 --- src/resources/resourcemanager.cpp | 12 ++++++------ src/resources/resourcemanager.h | 6 ++++-- 5 files changed, 25 insertions(+), 14 deletions(-) (limited to 'src/resources') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 15ef6708..f84826bb 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -26,6 +26,7 @@ #include #include #include "../graphic/graphic.h" +#include "resourcemanager.h" Image::Image(SDL_Surface *image): image(image) @@ -37,7 +38,7 @@ Image::~Image() unload(); } -Image* Image::load(const std::string &filePath) +Image* Image::load(const std::string &filePath, int flags) { #ifdef __DEBUG std::cout << "Image::load(" << filePath << ")\n"; @@ -46,7 +47,13 @@ Image* Image::load(const std::string &filePath) SDL_Surface *tmpImage = IMG_Load(filePath.c_str()); SDL_SetColorKey(tmpImage, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(tmpImage->format, 255, 0, 255)); - SDL_Surface *image = SDL_DisplayFormat(tmpImage); + SDL_Surface *image = NULL; + if (flags & IMG_ALPHA) { + image = SDL_DisplayFormatAlpha(tmpImage); + } + else { + image = SDL_DisplayFormat(tmpImage); + } SDL_FreeSurface(tmpImage); // Check if the file was opened and return the appropriate value. diff --git a/src/resources/image.h b/src/resources/image.h index 1c2b58cf..bed75983 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -27,6 +27,11 @@ #include "resource.h" #include +// This flag causes image alpha channel to be preserved, otherwise masking is +// used. +#define IMG_ALPHA 1 + + // Forward declarations class SubImage; class ScaledImage; @@ -53,7 +58,7 @@ class Image : public Resource * @return true if the image was loaded * false otherwise. */ - static Image *load(const std::string &filePath); + static Image *load(const std::string &filePath, int flags); /** * Frees the resources created by SDL. diff --git a/src/resources/resource.h b/src/resources/resource.h index f1252c12..bd6bfcc5 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -24,9 +24,6 @@ #ifndef _TMW_RESOURCE_H #define _TMW_RESOURCE_H -#include -//#include - /** * A generic reference counted resource object. */ diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 0d936836..1a2c7a5f 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -21,9 +21,8 @@ * $Id$ */ -#include "../log.h" -#include "image.h" #include "resourcemanager.h" +#include "../log.h" #include #include @@ -71,7 +70,7 @@ ResourceManager::~ResourceManager() } Resource* ResourceManager::get(const E_RESOURCE_TYPE &type, - const std::string &idPath) + const std::string &idPath, int flags) { // Check if the id exists, and return the value if it does. std::map::iterator resIter = @@ -108,7 +107,8 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type, break; case IMAGE: // Attempt to create and load our image object. - resource = reinterpret_cast(Image::load(filePath)); + resource = + reinterpret_cast(Image::load(filePath, flags)); break; case SCRIPT: warning("Script resource not supported."); @@ -139,9 +139,9 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type, return resource; } -Image *ResourceManager::getImage(const std::string &idPath) +Image *ResourceManager::getImage(const std::string &idPath, int flags) { - return (Image*)get(IMAGE, idPath); + return (Image*)get(IMAGE, idPath, flags); } ResourceManager* ResourceManager::getInstance() diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 1b719b41..fe8b2a96 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -27,6 +27,7 @@ #include #include #include "resource.h" +#include "image.h" /** * A resource entry descriptor. @@ -80,12 +81,13 @@ class ResourceManager */ Resource *get( const E_RESOURCE_TYPE &type, - const std::string &idPath); + const std::string &idPath, + int flags = 0); /** * Convenience wrapper around ResourceManager::create. */ - Image *getImage(const std::string &idPath); + Image *getImage(const std::string &idPath, int flags = 0); /** * Returns an instance of the class, creating one if it does not -- cgit v1.2.3-70-g09d2