From e36861eaef6f178543bd1029809da3ce1bab0e55 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 10 Apr 2009 00:15:14 +0200 Subject: Some tweaks to wallpaper loading code Mainly to conform better with coding conventions. --- src/resources/wallpaper.cpp | 56 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'src/resources/wallpaper.cpp') 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 -#include -#include - #include "resources/wallpaper.h" #include "log.h" #include "utils/strprintf.h" -#define WALLPAPER_FOLDER "graphics/images/" +#include +#include +#include -#define WALLPAPER_BASE "login_wallpaper" +#include -struct wallpaper { - Uint16 width; - Uint16 height; +#define WALLPAPER_FOLDER "graphics/images/" +#define WALLPAPER_BASE "login_wallpaper" + +struct WallpaperSize +{ + int width; + int height; }; -std::vector wallpapers; -bool haveBackup; // Is the backup (no size given) version availabnle? +static std::vector 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::iterator iter; - wallpaper wp; + std::vector::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(); } -- cgit v1.2.3-60-g2f50