blob: b2779c4fae3caf389715f350c0f00f1df9e552e2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* The Mana Client
* Copyright (C) 2008-2009 The Mana World Development Team
* Copyright (C) 2009-2012 The Mana Developers
*
* This file is part of The Mana Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gui/widgets/tab.h"
#include "graphics.h"
#include "gui/gui.h"
#include "gui/widgets/label.h"
#include "gui/widgets/tabbedarea.h"
#include "resources/theme.h"
#include <guichan/widgets/label.hpp>
Tab::Tab()
{
setFocusable(false);
// Replace the label with customized version
delete mLabel;
mLabel = new Label();
add(mLabel);
auto &skin = gui->getTheme()->getSkin(SkinType::Tab);
setFrameSize(skin.frameSize);
mPadding = skin.padding;
mLabel->setPosition(mPadding, mPadding);
}
void Tab::setCaption(const std::string &caption)
{
mLabel->setCaption(caption);
mLabel->adjustSize();
setSize(mLabel->getWidth() + mPadding * 2,
mLabel->getHeight() + mPadding * 2);
if (mTabbedArea)
static_cast<TabbedArea*>(mTabbedArea)->adjustTabPositions();
}
void Tab::draw(gcn::Graphics *graphics)
{
if (getFrameSize() == 0)
drawFrame(graphics);
// if tab is selected, it doesnt need to highlight activity
if (mTabbedArea && mTabbedArea->isTabSelected(this))
mFlash = false;
uint8_t flags = 0;
if (mHasMouse)
flags |= STATE_HOVERED;
if (mTabbedArea && mTabbedArea->isTabSelected(this))
flags |= STATE_SELECTED;
auto &skin = gui->getTheme()->getSkin(SkinType::Tab);
if (auto state = skin.getState(flags))
{
gcn::Color foregroundColor = state->textFormat.color;
if (mFlash)
foregroundColor = Theme::getThemeColor(Theme::TAB_FLASH);
else if (mTabColor)
foregroundColor = *mTabColor;
auto label = static_cast<Label*>(mLabel);
label->setForegroundColor(foregroundColor);
label->setOutlineColor(state->textFormat.outlineColor);
label->setShadowColor(state->textFormat.shadowColor);
}
// draw label
drawChildren(graphics);
}
void Tab::drawFrame(gcn::Graphics *graphics)
{
WidgetState state(this);
state.width += getFrameSize() * 2;
state.height += getFrameSize() * 2;
if (mHasMouse)
state.flags |= STATE_HOVERED;
if (mTabbedArea && mTabbedArea->isTabSelected(this))
state.flags |= STATE_SELECTED;
gui->getTheme()->drawSkin(static_cast<Graphics *>(graphics), SkinType::Tab, state);
}
void Tab::setTabColor(const gcn::Color *color)
{
mTabColor = color;
}
void Tab::setFlash(bool flash)
{
mFlash = flash;
}
|