summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp11
-rw-r--r--src/resources/image.h7
-rw-r--r--src/resources/resource.h3
-rw-r--r--src/resources/resourcemanager.cpp12
-rw-r--r--src/resources/resourcemanager.h6
5 files changed, 25 insertions, 14 deletions
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 <iostream>
#include <SDL_image.h>
#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 <SDL.h>
+// 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 <code>true</code> if the image was loaded
* <code>false</code> 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 <string>
-//#include <SDL/SDL.h>
-
/**
* 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 <iostream>
#include <sstream>
@@ -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<std::string, ResourceEntry>::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<Resource*>(Image::load(filePath));
+ resource =
+ reinterpret_cast<Resource*>(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 <map>
#include <string>
#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