Mana
Loading...
Searching...
No Matches
tab.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-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
22#include "gui/widgets/tab.h"
23
24#include "graphics.h"
25
26#include "gui/gui.h"
27#include "gui/widgets/label.h"
29
30#include "resources/theme.h"
31
32#include <guichan/widgets/label.hpp>
33
35{
36 setFocusable(false);
37
38 // Replace the label with customized version
39 delete mLabel;
40 mLabel = new Label();
41 add(mLabel);
42
43 auto &skin = gui->getTheme()->getSkin(SkinType::Tab);
44 setFrameSize(skin.frameSize);
45 mPadding = skin.padding;
46 mLabel->setPosition(mPadding, mPadding);
47}
48
49void Tab::setCaption(const std::string &caption)
50{
51 mLabel->setCaption(caption);
52 mLabel->adjustSize();
53
54 setSize(mLabel->getWidth() + mPadding * 2,
55 mLabel->getHeight() + mPadding * 2);
56
57 if (mTabbedArea)
58 static_cast<TabbedArea*>(mTabbedArea)->adjustTabPositions();
59}
60
61void Tab::draw(gcn::Graphics *graphics)
62{
63 if (getFrameSize() == 0)
65
66 // if tab is selected, it doesnt need to highlight activity
67 if (mTabbedArea && mTabbedArea->isTabSelected(this))
68 mFlash = false;
69
70 uint8_t flags = 0;
71 if (mHasMouse)
72 flags |= STATE_HOVERED;
73 if (mTabbedArea && mTabbedArea->isTabSelected(this))
74 flags |= STATE_SELECTED;
75
76 auto theme = gui->getTheme();
77 auto &palette = theme->getPalette(0);
78 auto &skin = theme->getSkin(SkinType::Tab);
79
80 if (auto state = skin.getState(flags))
81 {
82 gcn::Color foregroundColor = state->textFormat.color;
83 auto outlineColor = state->textFormat.outlineColor;
84 if (mFlash)
85 {
86 foregroundColor = palette.getColor(Theme::TAB_FLASH);
87 outlineColor = palette.getOutlineColor(Theme::TAB_FLASH);
88 }
89 else if (mTabColor)
90 {
91 foregroundColor = *mTabColor;
92 }
93
94 auto label = static_cast<Label*>(mLabel);
95 label->setForegroundColor(foregroundColor);
96 label->setOutlineColor(outlineColor);
97 label->setShadowColor(state->textFormat.shadowColor);
98 }
99
100 // draw label
101 drawChildren(graphics);
102}
103
104void Tab::drawFrame(gcn::Graphics *graphics)
105{
106 WidgetState state(this);
107 state.width += getFrameSize() * 2;
108 state.height += getFrameSize() * 2;
109 if (mHasMouse)
110 state.flags |= STATE_HOVERED;
111 if (mTabbedArea && mTabbedArea->isTabSelected(this))
112 state.flags |= STATE_SELECTED;
113
114 gui->getTheme()->drawSkin(static_cast<Graphics *>(graphics), SkinType::Tab, state);
115}
116
117void Tab::setTabColor(const gcn::Color *color)
118{
119 mTabColor = color;
120}
121
122void Tab::setFlash(bool flash)
123{
124 mFlash = flash;
125}
A central point of control for graphics.
Definition graphics.h:78
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
Label widget.
Definition label.h:34
void setOutlineColor(std::optional< gcn::Color > color)
Sets the color of the outline.
Definition label.h:64
const gcn::Color & getColor(int type) const
Gets the color associated with the type.
Definition palette.h:72
bool mFlash
Definition tab.h:70
Tab()
Definition tab.cpp:34
const gcn::Color * mTabColor
Definition tab.h:69
void drawFrame(gcn::Graphics *graphics) override
Draw the tab frame.
Definition tab.cpp:104
void setCaption(const std::string &caption)
Sets the caption of the tab.
Definition tab.cpp:49
void draw(gcn::Graphics *graphics) override
Draw the tab.
Definition tab.cpp:61
void setTabColor(const gcn::Color *color)
Set the normal color fo the tab's text.
Definition tab.cpp:117
void setFlash(bool flash)
Set tab flashing state.
Definition tab.cpp:122
int mPadding
Definition tab.h:71
A tabbed area, the same as the guichan tabbed area in 0.8, but extended.
Definition tabbedarea.h:40
const Skin & getSkin(SkinType skinType) const
Definition theme.cpp:434
const Palette & getPalette(size_t index) const
Definition theme.cpp:328
@ TAB_FLASH
Definition theme.h:233
void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const
Definition theme.cpp:373
Graphics * graphics
Definition client.cpp:104
Gui * gui
The GUI system.
Definition gui.cpp:50
unsigned char uint8_t
Definition sha256.cpp:81
uint8_t flags
Definition theme.h:150
int width
Definition theme.h:148
int height
Definition theme.h:149
@ STATE_HOVERED
Definition theme.h:105
@ STATE_SELECTED
Definition theme.h:106