00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/widgets/desktop.h"
00023
00024 #include "gui/palette.h"
00025 #include "gui/widgets/label.h"
00026
00027 #include "resources/image.h"
00028 #include "resources/resourcemanager.h"
00029 #include "resources/wallpaper.h"
00030
00031 #include "graphics.h"
00032 #include "log.h"
00033 #include "main.h"
00034
00035 Desktop::Desktop()
00036 : mWallpaper(0)
00037 {
00038 addWidgetListener(this);
00039
00040 Wallpaper::loadWallpapers();
00041
00042 gcn::Label *versionLabel = new Label(FULL_VERSION);
00043 add(versionLabel, 25, 2);
00044 }
00045
00046 Desktop::~Desktop()
00047 {
00048 if (mWallpaper)
00049 mWallpaper->decRef();
00050 }
00051
00052 void Desktop::reloadWallpaper()
00053 {
00054 Wallpaper::loadWallpapers();
00055 setBestFittingWallpaper();
00056 }
00057
00058 void Desktop::widgetResized(const gcn::Event &event)
00059 {
00060 setBestFittingWallpaper();
00061 }
00062
00063 void Desktop::draw(gcn::Graphics *graphics)
00064 {
00065 Graphics *g = static_cast<Graphics *>(graphics);
00066
00067 if (!mWallpaper || (getWidth() > mWallpaper->getWidth() ||
00068 getHeight() > mWallpaper->getHeight()))
00069 {
00070
00071 g->setColor(gcn::Color(64, 64, 64));
00072 g->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
00073 }
00074
00075 if (mWallpaper)
00076 {
00077 g->drawImage(mWallpaper,
00078 (getWidth() - mWallpaper->getWidth()) / 2,
00079 (getHeight() - mWallpaper->getHeight()) / 2);
00080 }
00081
00082 Container::draw(graphics);
00083 }
00084
00085 void Desktop::setBestFittingWallpaper()
00086 {
00087 const std::string wallpaperName =
00088 Wallpaper::getWallpaper(getWidth(), getHeight());
00089
00090 Image *temp = ResourceManager::getInstance()->getImage(wallpaperName);
00091
00092 if (temp)
00093 {
00094 if (mWallpaper)
00095 mWallpaper->decRef();
00096 mWallpaper = temp;
00097 }
00098 else
00099 {
00100 logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
00101 }
00102 }