Mana
Loading...
Searching...
No Matches
checkbox.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World 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
23
24#include "gui/gui.h"
25#include "resources/theme.h"
26
27#include <guichan/font.hpp>
28
29CheckBox::CheckBox(const std::string &caption, bool selected)
30 : gcn::CheckBox(caption, selected)
31{
32 auto &skin = gui->getTheme()->getSkin(SkinType::CheckBox);
33 setWidth(skin.getMinWidth() + 2 * skin.padding + skin.spacing + getFont()->getWidth(caption));
34 setHeight(skin.getMinHeight() + 2 * skin.padding);
35}
36
37void CheckBox::draw(gcn::Graphics* graphics)
38{
39 WidgetState widgetState(this);
40 if (mHasMouse)
41 widgetState.flags |= STATE_HOVERED;
42 if (isSelected())
43 widgetState.flags |= STATE_SELECTED;
44
45 auto g = static_cast<Graphics *>(graphics);
46 auto &skin = gui->getTheme()->getSkin(SkinType::CheckBox);
47 skin.draw(g, widgetState);
48
49 if (auto skinState = skin.getState(widgetState.flags))
50 {
51 auto &textFormat = skinState->textFormat;
52 g->drawText(getCaption(),
53 skin.getMinWidth() + skin.padding + skin.spacing,
54 skin.padding,
55 Graphics::LEFT,
56 textFormat.bold ? boldFont : getFont(),
57 textFormat);
58 }
59}
60
61void CheckBox::mouseEntered(gcn::MouseEvent& event)
62{
63 mHasMouse = true;
64}
65
66void CheckBox::mouseExited(gcn::MouseEvent& event)
67{
68 mHasMouse = false;
69}
Check box widget.
Definition checkbox.h:32
void mouseEntered(gcn::MouseEvent &event) override
Called when the mouse enteres the widget area.
Definition checkbox.cpp:61
CheckBox(const std::string &caption, bool selected=false)
Definition checkbox.cpp:29
bool mHasMouse
Definition checkbox.h:57
void draw(gcn::Graphics *graphics) override
Draws the caption, then calls drawBox to draw the check box.
Definition checkbox.cpp:37
void mouseExited(gcn::MouseEvent &event) override
Called when the mouse leaves the widget area.
Definition checkbox.cpp:66
A central point of control for graphics.
Definition graphics.h:78
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
void draw(Graphics *graphics, const WidgetState &state) const
Definition theme.cpp:122
const Skin & getSkin(SkinType skinType) const
Definition theme.cpp:434
Graphics * graphics
Definition client.cpp:104
Gui * gui
The GUI system.
Definition gui.cpp:50
gcn::Font * boldFont
Bolded text font.
Definition gui.cpp:54
uint8_t flags
Definition theme.h:150
@ STATE_HOVERED
Definition theme.h:105
@ STATE_SELECTED
Definition theme.h:106