From fc70e6ca13c8134057bb0694e157d88e83b6ea17 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 6 Apr 2009 23:01:57 +0200 Subject: Modified speech bubble class to be less skin specific for positioning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ira Rice Signed-off-by: Bjørn Lindeijer --- src/gui/speechbubble.cpp | 39 +++++++++++++++++++-------------------- 1 file 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() -- cgit v1.2.3-70-g09d2