GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/popups/speechbubble.cpp Lines: 19 38 50.0 %
Date: 2018-05-19 03:07:18 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-2018  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(
52
        getThemeColor(ThemeColorId::BUBBLE_TEXT, 255U),
53
        getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE, 255U));
54
2
}
55
56
2
void SpeechBubble::postInit()
57
{
58
4
    Popup::postInit();
59
2
    add(mCaption);
60
2
    add(mSpeechBox);
61
2
    requestMoveToBackground();
62
2
}
63
64
void SpeechBubble::setCaption(const std::string &name,
65
                              const Color *const color1,
66
                              const Color *const color2)
67
{
68
    mCaption->setCaption(name);
69
    mCaption->adjustSize();
70
    mCaption->setForegroundColorAll(*color1, *color2);
71
}
72
73
void SpeechBubble::setText(const std::string &text, const bool showName)
74
{
75
    if (text == mText && (mCaption->getWidth() <= mSpeechBox->getWidth()))
76
        return;
77
78
    mSpeechBox->setForegroundColorAll(
79
        getThemeColor(ThemeColorId::BUBBLE_TEXT, 255U),
80
        getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE, 255U));
81
82
    int width = mCaption->getWidth();
83
    mSpeechBox->clearRows();
84
    mSpeechBox->addRow(text,
85
        false);
86
    mSpeechBox->updateHeight();
87
88
    const int speechWidth = mSpeechBox->getWidth();
89
    const int nameHeight = showName ? mCaption->getHeight() + mSpacing : 0;
90
91
    if (width < speechWidth)
92
        width = speechWidth;
93
94
    setContentSize(width, getFont()->getHeight() + nameHeight);
95
    mCaption->setPosition(0, 0);
96
    mSpeechBox->setPosition(0, nameHeight);
97
}
98
99
void SpeechBubble::requestMoveToBackground()
100
{
101
2
    windowContainer->moveWidgetAfter(viewport, this);
102
4
}