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-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 
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 
53 }
54 
56 {
58  add(mCaption);
59  add(mSpeechBox);
60 }
61 
62 void SpeechBubble::setCaption(const std::string &name,
63  const Color *const color1,
64  const Color *const color2)
65 {
66  mCaption->setCaption(name);
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 
78 
79  int width = mCaption->getWidth();
81  mSpeechBox->addRow(text);
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 
96 {
98 }
Font * getFont() const
Definition: widget.cpp:330
void setContentSize(int width, int height)
Definition: popup.cpp:151
int getWidth() const
Definition: widget.h:220
Font * boldFont
Definition: gui.cpp:111
void setMinHeight(const int height)
Definition: popup.cpp:201
void moveWidgetAfter(Widget *const before, Widget *const widget)
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha=255U) const A_INLINE
Definition: widget2.h:44
WindowContainer * windowContainer
Label * mCaption
Definition: speechbubble.h:63
void postInit()
Definition: popup.h:176
void setCaption(const std::string &name, const Color *const color1=&theme->getColor(ThemeColorId::BUBBLE_NAME, 255), const Color *const color2=&theme->getColor(ThemeColorId::BUBBLE_NAME_OUTLINE, 255))
void setMinWidth(const int width)
Definition: popup.cpp:188
void requestMoveToBackground()
#define new
Definition: debug_new.h:147
void setCaption(const std::string &caption)
Definition: label.cpp:256
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:61
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:64
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:209
void setText(const std::string &text, const bool showName=true)
void adjustSize()
Definition: label.cpp:192
Viewport * viewport
Definition: viewport.cpp:35
void addRow(const std::string &row, const bool atTop=false)