[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> |
---|
| 33 | |
---|
| 34 | #include "util/Convert.h" |
---|
| 35 | |
---|
| 36 | namespace orxonox |
---|
| 37 | { |
---|
| 38 | CreateFactory(HUDText); |
---|
| 39 | |
---|
| 40 | using namespace Ogre; |
---|
| 41 | |
---|
| 42 | HUDText::HUDText() |
---|
| 43 | : background_(0) |
---|
| 44 | , text_(0) |
---|
| 45 | { |
---|
| 46 | RegisterObject(HUDText); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | HUDText::~HUDText() |
---|
| 50 | { |
---|
| 51 | if (this->isInitialized()) |
---|
| 52 | { |
---|
| 53 | if (this->text_) |
---|
| 54 | OverlayManager::getSingleton().destroyOverlayElement(this->text_); |
---|
| 55 | if (this->background_) |
---|
| 56 | OverlayManager::getSingleton().destroyOverlayElement(this->background_); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | void HUDText::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
| 61 | { |
---|
| 62 | HUDOverlay::XMLPort(xmlElement, mode); |
---|
| 63 | |
---|
[1590] | 64 | if (mode == XMLPort::LoadObject) |
---|
| 65 | { |
---|
| 66 | // create background |
---|
| 67 | this->background_ = static_cast<PanelOverlayElement*>( |
---|
| 68 | OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); |
---|
| 69 | this->background_->setMetricsMode(GMM_RELATIVE); |
---|
| 70 | this->background_->setDimensions(1.0f, 1.0f); |
---|
| 71 | this->background_->setPosition(0.0f, 0.0f); |
---|
[1588] | 72 | |
---|
[1590] | 73 | this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text")); |
---|
| 74 | this->text_->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
| 75 | this->text_->setPosition(0.0f, 0.0f); |
---|
| 76 | this->text_->setCharHeight(1.0f); |
---|
| 77 | this->text_->setFontName("Monofur"); |
---|
[1588] | 78 | |
---|
[1590] | 79 | this->overlay_->add2D(this->background_); |
---|
| 80 | this->background_->addChild(this->text_); |
---|
| 81 | } |
---|
[1588] | 82 | |
---|
| 83 | XMLPortParam(HUDText, "material", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode); |
---|
| 84 | XMLPortParam(HUDText, "font", setFont, getFont, xmlElement, mode); |
---|
| 85 | XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode); |
---|
| 86 | |
---|
[1590] | 87 | if (mode == XMLPort::LoadObject) |
---|
| 88 | { |
---|
| 89 | this->text_->setCaption(this->caption_); |
---|
| 90 | } |
---|
[1588] | 91 | } |
---|
| 92 | |
---|
| 93 | void HUDText::setBackgroundMaterial(const std::string& material) |
---|
| 94 | { |
---|
| 95 | if (this->background_ && material != "") |
---|
| 96 | this->background_->setMaterialName(material); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | std::string HUDText::getBackgroundMaterial() const |
---|
| 100 | { |
---|
| 101 | if (this->background_) |
---|
| 102 | return this->background_->getMaterialName(); |
---|
| 103 | else |
---|
| 104 | return ""; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void HUDText::setCaption(const std::string& caption) |
---|
| 108 | { |
---|
| 109 | this->caption_ = caption; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | const std::string& HUDText::getCaption() const |
---|
| 113 | { |
---|
| 114 | return this->caption_; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void HUDText::setFont(const std::string& font) |
---|
| 118 | { |
---|
| 119 | if (this->text_ && font != "") |
---|
| 120 | this->text_->setFontName(font); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | std::string HUDText::getFont() const |
---|
| 124 | { |
---|
| 125 | if (this->text_) |
---|
| 126 | return this->text_->getFontName(); |
---|
| 127 | else |
---|
| 128 | return ""; |
---|
| 129 | } |
---|
| 130 | } |
---|