[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" |
---|
| 30 | #include "HUDText.h" |
---|
| 31 | |
---|
| 32 | #include <OgreOverlayManager.h> |
---|
[1614] | 33 | #include <OgreTextAreaOverlayElement.h> |
---|
| 34 | #include <OgrePanelOverlayElement.h> |
---|
[1588] | 35 | |
---|
| 36 | #include "util/Convert.h" |
---|
| 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | CreateFactory(HUDText); |
---|
| 41 | |
---|
| 42 | using namespace Ogre; |
---|
| 43 | |
---|
| 44 | HUDText::HUDText() |
---|
[1614] | 45 | : text_(0) |
---|
[1588] | 46 | { |
---|
| 47 | RegisterObject(HUDText); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | HUDText::~HUDText() |
---|
| 51 | { |
---|
| 52 | if (this->isInitialized()) |
---|
| 53 | { |
---|
| 54 | if (this->text_) |
---|
| 55 | OverlayManager::getSingleton().destroyOverlayElement(this->text_); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void HUDText::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
| 60 | { |
---|
[1601] | 61 | OrxonoxOverlay::XMLPort(xmlElement, mode); |
---|
[1588] | 62 | |
---|
[1590] | 63 | if (mode == XMLPort::LoadObject) |
---|
| 64 | { |
---|
| 65 | this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text")); |
---|
| 66 | this->text_->setCharHeight(1.0f); |
---|
| 67 | this->text_->setFontName("Monofur"); |
---|
[1588] | 68 | |
---|
[1590] | 69 | this->background_->addChild(this->text_); |
---|
| 70 | } |
---|
[1588] | 71 | |
---|
| 72 | XMLPortParam(HUDText, "font", setFont, getFont, xmlElement, mode); |
---|
| 73 | XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode); |
---|
| 74 | |
---|
[1590] | 75 | if (mode == XMLPort::LoadObject) |
---|
| 76 | { |
---|
| 77 | this->text_->setCaption(this->caption_); |
---|
| 78 | } |
---|
[1588] | 79 | } |
---|
| 80 | |
---|
| 81 | void HUDText::setCaption(const std::string& caption) |
---|
| 82 | { |
---|
| 83 | this->caption_ = caption; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | const std::string& HUDText::getCaption() const |
---|
| 87 | { |
---|
| 88 | return this->caption_; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void HUDText::setFont(const std::string& font) |
---|
| 92 | { |
---|
| 93 | if (this->text_ && font != "") |
---|
| 94 | this->text_->setFontName(font); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | std::string HUDText::getFont() const |
---|
| 98 | { |
---|
| 99 | if (this->text_) |
---|
| 100 | return this->text_->getFontName(); |
---|
| 101 | else |
---|
| 102 | return ""; |
---|
| 103 | } |
---|
| 104 | } |
---|