summaryrefslogtreecommitdiff
path: root/src/gui/speechbubble.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/speechbubble.cpp')
-rw-r--r--src/gui/speechbubble.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 165d216f..73ada2e1 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -29,14 +29,17 @@
#include "speechbubble.h"
#include "textbox.h"
+#include "../graphics.h"
+
#include "../utils/gettext.h"
SpeechBubble::SpeechBubble():
- Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml")
+ Popup("Speech", NULL, "graphics/gui/speechbubble.xml"),
+ mText("")
{
setContentSize(140, 46);
- setShowTitle(false);
- setTitleBarHeight(0);
+ setMinWidth(29);
+ setMinHeight(29);
mCaption = new gcn::Label("");
mCaption->setFont(boldFont);
@@ -45,6 +48,7 @@ SpeechBubble::SpeechBubble():
mSpeechBox = new TextBox;
mSpeechBox->setEditable(false);
mSpeechBox->setOpaque(false);
+ mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT));
mSpeechArea = new ScrollArea(mSpeechBox);
@@ -56,26 +60,29 @@ SpeechBubble::SpeechBubble():
add(mCaption);
add(mSpeechArea);
-
- setLocationRelativeTo(getParent());
}
-void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color)
+void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color)
{
mCaption->setCaption(name);
mCaption->adjustSize();
- mCaption->setForegroundColor(color);
+ mCaption->setForegroundColor(*color);
}
-void SpeechBubble::setText(std::string mText, bool showName)
+void SpeechBubble::setText(std::string text, bool showName)
{
+ if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth()))
+ return;
+
+ graphics->setColor(guiPalette->getColor(Palette::TEXT));
+
int width = mCaption->getWidth();
- mSpeechBox->setTextWrapped(mText, 130 > width ? 130 : width);
+ mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width);
const int fontHeight = getFont()->getHeight();
const int numRows = showName ? mSpeechBox->getNumberOfRows() + 1 :
mSpeechBox->getNumberOfRows();
- int yPos = showName ? fontHeight + 3 : 3;
+ int yPos = showName ? fontHeight + getPadding() : getPadding();
int height = (numRows * fontHeight);
if (width < mSpeechBox->getMinWidth())
@@ -83,11 +90,11 @@ void SpeechBubble::setText(std::string mText, bool showName)
if (numRows == 1)
{
- yPos = (fontHeight / 4) + 3;
+ yPos = (fontHeight / 4) + getPadding();
height = ((3 * fontHeight) / 2) + 1;
}
- setContentSize(width + fontHeight, height + 6);
+ setContentSize(width + fontHeight, height + getPadding());
mSpeechArea->setDimension(gcn::Rectangle(4, yPos, width + 5, height));
}