00001 /* 00002 * Speech bubbles 00003 * Copyright (C) 2008 The Legend of Mazzeroth Development Team 00004 * Copyright (C) 2008 The Mana World Development Team 00005 * 00006 * This file is part of The Mana World. 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #include "gui/speechbubble.h" 00024 00025 #include "gui/gui.h" 00026 00027 #include "gui/widgets/textbox.h" 00028 00029 #include "graphics.h" 00030 00031 #include "utils/gettext.h" 00032 00033 #include <guichan/font.hpp> 00034 #include <guichan/widgets/label.hpp> 00035 00036 SpeechBubble::SpeechBubble(): 00037 Popup("Speech", "graphics/gui/speechbubble.xml") 00038 { 00039 setContentSize(140, 46); 00040 setMinWidth(29); 00041 setMinHeight(29); 00042 00043 mCaption = new gcn::Label; 00044 mCaption->setFont(boldFont); 00045 00046 mSpeechBox = new TextBox; 00047 mSpeechBox->setEditable(false); 00048 mSpeechBox->setOpaque(false); 00049 mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT)); 00050 00051 add(mCaption); 00052 add(mSpeechBox); 00053 00054 loadPopupConfiguration(); 00055 } 00056 00057 void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) 00058 { 00059 mCaption->setCaption(name); 00060 mCaption->adjustSize(); 00061 mCaption->setForegroundColor(*color); 00062 } 00063 00064 void SpeechBubble::setText(const std::string &text, bool showName) 00065 { 00066 if (text == mText && (mCaption->getWidth() <= mSpeechBox->getMinWidth())) 00067 return; 00068 00069 mSpeechBox->setTextColor(&guiPalette->getColor(Palette::TEXT)); 00070 00071 int width = mCaption->getWidth() + 2 * getPadding(); 00072 mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width); 00073 const int speechWidth = mSpeechBox->getMinWidth() + 2 * getPadding(); 00074 00075 const int fontHeight = getFont()->getHeight(); 00076 const int nameHeight = showName ? mCaption->getHeight() + 00077 (getPadding() / 2) : 0; 00078 const int numRows = mSpeechBox->getNumberOfRows(); 00079 const int height = (numRows * fontHeight) + nameHeight + getPadding(); 00080 00081 if (width < speechWidth) 00082 width = speechWidth; 00083 00084 width += 2 * getPadding(); 00085 00086 setContentSize(width, height); 00087 00088 const int xPos = ((getWidth() - width) / 2); 00089 const int yPos = ((getHeight() - height) / 2) + nameHeight; 00090 00091 mCaption->setPosition(xPos, getPadding()); 00092 mSpeechBox->setPosition(xPos, yPos); 00093 }