diff options
author | Ira Rice <irarice@gmail.com> | 2009-04-06 23:01:57 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-04-06 23:03:08 +0200 |
commit | fc70e6ca13c8134057bb0694e157d88e83b6ea17 (patch) | |
tree | 585d22d3a25e45365a6843ac3d1b1cef4cbaf4f2 /src/gui | |
parent | f0fd20fdd649eb61fa0d2444d910a2b0882e3580 (diff) | |
download | mana-fc70e6ca13c8134057bb0694e157d88e83b6ea17.tar.gz mana-fc70e6ca13c8134057bb0694e157d88e83b6ea17.tar.bz2 mana-fc70e6ca13c8134057bb0694e157d88e83b6ea17.tar.xz mana-fc70e6ca13c8134057bb0694e157d88e83b6ea17.zip |
Modified speech bubble class to be less skin specific for positioning.
Signed-off-by: Ira Rice <irarice@gmail.com>
Signed-off-by: Bjørn Lindeijer <bjorn@lindeijer.nl>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/speechbubble.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 4fb3409c..2f765ab0 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -42,7 +42,6 @@ SpeechBubble::SpeechBubble(): mCaption = new gcn::Label; mCaption->setFont(boldFont); - mCaption->setPosition(5, 3); mSpeechBox = new TextBox; mSpeechBox->setEditable(false); @@ -53,8 +52,6 @@ SpeechBubble::SpeechBubble(): mSpeechArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mSpeechArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mSpeechArea->setDimension(gcn::Rectangle(4, boldFont->getHeight() + 3, - 130, 28)); mSpeechArea->setOpaque(false); add(mCaption); @@ -77,26 +74,28 @@ void SpeechBubble::setText(std::string text, bool showName) graphics->setColor(guiPalette->getColor(Palette::TEXT)); - int width = mCaption->getWidth(); + int width = mCaption->getWidth() + 2 * getPadding(); + const int speechWidth = mSpeechBox->getMinWidth() + 2 * getPadding(); 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 + getPadding() : getPadding(); - int height = (numRows * fontHeight); - - if (width < mSpeechBox->getMinWidth()) - width = mSpeechBox->getMinWidth(); - - if (numRows == 1) - { - yPos = (fontHeight / 4) + getPadding(); - height = ((3 * fontHeight) / 2) + 1; - } - - setContentSize(width + fontHeight, height + getPadding()); - mSpeechArea->setDimension(gcn::Rectangle(4, yPos, width + 5, height)); + const int nameHeight = showName ? mCaption->getHeight() + + getPadding() / 2 : 0; + const int numRows = mSpeechBox->getNumberOfRows(); + const int height = (numRows * fontHeight) + nameHeight + 2 * getPadding(); + + if (width < speechWidth) + width = speechWidth; + + width += 2 * getPadding(); + + setContentSize(width, height); + + const int xPos = ((getWidth() - width) / 2); + const int yPos = ((getHeight() - height) / 2) + nameHeight; + + mCaption->setPosition(xPos, getPadding()); + mSpeechArea->setDimension(gcn::Rectangle(xPos, yPos, width, height)); } unsigned int SpeechBubble::getNumRows() |