Mana
Loading...
Searching...
No Matches
speechbubble.cpp
Go to the documentation of this file.
1/*
2 * Speech bubbles
3 * Copyright (C) 2008 The Legend of Mazzeroth Development Team
4 * Copyright (C) 2008-2009 The Mana World Development Team
5 * Copyright (C) 2009-2012 The Mana Developers
6 *
7 * This file is part of The Mana Client.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include "gui/speechbubble.h"
24
25#include "gui/gui.h"
26
27#include "gui/widgets/label.h"
28#include "gui/widgets/textbox.h"
29
30#include <guichan/font.hpp>
31#include <guichan/widgets/label.hpp>
32
34 : Popup("Speech", SkinType::SpeechBubble)
35{
36 setMinWidth(0);
37 setMinHeight(0);
38
39 mCaption = new Label;
40 mCaption->setFont(boldFont);
41
42 mSpeechBox = new TextBox;
43 mSpeechBox->setEditable(false);
44 mSpeechBox->setOpaque(false);
46
49}
50
51void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color)
52{
53 mCaption->setCaption(name);
54 mCaption->adjustSize();
55 mCaption->setForegroundColor(*color);
56}
57
58void SpeechBubble::setText(const std::string &text, bool showName)
59{
60 if (text == mText && mCaption->getWidth() <= mSpeechBox->getMinWidth())
61 return;
62
63 int width = mCaption->getWidth();
64 mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width);
65 const int speechWidth = mSpeechBox->getMinWidth();
66
67 const int fontHeight = getFont()->getHeight();
68 const int nameHeight = showName ? mCaption->getHeight() +
69 (getPadding() / 2) : 0;
70 const int numRows = mSpeechBox->getNumberOfRows();
71 const int height = (numRows * fontHeight) + nameHeight;
72
73 if (width < speechWidth)
74 width = speechWidth;
75
76 setContentSize(width, height);
77
78 mCaption->setPosition(0, 0);
79 mSpeechBox->setPosition(0, nameHeight);
80}
Label widget.
Definition label.h:34
A light version of the Window class.
Definition popup.h:48
void setMinHeight(int height)
Sets the minimum height of the popup.
Definition popup.cpp:163
void add(gcn::Widget *widget) override
Definition popup.cpp:69
void setMinWidth(int width)
Sets the minimum width of the popup.
Definition popup.cpp:158
int getPadding() const
Gets the padding of the popup.
Definition popup.h:132
void setContentSize(int width, int height)
Sets the size of this popup.
Definition popup.cpp:127
void setCaption(const std::string &name, const gcn::Color *color=&Theme::getThemeColor(Theme::TEXT))
Sets the name displayed for the speech bubble, and in what color.
std::string mText
void setText(const std::string &text, bool showName=true)
Sets the text to be displayed.
TextBox * mSpeechBox
gcn::Label * mCaption
A text box, meant to be used inside a scroll area.
Definition textbox.h:36
void setTextColor(const gcn::Color *color)
Definition textbox.h:40
void setTextWrapped(const std::string &text, int minDimension)
Sets the text after wrapping it to the current width of the widget.
Definition textbox.cpp:42
int getMinWidth() const
Get the minimum text width for the text box.
Definition textbox.h:54
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
Definition theme.cpp:313
@ BUBBLE_TEXT
Definition theme.h:239
gcn::Font * boldFont
Bolded text font.
Definition gui.cpp:54
SkinType
Definition theme.h:69