[1588] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
[1615] | 30 | #include "OverlayText.h" |
---|
[1588] | 31 | |
---|
| 32 | #include <OgreOverlayManager.h> |
---|
[1614] | 33 | #include <OgreTextAreaOverlayElement.h> |
---|
| 34 | #include <OgrePanelOverlayElement.h> |
---|
[1588] | 35 | |
---|
| 36 | #include "util/Convert.h" |
---|
[1615] | 37 | #include "util/String.h" |
---|
[1616] | 38 | #include "core/CoreIncludes.h" |
---|
| 39 | #include "core/XMLPort.h" |
---|
[1588] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[1615] | 43 | CreateFactory(OverlayText); |
---|
[1588] | 44 | |
---|
[1615] | 45 | OverlayText::OverlayText() |
---|
| 46 | : text_(0) |
---|
| 47 | { |
---|
| 48 | RegisterObject(OverlayText); |
---|
| 49 | } |
---|
[1588] | 50 | |
---|
[1615] | 51 | OverlayText::~OverlayText() |
---|
[1588] | 52 | { |
---|
[1615] | 53 | if (this->text_) |
---|
| 54 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_); |
---|
[1588] | 55 | } |
---|
| 56 | |
---|
[1615] | 57 | void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
[1590] | 58 | { |
---|
[1615] | 59 | if (mode == XMLPort::LoadObject) |
---|
| 60 | { |
---|
| 61 | // setting this to true makes the text more readable when the |
---|
| 62 | // resolution aspect is far from 1.0 |
---|
| 63 | this->bCorrectAspect_ = true; // can be overridden by xml |
---|
| 64 | } |
---|
[1588] | 65 | |
---|
[1615] | 66 | OrxonoxOverlay::XMLPort(xmlElement, mode); |
---|
| 67 | |
---|
| 68 | if (mode == XMLPort::LoadObject) |
---|
| 69 | { |
---|
| 70 | this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() |
---|
| 71 | .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr())); |
---|
| 72 | this->text_->setCharHeight(1.0f); |
---|
| 73 | this->text_->setFontName("Monofur"); |
---|
| 74 | |
---|
| 75 | this->background_->addChild(this->text_); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode); |
---|
| 79 | XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode); |
---|
| 80 | XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode); |
---|
| 81 | |
---|
| 82 | if (mode == XMLPort::LoadObject) |
---|
| 83 | { |
---|
| 84 | this->text_->setCaption(this->caption_); |
---|
| 85 | } |
---|
[1590] | 86 | } |
---|
[1588] | 87 | |
---|
[1615] | 88 | void OverlayText::setFont(const std::string& font) |
---|
| 89 | { |
---|
| 90 | if (this->text_ && font != "") |
---|
| 91 | this->text_->setFontName(font); |
---|
| 92 | } |
---|
[1588] | 93 | |
---|
[1615] | 94 | const std::string& OverlayText::getFont() const |
---|
[1590] | 95 | { |
---|
[1615] | 96 | if (this->text_) |
---|
| 97 | return this->text_->getFontName(); |
---|
| 98 | else |
---|
| 99 | return blankString; |
---|
[1590] | 100 | } |
---|
[1588] | 101 | |
---|
[1615] | 102 | void OverlayText::sizeChanged() |
---|
| 103 | { |
---|
[1622] | 104 | this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y); |
---|
[1615] | 105 | positionChanged(); |
---|
| 106 | } |
---|
[1588] | 107 | } |
---|