GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/popups/speechbubble.cpp Lines: 17 37 45.9 %
Date: 2017-11-29 Branches: 17 40 42.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  The Legend of Mazzeroth Development Team
4
 *  Copyright (C) 2008-2009  The Mana World Development Team
5
 *  Copyright (C) 2009-2010  The Mana Developers
6
 *  Copyright (C) 2011-2017  The ManaPlus Developers
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "gui/popups/speechbubble.h"
25
26
#include "gui/gui.h"
27
#include "gui/skin.h"
28
#include "gui/viewport.h"
29
30
#include "gui/fonts/font.h"
31
32
#include "gui/widgets/label.h"
33
#include "gui/widgets/staticbrowserbox.h"
34
35
#include "debug.h"
36
37
2
SpeechBubble::SpeechBubble() :
38
    Popup("Speech", "speechbubble.xml"),
39
    mText(),
40


8
    mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 2),
41

2
    mCaption(new Label(this)),
42
    mSpeechBox(new StaticBrowserBox(this, Opaque_true,
43



26
        "speechbrowserbox.xml"))
44
{
45
2
    setContentSize(140, 46);
46
2
    setMinWidth(8);
47
2
    setMinHeight(8);
48
49
2
    mCaption->setFont(boldFont);
50
4
    mSpeechBox->setOpaque(Opaque_false);
51
6
    mSpeechBox->setForegroundColorAll(getThemeColor(ThemeColorId::BUBBLE_TEXT),
52
        getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE));
53
2
}
54
55
2
void SpeechBubble::postInit()
56
{
57
4
    Popup::postInit();
58
2
    add(mCaption);
59
2
    add(mSpeechBox);
60
2
}
61
62
void SpeechBubble::setCaption(const std::string &name,
63
                              const Color *const color1,
64
                              const Color *const color2)
65
{
66
    mCaption->setCaption(name);
67
    mCaption->adjustSize();
68
    mCaption->setForegroundColorAll(*color1, *color2);
69
}
70
71
void SpeechBubble::setText(const std::string &text, const bool showName)
72
{
73
    if (text == mText && (mCaption->getWidth() <= mSpeechBox->getWidth()))
74
        return;
75
76
    mSpeechBox->setForegroundColorAll(getThemeColor(ThemeColorId::BUBBLE_TEXT),
77
        getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE));
78
79
    int width = mCaption->getWidth();
80
    mSpeechBox->clearRows();
81
    mSpeechBox->addRow(text);
82
    mSpeechBox->updateHeight();
83
84
    const int speechWidth = mSpeechBox->getWidth();
85
    const int nameHeight = showName ? mCaption->getHeight() + mSpacing : 0;
86
87
    if (width < speechWidth)
88
        width = speechWidth;
89
90
    setContentSize(width, getFont()->getHeight() + nameHeight);
91
    mCaption->setPosition(0, 0);
92
    mSpeechBox->setPosition(0, nameHeight);
93
}
94
95
void SpeechBubble::requestMoveToBackground()
96
{
97
    windowContainer->moveWidgetAfter(viewport, this);
98
4
}