ManaPlus
speechbubble.cpp
Go to the documentation of this file.
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 
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"
34 
35 #include "debug.h"
36 
38  Popup("Speech", "speechbubble.xml"),
39  mText(),
40  mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 2),
41  mCaption(new Label(this)),
42  mSpeechBox(new StaticBrowserBox(this, Opaque_true,
43  "speechbrowserbox.xml"))
44 {
45  setContentSize(140, 46);
46  setMinWidth(8);
47  setMinHeight(8);
48 
54 }
55 
57 {
59  add(mCaption);
60  add(mSpeechBox);
62 }
63 
64 void SpeechBubble::setCaption(const std::string &name,
65  const Color *const color1,
66  const Color *const color2)
67 {
68  mCaption->setCaption(name);
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 
81 
82  int width = mCaption->getWidth();
84  mSpeechBox->addRow(text,
85  false);
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 
100 {
102 }
Font * getFont() const
Definition: widget.cpp:330
void setContentSize(int width, int height)
Definition: popup.cpp:154
int getWidth() const
Definition: widget.h:220
Font * boldFont
Definition: gui.cpp:111
void setMinHeight(const int height)
Definition: popup.cpp:204
void moveWidgetAfter(Widget *const before, Widget *const widget)
WindowContainer * windowContainer
Label * mCaption
Definition: speechbubble.h:62
void postInit()
Definition: popup.h:176
void setMinWidth(const int width)
Definition: popup.cpp:191
void requestMoveToBackground()
#define new
Definition: debug_new.h:147
void setCaption(const std::string &caption)
Definition: label.cpp:261
Definition: label.h:87
virtual void add(Widget *const widget)
#define nullptr
Definition: localconsts.h:44
const bool Opaque_false
Definition: opaque.h:29
void setPosition(const int x, const int y)
Definition: widget.cpp:160
std::string mText
Definition: speechbubble.h:60
void setOpaque(Opaque opaque)
void setForegroundColorAll(const Color &color1, const Color &color2)
void setFont(Font *const font)
Definition: widget.cpp:348
const bool Opaque_true
Definition: opaque.h:29
int getHeight() const
Definition: widget.h:239
Definition: popup.h:48
Definition: color.h:74
StaticBrowserBox * mSpeechBox
Definition: speechbubble.h:63
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:214
void setCaption(const std::string &name, const Color *const color1, const Color *const color2)
void adjustSize()
Definition: label.cpp:197
Viewport * viewport
Definition: viewport.cpp:35
void addRow(const std::string &row, const bool atTop)
void setText(const std::string &text, const bool showName)