diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-04-10 00:15:14 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-04-10 00:15:14 +0200 |
commit | e36861eaef6f178543bd1029809da3ce1bab0e55 (patch) | |
tree | 2aca21da04f8c7816e4cb93fa7327a1b1b36ad52 /src | |
parent | 9b680f95087290315c24a04535f1626acd8ec9a7 (diff) | |
download | mana-client-e36861eaef6f178543bd1029809da3ce1bab0e55.tar.gz mana-client-e36861eaef6f178543bd1029809da3ce1bab0e55.tar.bz2 mana-client-e36861eaef6f178543bd1029809da3ce1bab0e55.tar.xz mana-client-e36861eaef6f178543bd1029809da3ce1bab0e55.zip |
Some tweaks to wallpaper loading code
Mainly to conform better with coding conventions.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/resourcemanager.h | 6 | ||||
-rw-r--r-- | src/resources/wallpaper.cpp | 56 | ||||
-rw-r--r-- | src/resources/wallpaper.h | 1 |
3 files changed, 32 insertions, 31 deletions
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 828c5b0a..17ce7cae 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -48,13 +48,11 @@ class ResourceManager typedef Resource *(*loader)(void *, unsigned); typedef Resource *(*generator)(void *); - /** - * Constructor. - */ ResourceManager(); /** - * Destructor. + * Destructor. Cleans up remaining resources, warning about resources + * that were still referenced. */ ~ResourceManager(); diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 2c8c4a00..07f6ecb6 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -19,35 +19,36 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <algorithm> -#include <cstring> -#include <physfs.h> - #include "resources/wallpaper.h" #include "log.h" #include "utils/strprintf.h" -#define WALLPAPER_FOLDER "graphics/images/" +#include <algorithm> +#include <cstring> +#include <vector> -#define WALLPAPER_BASE "login_wallpaper" +#include <physfs.h> -struct wallpaper { - Uint16 width; - Uint16 height; +#define WALLPAPER_FOLDER "graphics/images/" +#define WALLPAPER_BASE "login_wallpaper" + +struct WallpaperSize +{ + int width; + int height; }; -std::vector<struct wallpaper> wallpapers; -bool haveBackup; // Is the backup (no size given) version availabnle? +static std::vector<WallpaperSize> wallpaperSizes; +static bool haveBackup; // Is the backup (no size given) version available? -bool wallpaperCompare(struct wallpaper x, struct wallpaper y) +bool wallpaperCompare(WallpaperSize a, WallpaperSize b) { - int aX = x.width * x.height; - int aY = y.width * y.height; + int aa = a.width * a.height; + int ab = b.width * b.height; - if (aX > aY || (aX == aY && x.width > y.width)) return true; - return false; + return (aa > ab || (aa == ab && a.width > b.width)); } void Wallpaper::loadWallpapers() @@ -58,7 +59,7 @@ void Wallpaper::loadWallpapers() int width; int height; - wallpapers.clear(); + wallpaperSizes.clear(); haveBackup = false; @@ -76,33 +77,36 @@ void Wallpaper::loadWallpapers() else if (sscanf(*i, WALLPAPER_BASE "_%dx%d.png", &width, &height) == 2) { - struct wallpaper wp; + WallpaperSize wp; wp.width = width; wp.height = height; - wallpapers.push_back(wp); + wallpaperSizes.push_back(wp); } } } PHYSFS_freeList(imgs); - std::sort(wallpapers.begin(), wallpapers.end(), wallpaperCompare); + std::sort(wallpaperSizes.begin(), wallpaperSizes.end(), wallpaperCompare); } std::string Wallpaper::getWallpaper(int width, int height) { - std::vector<wallpaper>::iterator iter; - wallpaper wp; + std::vector<WallpaperSize>::iterator iter; + WallpaperSize wp; - for(iter = wallpapers.begin(); iter != wallpapers.end(); iter++) + for (iter = wallpaperSizes.begin(); iter != wallpaperSizes.end(); iter++) { wp = *iter; if (wp.width <= width && wp.height <= height) + { return std::string(strprintf(WALLPAPER_FOLDER WALLPAPER_BASE - "_%dx%d.png", wp.width, wp.height)); + "_%dx%d.png", wp.width, wp.height)); + } } - if (haveBackup) return std::string(WALLPAPER_FOLDER WALLPAPER_BASE ".png"); + if (haveBackup) + return std::string(WALLPAPER_FOLDER WALLPAPER_BASE ".png"); - return std::string(""); + return std::string(); } diff --git a/src/resources/wallpaper.h b/src/resources/wallpaper.h index 9a0a3585..96a655e8 100644 --- a/src/resources/wallpaper.h +++ b/src/resources/wallpaper.h @@ -23,7 +23,6 @@ #define WALLPAPER_H #include <string> -#include <vector> #include <SDL_types.h> |