From 3a85cabf37da9d38f7ce02175d356fd047fc0f8e Mon Sep 17 00:00:00 2001 From: Ayla Date: Mon, 11 Jul 2011 13:34:52 +0200 Subject: [PATCH] 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. --- src/gmenu2x.cpp | 6 +++--- src/surfacecollection.cpp | 30 ++++++++++++++++-------------- src/surfacecollection.h | 8 ++++---- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 599323f..aa15140 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -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 diff --git a/src/surfacecollection.cpp b/src/surfacecollection.cpp index 974dda2..aa63b4b 100644 --- a/src/surfacecollection.cpp +++ b/src/surfacecollection.cpp @@ -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; } diff --git a/src/surfacecollection.h b/src/surfacecollection.h index 2c63acd..4841ecb 100644 --- a/src/surfacecollection.h +++ b/src/surfacecollection.h @@ -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;