1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-04 20:40:44 +03:00

The SurfaceCollection won't load the files selection.png, bottombar.png or topbar.png from the Default skin if they are missing in the current skin.

This commit is contained in:
Ayla 2011-07-11 13:34:52 +02:00
parent 11e58c8ca5
commit 3a85cabf37
3 changed files with 23 additions and 21 deletions

View File

@ -1377,7 +1377,7 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) {
if (menu != NULL) menu->loadIcons(); if (menu != NULL) menu->loadIcons();
//Selection png //Selection png
useSelectionPng = sc.addSkinRes("imgs/selection.png") != NULL; useSelectionPng = sc.addSkinRes("imgs/selection.png", false) != NULL;
//font //font
initFont(); initFont();
@ -2140,7 +2140,7 @@ void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint to
void GMenu2X::drawTopBar(Surface *s) { void GMenu2X::drawTopBar(Surface *s) {
if (s==NULL) s = this->s; if (s==NULL) s = this->s;
Surface *bar = sc.skinRes("imgs/topbar.png"); Surface *bar = sc.skinRes("imgs/topbar.png", false);
if (bar != NULL) if (bar != NULL)
bar->blit(s, 0, 0); bar->blit(s, 0, 0);
else else
@ -2151,7 +2151,7 @@ void GMenu2X::drawTopBar(Surface *s) {
void GMenu2X::drawBottomBar(Surface *s) { void GMenu2X::drawBottomBar(Surface *s) {
if (s==NULL) s = this->s; if (s==NULL) s = this->s;
Surface *bar = sc.skinRes("imgs/bottombar.png"); Surface *bar = sc.skinRes("imgs/bottombar.png", false);
if (bar != NULL) if (bar != NULL)
bar->blit(s, 0, resY-bar->height()); bar->blit(s, 0, resY-bar->height());
else else

View File

@ -55,12 +55,12 @@ string SurfaceCollection::getSkinPath(const string &skin)
return ""; return "";
} }
string SurfaceCollection::getSkinFilePath(const string &file) string SurfaceCollection::getSkinFilePath(const string &file, bool useDefault)
{ {
return SurfaceCollection::getSkinFilePath(skin, file); return SurfaceCollection::getSkinFilePath(skin, file, useDefault);
} }
string SurfaceCollection::getSkinFilePath(const string &skin, const string &file) string SurfaceCollection::getSkinFilePath(const string &skin, const string &file, bool useDefault)
{ {
/* We first search the skin file on the user-specific directory. */ /* We first search the skin file on the user-specific directory. */
string path = GMenu2X::getHome() + "/skins/" + skin + "/" + file; string path = GMenu2X::getHome() + "/skins/" + skin + "/" + file;
@ -75,9 +75,11 @@ string SurfaceCollection::getSkinFilePath(const string &skin, const string &file
/* If it is nowhere to be found, as a last resort we check the /* If it is nowhere to be found, as a last resort we check the
* "Default" skin on the system directory for a corresponding * "Default" skin on the system directory for a corresponding
* (but probably not similar) file. */ * (but probably not similar) file. */
path = GMENU2X_SYSTEM_DIR "/skins/Default/" + file; if (useDefault) {
if (fileExists(path)) path = GMENU2X_SYSTEM_DIR "/skins/Default/" + file;
return path; if (fileExists(path))
return path;
}
return ""; return "";
} }
@ -100,8 +102,7 @@ Surface *SurfaceCollection::add(Surface *s, const string &path) {
} }
Surface *SurfaceCollection::add(const string &path) { Surface *SurfaceCollection::add(const string &path) {
DEBUG("Adding surface: '%s'\n", path.c_str()); if (path.empty()) return NULL;
if (exists(path)) del(path); if (exists(path)) del(path);
string filePath = path; string filePath = path;
@ -111,6 +112,7 @@ Surface *SurfaceCollection::add(const string &path) {
return NULL; return NULL;
} else if (!fileExists(filePath)) return NULL; } else if (!fileExists(filePath)) return NULL;
DEBUG("Adding surface: '%s'\n", path.c_str());
Surface *s = Surface::loadImage(filePath); Surface *s = Surface::loadImage(filePath);
if (s != NULL) { if (s != NULL) {
surfaces[path] = s; surfaces[path] = s;
@ -118,15 +120,15 @@ Surface *SurfaceCollection::add(const string &path) {
return s; return s;
} }
Surface *SurfaceCollection::addSkinRes(const string &path) { Surface *SurfaceCollection::addSkinRes(const string &path, bool useDefault) {
DEBUG("Adding skin surface: '%s'\n", path.c_str());
if (path.empty()) return NULL; if (path.empty()) return NULL;
if (exists(path)) del(path); if (exists(path)) del(path);
string skinpath = getSkinFilePath(path); string skinpath = getSkinFilePath(path, useDefault);
if (skinpath.empty()) if (skinpath.empty())
return NULL; return NULL;
DEBUG("Adding skin surface: '%s'\n", path.c_str());
Surface *s = Surface::loadImage(skinpath); Surface *s = Surface::loadImage(skinpath);
if (s != NULL) { if (s != NULL) {
surfaces[path] = s; surfaces[path] = s;
@ -160,12 +162,12 @@ Surface *SurfaceCollection::operator[](const string &key) {
return i->second; return i->second;
} }
Surface *SurfaceCollection::skinRes(const string &key) { Surface *SurfaceCollection::skinRes(const string &key, bool useDefault) {
if (key.empty()) return NULL; if (key.empty()) return NULL;
SurfaceHash::iterator i = surfaces.find(key); SurfaceHash::iterator i = surfaces.find(key);
if (i == surfaces.end()) if (i == surfaces.end())
return addSkinRes(key); return addSkinRes(key, useDefault);
else else
return i->second; return i->second;
} }

View File

@ -38,8 +38,8 @@ public:
~SurfaceCollection(); ~SurfaceCollection();
void setSkin(const std::string &skin); void setSkin(const std::string &skin);
std::string getSkinFilePath(const std::string &file); std::string getSkinFilePath(const std::string &file, bool useDefault = true);
static std::string getSkinFilePath(const std::string &skin, const std::string &file); static std::string getSkinFilePath(const std::string &skin, const std::string &file, bool useDefault = true);
static std::string getSkinPath(const std::string &skin); static std::string getSkinPath(const std::string &skin);
bool defaultAlpha; bool defaultAlpha;
@ -47,14 +47,14 @@ public:
Surface *add(Surface *s, const std::string &path); Surface *add(Surface *s, const std::string &path);
Surface *add(const std::string &path); Surface *add(const std::string &path);
Surface *addSkinRes(const std::string &path); Surface *addSkinRes(const std::string &path, bool useDefault = true);
void del(const std::string &path); void del(const std::string &path);
void clear(); void clear();
void move(const std::string &from, const std::string &to); void move(const std::string &from, const std::string &to);
bool exists(const std::string &path); bool exists(const std::string &path);
Surface *operator[](const std::string &); Surface *operator[](const std::string &);
Surface *skinRes(const std::string &); Surface *skinRes(const std::string &key, bool useDefault = true);
private: private:
SurfaceHash surfaces; SurfaceHash surfaces;