diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-07-12 01:22:46 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-07-13 01:02:41 +0300 |
commit | f42921c0597101b5d6f10afa68d0ffc6f6d1a66f (patch) | |
tree | ed11947780a97e2989cff78a2eb6537c7109d8d6 /src/resources/resourcemanager.cpp | |
parent | c3b31b434fa392e22783d4a4b7fb007245c605db (diff) | |
download | plus-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.tar.gz plus-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.tar.bz2 plus-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.tar.xz plus-f42921c0597101b5d6f10afa68d0ffc6f6d1a66f.zip |
Add to resourcemanager method to load subimage.
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r-- | src/resources/resourcemanager.cpp | 35 |
1 files changed, 35 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; |