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-2019 The ManaPlus Developers
7  * Copyright (C) 2019-2021 Andrei Karas
8  *
9  * This file is part of The ManaPlus Client.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
26 
27 #include "gui/gui.h"
28 #include "gui/skin.h"
29 #include "gui/viewport.h"
30 
31 #include "gui/fonts/font.h"
32 
33 #include "gui/widgets/label.h"
35 
36 #include "debug.h"
37 
39  Popup("Speech", "speechbubble.xml"),
40  mText(),
41  mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 2),
42  mCaption(new Label(this)),
43  mSpeechBox(new StaticBrowserBox(this, Opaque_true,
44  "speechbrowserbox.xml"))
45 {
46  setContentSize(140, 46);
47  setMinWidth(8);
48  setMinHeight(8);
49 
53  getThemeColor(ThemeColorId::BUBBLE_TEXT, 255U),
54  getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE, 255U));
55 }
56 
58 {
60  add(mCaption);
61  add(mSpeechBox);
63 }
64 
65 void SpeechBubble::setCaption(const std::string &name,
66  const Color *const color1,
67  const Color *const color2)
68 {
69  mCaption->setCaption(name);
71  mCaption->setForegroundColorAll(*color1, *color2);
72 }
73 
74 void SpeechBubble::setText(const std::string &text, const bool showName)
75 {
76  if (text == mText && (mCaption->getWidth() <= mSpeechBox->getWidth()))
77  return;
78 
80  getThemeColor(ThemeColorId::BUBBLE_TEXT, 255U),
81  getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE, 255U));
82 
83  int width = mCaption->getWidth();
85  mSpeechBox->addRow(text,
86  false);
88 
89  const int speechWidth = mSpeechBox->getWidth();
90  const int nameHeight = showName ? mCaption->getHeight() + mSpacing : 0;
91 
92  if (width < speechWidth)
93  width = speechWidth;
94 
95  setContentSize(width, getFont()->getHeight() + nameHeight);
96  mCaption->setPosition(0, 0);
97  mSpeechBox->setPosition(0, nameHeight);
98 }
99 
101 {
103 }
virtual void add(Widget *const widget)
Definition: color.h:76
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:217
void setCaption(const std::string &caption)
Definition: label.cpp:264
Definition: popup.h:52
void setMinHeight(const int height)
Definition: popup.cpp:207
void setMinWidth(const int width)
Definition: popup.cpp:194
void setContentSize(int width, int height)
Definition: popup.cpp:155
void postInit()
Definition: popup.h:177
StaticBrowserBox * mSpeechBox
Definition: speechbubble.h:64
void setCaption(const std::string &name, const Color *const color1, const Color *const color2)
void requestMoveToBackground()
std::string mText
Definition: speechbubble.h:61
void setText(const std::string &text, const bool showName)
Label * mCaption
Definition: speechbubble.h:63
void addRow(const std::string &row, const bool atTop)
void setForegroundColorAll(const Color &color1, const Color &color2)
void setOpaque(Opaque opaque)
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
void setFont(Font *const font)
Definition: widget.cpp:349
Font * getFont() const
Definition: widget.cpp:331
void setPosition(const int x, const int y)
Definition: widget.cpp:161
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
void moveWidgetAfter(Widget *const before, Widget *const widget)
#define new
Definition: debug_new.h:147
Viewport * viewport
Definition: viewport.cpp:36
Font * boldFont
Definition: gui.cpp:112
#define nullptr
Definition: localconsts.h:45
const bool Opaque_false
Definition: opaque.h:30
const bool Opaque_true
Definition: opaque.h:30
WindowContainer * windowContainer