summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-12 01:22:46 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-13 01:02:41 +0300
commitf42921c0597101b5d6f10afa68d0ffc6f6d1a66f (patch)
treeed11947780a97e2989cff78a2eb6537c7109d8d6
parentc3b31b434fa392e22783d4a4b7fb007245c605db (diff)
downloadmv-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.tar.gz
mv-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.tar.bz2
mv-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.tar.xz
mv-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.zip
Add to resourcemanager method to load subimage.
-rw-r--r--src/resources/resourcemanager.cpp35
-rw-r--r--src/resources/resourcemanager.h3
2 files changed, 38 insertions, 0 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 452bc9942..2c4bc0f95 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -552,6 +552,41 @@ ImageSet *ResourceManager::getImageSet(const std::string &imagePath,
return static_cast<ImageSet*>(get(ss.str(), ImageSetLoader::load, &rl));
}
+struct SubImageLoader
+{
+ ResourceManager *manager;
+ Image *parent;
+ int x, y;
+ int width, height;
+ static Resource *load(void *v)
+ {
+ if (!v)
+ return nullptr;
+
+ SubImageLoader *rl = static_cast< SubImageLoader * >(v);
+ if (!rl->manager || !rl->parent)
+ return nullptr;
+
+ Image *res = rl->parent->getSubImage(rl->x, rl->y,
+ rl->width, rl->height);
+ return res;
+ }
+};
+
+SubImage *ResourceManager::getSubImage(Image *parent, int x, int y,
+ int width, int height)
+{
+ if (!parent)
+ return nullptr;
+
+ SubImageLoader rl = { this, parent, x, y, width, height};
+
+ std::stringstream ss;
+ ss << parent->getIdPath() << ",[" << x << "," << y << ","
+ << width << "x" << height << "]";
+ return reinterpret_cast<SubImage*>(get(ss.str(), SubImageLoader::load, &rl));
+}
+
struct SpriteDefLoader
{
std::string path;
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index b07b23431..b4892227e 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -38,6 +38,7 @@ class ImageSet;
class Music;
class Resource;
class SoundEffect;
+class SubImage;
class SpriteDef;
struct SDL_Surface;
@@ -202,6 +203,8 @@ class ResourceManager
*/
ImageSet *getImageSet(const std::string &imagePath, int w, int h);
+ SubImage *getSubImage(Image *parent, int x, int y, int width, int height);
+
/**
* Creates a sprite definition based on a given path and the supplied
* variant.