Mana
Loading...
Searching...
No Matches
label.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (c) 2009 Aethyra Development Team
4 * Copyright (C) 2009-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/label.h"
23
24#include "resources/theme.h"
25
26#include <guichan/exception.hpp>
27#include <guichan/font.hpp>
28
30{
31 setForegroundColor(Theme::getThemeColor(Theme::TEXT));
32}
33
34Label::Label(const std::string &caption) :
35 gcn::Label(caption)
36{
37 setForegroundColor(Theme::getThemeColor(Theme::TEXT));
38}
39
40void Label::draw(gcn::Graphics *graphics)
41{
42 int textX;
43 int textY = (getHeight() - getFont()->getHeight()) / 2;
44
45 switch (getAlignment())
46 {
47 case Graphics::LEFT:
48 textX = 0;
49 break;
50 case Graphics::CENTER:
51 textX = getWidth() / 2;
52 break;
53 case Graphics::RIGHT:
54 textX = getWidth();
55 break;
56 default:
57 throw GCN_EXCEPTION("Unknown alignment.");
58 }
59
60 auto g = static_cast<Graphics *>(graphics);
61 g->drawText(getCaption(),
62 textX,
63 textY,
64 getAlignment(),
65 getForegroundColor(),
66 getFont(),
67 mOutlineColor.has_value(),
68 mShadowColor.has_value(),
71}
A central point of control for graphics.
Definition graphics.h:78
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
Definition graphics.cpp:176
Label widget.
Definition label.h:34
std::optional< gcn::Color > mShadowColor
Definition label.h:61
void draw(gcn::Graphics *graphics) override
Draws the label.
Definition label.cpp:40
std::optional< gcn::Color > mOutlineColor
Definition label.h:60
Label()
Definition label.cpp:29
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
Definition theme.cpp:313
@ TEXT
Definition theme.h:214
Graphics * graphics
Definition client.cpp:104