summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-14 12:39:24 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-14 12:39:24 +0300
commit8ba9dc8011a3b17d97828f9a8b800f8ad56459bf (patch)
tree08ed78a8911c288d7984af662f93836c9b8a6cf7
parenta42faf3f01378c00b2410905c7fb78f3b5270790 (diff)
downloadplus-8ba9dc8011a3b17d97828f9a8b800f8ad56459bf.tar.gz
plus-8ba9dc8011a3b17d97828f9a8b800f8ad56459bf.tar.bz2
plus-8ba9dc8011a3b17d97828f9a8b800f8ad56459bf.tar.xz
plus-8ba9dc8011a3b17d97828f9a8b800f8ad56459bf.zip
Add to resourcemanager method to load imageset from image.
-rw-r--r--src/gui/theme.cpp24
-rw-r--r--src/gui/theme.h2
-rw-r--r--src/resources/resourcemanager.cpp35
-rw-r--r--src/resources/resourcemanager.h2
4 files changed, 62 insertions, 1 deletions
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 4d22612fb..77fe24d51 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -895,3 +895,27 @@ Image *Theme::getImageFromThemeXml(const std::string &name)
}
return nullptr;
}
+
+ImageSet *Theme::getImageSetFromThemeXml(const std::string &name,
+ int w, int h)
+{
+ Theme *theme = Theme::instance();
+ Skin *skin = theme->load(name);
+ if (skin)
+ {
+ const ImageRect &rect = skin->getBorder();
+ if (rect.grid[0])
+ {
+ Image *image = rect.grid[0];
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ ImageSet *imageSet = resman->getSubImageSet(image, w, h);
+
+// image->incRef();
+ theme->unload(skin);
+ return imageSet;
+ }
+ theme->unload(skin);
+ }
+ return nullptr;
+}
diff --git a/src/gui/theme.h b/src/gui/theme.h
index e2be8a232..56c0c57c7 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -148,6 +148,8 @@ class Theme : public Palette, public ConfigListener
static ImageSet *getImageSetFromTheme(const std::string &path,
int w, int h);
+ ImageSet *getImageSetFromThemeXml(const std::string &name,
+ int w, int h);
enum ThemePalette
{
TEXT = 0,
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index b88c4dbb5..8b9c4e3c0 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -552,6 +552,39 @@ ImageSet *ResourceManager::getImageSet(const std::string &imagePath,
return static_cast<ImageSet*>(get(ss.str(), ImageSetLoader::load, &rl));
}
+
+struct SubImageSetLoader
+{
+ ResourceManager *manager;
+ Image *parent;
+ int width, height;
+ static Resource *load(void *v)
+ {
+ if (!v)
+ return nullptr;
+
+ SubImageSetLoader *rl = static_cast< SubImageSetLoader * >(v);
+ if (!rl->manager)
+ return nullptr;
+
+ if (!rl->parent)
+ return nullptr;
+ ImageSet *res = new ImageSet(rl->parent, rl->width, rl->height);
+ return res;
+ }
+};
+
+ImageSet *ResourceManager::getSubImageSet(Image *parent, int width, int height)
+{
+ if (!parent)
+ return nullptr;
+
+ SubImageSetLoader rl = { this, parent, width, height };
+ std::stringstream ss;
+ ss << parent->getIdPath() << ", set[" << width << "x" << height << "]";
+ return static_cast<ImageSet*>(get(ss.str(), SubImageSetLoader::load, &rl));
+}
+
struct SubImageLoader
{
ResourceManager *manager;
@@ -574,7 +607,7 @@ struct SubImageLoader
};
Image *ResourceManager::getSubImage(Image *parent, int x, int y,
- int width, int height)
+ int width, int height)
{
if (!parent)
return nullptr;
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 7a1e517c0..6abd8732e 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -202,6 +202,8 @@ class ResourceManager
*/
ImageSet *getImageSet(const std::string &imagePath, int w, int h);
+ ImageSet *getSubImageSet(Image *parent, int width, int height);
+
Image *getSubImage(Image *parent, int x, int y, int width, int height);
/**