mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 13:44:04 +02: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:
parent
11e58c8ca5
commit
3a85cabf37
@ -1377,7 +1377,7 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) {
|
||||
if (menu != NULL) menu->loadIcons();
|
||||
|
||||
//Selection png
|
||||
useSelectionPng = sc.addSkinRes("imgs/selection.png") != NULL;
|
||||
useSelectionPng = sc.addSkinRes("imgs/selection.png", false) != NULL;
|
||||
|
||||
//font
|
||||
initFont();
|
||||
@ -2140,7 +2140,7 @@ void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint to
|
||||
void GMenu2X::drawTopBar(Surface *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)
|
||||
bar->blit(s, 0, 0);
|
||||
else
|
||||
@ -2151,7 +2151,7 @@ void GMenu2X::drawTopBar(Surface *s) {
|
||||
void GMenu2X::drawBottomBar(Surface *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)
|
||||
bar->blit(s, 0, resY-bar->height());
|
||||
else
|
||||
|
@ -55,12 +55,12 @@ string SurfaceCollection::getSkinPath(const string &skin)
|
||||
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. */
|
||||
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
|
||||
* "Default" skin on the system directory for a corresponding
|
||||
* (but probably not similar) file. */
|
||||
path = GMENU2X_SYSTEM_DIR "/skins/Default/" + file;
|
||||
if (fileExists(path))
|
||||
return path;
|
||||
if (useDefault) {
|
||||
path = GMENU2X_SYSTEM_DIR "/skins/Default/" + file;
|
||||
if (fileExists(path))
|
||||
return path;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
@ -100,8 +102,7 @@ Surface *SurfaceCollection::add(Surface *s, 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);
|
||||
string filePath = path;
|
||||
|
||||
@ -111,6 +112,7 @@ Surface *SurfaceCollection::add(const string &path) {
|
||||
return NULL;
|
||||
} else if (!fileExists(filePath)) return NULL;
|
||||
|
||||
DEBUG("Adding surface: '%s'\n", path.c_str());
|
||||
Surface *s = Surface::loadImage(filePath);
|
||||
if (s != NULL) {
|
||||
surfaces[path] = s;
|
||||
@ -118,15 +120,15 @@ Surface *SurfaceCollection::add(const string &path) {
|
||||
return s;
|
||||
}
|
||||
|
||||
Surface *SurfaceCollection::addSkinRes(const string &path) {
|
||||
DEBUG("Adding skin surface: '%s'\n", path.c_str());
|
||||
|
||||
Surface *SurfaceCollection::addSkinRes(const string &path, bool useDefault) {
|
||||
if (path.empty()) return NULL;
|
||||
if (exists(path)) del(path);
|
||||
|
||||
string skinpath = getSkinFilePath(path);
|
||||
string skinpath = getSkinFilePath(path, useDefault);
|
||||
if (skinpath.empty())
|
||||
return NULL;
|
||||
|
||||
DEBUG("Adding skin surface: '%s'\n", path.c_str());
|
||||
Surface *s = Surface::loadImage(skinpath);
|
||||
if (s != NULL) {
|
||||
surfaces[path] = s;
|
||||
@ -160,12 +162,12 @@ Surface *SurfaceCollection::operator[](const string &key) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
Surface *SurfaceCollection::skinRes(const string &key) {
|
||||
Surface *SurfaceCollection::skinRes(const string &key, bool useDefault) {
|
||||
if (key.empty()) return NULL;
|
||||
|
||||
SurfaceHash::iterator i = surfaces.find(key);
|
||||
if (i == surfaces.end())
|
||||
return addSkinRes(key);
|
||||
return addSkinRes(key, useDefault);
|
||||
else
|
||||
return i->second;
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ public:
|
||||
~SurfaceCollection();
|
||||
|
||||
void setSkin(const std::string &skin);
|
||||
std::string getSkinFilePath(const std::string &file);
|
||||
static std::string getSkinFilePath(const std::string &skin, 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, bool useDefault = true);
|
||||
static std::string getSkinPath(const std::string &skin);
|
||||
|
||||
bool defaultAlpha;
|
||||
@ -47,14 +47,14 @@ public:
|
||||
|
||||
Surface *add(Surface *s, 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 clear();
|
||||
void move(const std::string &from, const std::string &to);
|
||||
bool exists(const std::string &path);
|
||||
|
||||
Surface *operator[](const std::string &);
|
||||
Surface *skinRes(const std::string &);
|
||||
Surface *skinRes(const std::string &key, bool useDefault = true);
|
||||
|
||||
private:
|
||||
SurfaceHash surfaces;
|
||||
|
Loading…
Reference in New Issue
Block a user