[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 <OgrePanelOverlayElement.h> |
---|
[1588] | 34 | |
---|
[1615] | 35 | #include "util/String.h" |
---|
[1616] | 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
[1588] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[1615] | 41 | CreateFactory(OverlayText); |
---|
[1588] | 42 | |
---|
[2019] | 43 | OverlayText::OverlayText(BaseObject* creator) : OrxonoxOverlay(creator), text_(0) |
---|
[1615] | 44 | { |
---|
| 45 | RegisterObject(OverlayText); |
---|
| 46 | } |
---|
[1588] | 47 | |
---|
[1615] | 48 | OverlayText::~OverlayText() |
---|
[1588] | 49 | { |
---|
[1615] | 50 | if (this->text_) |
---|
| 51 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_); |
---|
[1588] | 52 | } |
---|
| 53 | |
---|
[1615] | 54 | void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
[1590] | 55 | { |
---|
[1747] | 56 | SUPER(OverlayText, XMLPort, xmlElement, mode); |
---|
[1615] | 57 | |
---|
| 58 | if (mode == XMLPort::LoadObject) |
---|
| 59 | { |
---|
| 60 | this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() |
---|
[2019] | 61 | .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString())); |
---|
[1632] | 62 | this->text_->setCharHeight(1.0); |
---|
[1615] | 63 | |
---|
| 64 | this->background_->addChild(this->text_); |
---|
| 65 | } |
---|
| 66 | |
---|
[1627] | 67 | XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode).defaultValues("Monofur"); |
---|
[1993] | 68 | XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); |
---|
[1627] | 69 | XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode).defaultValues(""); |
---|
| 70 | XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f); |
---|
[1993] | 71 | XMLPortParamTemplate(OverlayText, "align", setAlignment, getAlignment, xmlElement, mode, const std::string&).defaultValues("left"); |
---|
[1590] | 72 | } |
---|
[1588] | 73 | |
---|
[1615] | 74 | void OverlayText::setFont(const std::string& font) |
---|
| 75 | { |
---|
| 76 | if (this->text_ && font != "") |
---|
| 77 | this->text_->setFontName(font); |
---|
| 78 | } |
---|
[1588] | 79 | |
---|
[1615] | 80 | const std::string& OverlayText::getFont() const |
---|
[1590] | 81 | { |
---|
[1615] | 82 | if (this->text_) |
---|
| 83 | return this->text_->getFontName(); |
---|
| 84 | else |
---|
[2019] | 85 | return BLANKSTRING; |
---|
[1590] | 86 | } |
---|
[1588] | 87 | |
---|
[1993] | 88 | void OverlayText::setColour(const ColourValue& colour) |
---|
| 89 | { |
---|
| 90 | if (this->text_) |
---|
| 91 | this->text_->setColour(colour); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | const ColourValue& OverlayText::getColour() const |
---|
| 95 | { |
---|
| 96 | if (this->text_) |
---|
| 97 | return this->text_->getColour(); |
---|
| 98 | else |
---|
| 99 | return ColourValue::White; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void OverlayText::setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) |
---|
| 103 | { |
---|
| 104 | if (this->text_) |
---|
| 105 | this->text_->setAlignment(alignment); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | void OverlayText::setAlignment(const std::string& alignment) |
---|
| 109 | { |
---|
| 110 | if (alignment == "right") |
---|
| 111 | this->setAlignment(Ogre::TextAreaOverlayElement::Right); |
---|
| 112 | else if (alignment == "center") |
---|
| 113 | this->setAlignment(Ogre::TextAreaOverlayElement::Center); |
---|
| 114 | else // "left" and default |
---|
| 115 | this->setAlignment(Ogre::TextAreaOverlayElement::Left); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | std::string OverlayText::getAlignment() const |
---|
| 119 | { |
---|
| 120 | if (this->text_) |
---|
| 121 | { |
---|
| 122 | Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment(); |
---|
| 123 | |
---|
| 124 | switch (alignment) |
---|
| 125 | { |
---|
| 126 | case Ogre::TextAreaOverlayElement::Right: |
---|
| 127 | return "right"; |
---|
| 128 | case Ogre::TextAreaOverlayElement::Center: |
---|
| 129 | return "center"; |
---|
| 130 | case Ogre::TextAreaOverlayElement::Left: |
---|
| 131 | default:; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | return "left"; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | void OverlayText::setCaption(const std::string& caption) |
---|
| 138 | { |
---|
| 139 | this->caption_ = caption; |
---|
| 140 | this->text_->setCaption(caption); |
---|
| 141 | } |
---|
| 142 | |
---|
[1615] | 143 | void OverlayText::sizeChanged() |
---|
| 144 | { |
---|
[1627] | 145 | if (!this->overlay_) |
---|
| 146 | return; |
---|
| 147 | |
---|
[1632] | 148 | if (this->rotState_ == Horizontal) |
---|
| 149 | this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y); |
---|
| 150 | else if (this->rotState_ == Vertical) |
---|
| 151 | this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y); |
---|
| 152 | else |
---|
| 153 | this->overlay_->setScale(size_.y, size_.y); |
---|
| 154 | |
---|
[1615] | 155 | positionChanged(); |
---|
| 156 | } |
---|
[1588] | 157 | } |
---|