diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-30 15:01:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-30 15:01:42 +0300 |
commit | 64781090e80fa93a43ce37f0705bbb1cf22ed8bf (patch) | |
tree | 6932ff7f29b4a1e1fe2f3834592587c33d7c4651 /src/gui/popups/textpopup.cpp | |
parent | 25d77892d72d455f8a89372687db45aefbc61cec (diff) | |
download | manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.tar.gz manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.tar.bz2 manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.tar.xz manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.zip |
move popups into popups directory.
Diffstat (limited to 'src/gui/popups/textpopup.cpp')
-rw-r--r-- | src/gui/popups/textpopup.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/gui/popups/textpopup.cpp b/src/gui/popups/textpopup.cpp new file mode 100644 index 000000000..2b89e388b --- /dev/null +++ b/src/gui/popups/textpopup.cpp @@ -0,0 +1,105 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008 The Legend of Mazzeroth Development Team + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/popups/textpopup.h" + +#include "gui/widgets/label.h" + +#include <guichan/font.hpp> + +#include "debug.h" + +TextPopup::TextPopup(): + Popup("TextPopup", "textpopup.xml"), + mText() +{ + const int fontHeight = getFont()->getHeight(); + int y = 0; + for (int f = 0; f < TEXTPOPUPCOUNT; f ++) + { + Label *const label = new Label(this); + mText[f] = label; + label->setPosition(0, y); + label->setForegroundColorAll(getThemeColor(Theme::POPUP), + getThemeColor(Theme::POPUP_OUTLINE)); + add(label); + y += fontHeight; + } + addMouseListener(this); +} + +TextPopup::~TextPopup() +{ +} + +void TextPopup::show(const int x, const int y, const std::string &str1, + const std::string &str2, const std::string &str3) +{ + mText[0]->setCaption(str1); + mText[1]->setCaption(str2); + mText[2]->setCaption(str3); + + int minWidth = 0; + for (int f = 0; f < TEXTPOPUPCOUNT; f ++) + { + Label *const label = mText[f]; + label->adjustSize(); + const int width = label->getWidth(); + if (width > minWidth) + minWidth = width; + } + + const int pad2 = 2 * mPadding; + minWidth += pad2; + setWidth(minWidth); + + int cnt = 1; + if (!str2.empty()) + cnt ++; + if (!str3.empty()) + cnt ++; + + setHeight(pad2 + mText[0]->getFont()->getHeight() * cnt); + const int distance = 20; + + const gcn::Rectangle &rect = mDimension; + int posX = std::max(0, x - rect.width / 2); + int posY = y + distance; + + if (posX + rect.width > mainGraphics->mWidth) + posX = mainGraphics->mWidth - rect.width; + if (posY + rect.height > mainGraphics->mHeight) + posY = y - rect.height - distance; + + setPosition(posX, posY); + setVisible(true); + requestMoveToTop(); +} + +void TextPopup::mouseMoved(gcn::MouseEvent &event) +{ + Popup::mouseMoved(event); + + // When the mouse moved on top of the popup, hide it + setVisible(false); +} |