Mana
Loading...
Searching...
No Matches
desktop.cpp
Go to the documentation of this file.
1/*
2 * Desktop widget
3 * Copyright (c) 2009-2010 The Mana World Development Team
4 * Copyright (C) 2010-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/widgets/desktop.h"
23
24#include "configuration.h"
25#include "graphics.h"
26#include "log.h"
27#include "main.h"
28
29#include "gui/widgets/label.h"
30
31#include "resources/image.h"
33#include "resources/wallpaper.h"
34
35#include "utils/stringutils.h"
36
38{
39 addWidgetListener(this);
40
42
43 std::string appName = branding.getValue("appName", "");
44
45 if (appName.empty())
47 else
48 mVersionLabel = new Label(strprintf("%s (%s)", appName.c_str(),
50
51 mVersionLabel->setBackgroundColor(gcn::Color(255, 255, 255, 128));
52 add(mVersionLabel, 25, 2);
53}
54
55Desktop::~Desktop() = default;
56
62
63void Desktop::widgetResized(const gcn::Event &)
64{
66}
67
68void Desktop::draw(gcn::Graphics *graphics)
69{
70 auto *g = static_cast<Graphics *>(graphics);
71
72 if (mWallpaper)
73 {
74 g->drawRescaledImage(mWallpaper, 0, 0, 0, 0,
76 getWidth(), getHeight(), false);
77 }
78 else
79 {
81 }
82
83 // Draw a background beneath the application version for readability...
84 g->setColor(gcn::Color(255, 255, 255, 128));
85 g->fillRectangle(mVersionLabel->getDimension());
86
87 Container::draw(graphics);
88}
89
91{
92 const int width = getWidth();
93 const int height = getHeight();
94
95 if (width == 0 || height == 0)
96 return;
97
98 const std::string wallpaperName = Wallpaper::getWallpaper(width, height);
99
100 if (wallpaperName.empty())
101 return;
102
104 auto wallpaper = resman->getImage(wallpaperName);
105
106 if (wallpaper)
107 {
108 mWallpaper = std::move(wallpaper);
109 }
110 else
111 {
112 Log::info("Couldn't load %s as wallpaper", wallpaperName.c_str());
113 }
114}
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
void setBestFittingWallpaper()
Definition desktop.cpp:90
void reloadWallpaper()
Has to be called after updates have been loaded.
Definition desktop.cpp:57
gcn::Label * mVersionLabel
Definition desktop.h:66
ResourceRef< Image > mWallpaper
Definition desktop.h:65
~Desktop() override
Desktop()
Definition desktop.cpp:37
void draw(gcn::Graphics *graphics) override
Definition desktop.cpp:68
void widgetResized(const gcn::Event &) override
Definition desktop.cpp:63
A central point of control for graphics.
Definition graphics.h:78
bool drawRescaledImage(const Image *image, int x, int y, int width, int height)
Draws a rescaled version of the image.
Definition graphics.cpp:52
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
int getHeight() const
Returns the height of the image.
Definition image.h:89
int getWidth() const
Returns the width of the image.
Definition image.h:83
Label widget.
Definition label.h:34
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const
Definition theme.cpp:373
static void loadWallpapers()
Reads the folder that contains wallpapers and organizes the wallpapers found by area,...
Definition wallpaper.cpp:87
static std::string getWallpaper(int width, int height)
Returns the largest wallpaper for the given resolution, or the default wallpaper if none are found.
Graphics * graphics
Definition client.cpp:104
Configuration branding
XML branding information reader.
Definition client.cpp:98
Gui * gui
The GUI system.
Definition gui.cpp:50
#define FULL_VERSION
Definition main.h:55
void info(const char *log_text,...) LOG_PRINTF_ATTR
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.