[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 | |
---|
[1615] | 29 | #include "OverlayText.h" |
---|
[1588] | 30 | |
---|
| 31 | #include <OgreOverlayManager.h> |
---|
[1614] | 32 | #include <OgrePanelOverlayElement.h> |
---|
[3196] | 33 | #include <OgreTextAreaOverlayElement.h> |
---|
| 34 | #include <boost/static_assert.hpp> |
---|
[1588] | 35 | |
---|
[3280] | 36 | #include "util/StringUtils.h" |
---|
[1616] | 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include "core/XMLPort.h" |
---|
[1588] | 39 | |
---|
[3196] | 40 | |
---|
[1588] | 41 | namespace orxonox |
---|
| 42 | { |
---|
[9667] | 43 | RegisterClass(OverlayText); |
---|
[1588] | 44 | |
---|
[3196] | 45 | BOOST_STATIC_ASSERT((int)Ogre::TextAreaOverlayElement::Left == (int)OverlayText::Left); |
---|
| 46 | BOOST_STATIC_ASSERT((int)Ogre::TextAreaOverlayElement::Center == (int)OverlayText::Center); |
---|
| 47 | BOOST_STATIC_ASSERT((int)Ogre::TextAreaOverlayElement::Right == (int)OverlayText::Right); |
---|
| 48 | |
---|
[9667] | 49 | OverlayText::OverlayText(Context* context) |
---|
| 50 | : OrxonoxOverlay(context) |
---|
[1615] | 51 | { |
---|
| 52 | RegisterObject(OverlayText); |
---|
[2087] | 53 | |
---|
| 54 | this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() |
---|
| 55 | .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString())); |
---|
| 56 | this->text_->setCharHeight(1.0); |
---|
| 57 | |
---|
[2662] | 58 | this->setFont("Monofur"); |
---|
| 59 | this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); |
---|
| 60 | this->setCaption(""); |
---|
| 61 | this->setTextSize(1.0f); |
---|
| 62 | this->setAlignmentString("left"); |
---|
[2087] | 63 | |
---|
| 64 | this->background_->addChild(this->text_); |
---|
[1615] | 65 | } |
---|
[1588] | 66 | |
---|
[1615] | 67 | OverlayText::~OverlayText() |
---|
[1588] | 68 | { |
---|
[2087] | 69 | if (this->isInitialized()) |
---|
[1615] | 70 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_); |
---|
[1588] | 71 | } |
---|
| 72 | |
---|
[7401] | 73 | void OverlayText::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[1590] | 74 | { |
---|
[7401] | 75 | SUPER(OverlayText, XMLPort, xmlelement, mode); |
---|
[1615] | 76 | |
---|
[7401] | 77 | XMLPortParam(OverlayText, "font", setFont, getFont, xmlelement, mode); |
---|
| 78 | XMLPortParam(OverlayText, "colour", setColour, getColour, xmlelement, mode); |
---|
| 79 | XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlelement, mode); |
---|
| 80 | XMLPortParam(OverlayText, "textsize", setTextSize, getTextSize, xmlelement, mode); |
---|
| 81 | XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlelement, mode); |
---|
| 82 | XMLPortParam(OverlayText, "spacewidth", setSpaceWidth, getSpaceWidth, xmlelement, mode); |
---|
[1590] | 83 | } |
---|
[1588] | 84 | |
---|
[2087] | 85 | void OverlayText::setAlignmentString(const std::string& alignment) |
---|
[1590] | 86 | { |
---|
[2087] | 87 | if (alignment == "right") |
---|
[3196] | 88 | this->setAlignment(OverlayText::Right); |
---|
[2087] | 89 | else if (alignment == "center") |
---|
[3196] | 90 | this->setAlignment(OverlayText::Center); |
---|
[2087] | 91 | else // "left" and default |
---|
[3196] | 92 | this->setAlignment(OverlayText::Left); |
---|
[1590] | 93 | } |
---|
[1588] | 94 | |
---|
[2087] | 95 | std::string OverlayText::getAlignmentString() const |
---|
| 96 | { |
---|
| 97 | Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment(); |
---|
| 98 | |
---|
| 99 | switch (alignment) |
---|
| 100 | { |
---|
| 101 | case Ogre::TextAreaOverlayElement::Right: |
---|
| 102 | return "right"; |
---|
| 103 | case Ogre::TextAreaOverlayElement::Center: |
---|
| 104 | return "center"; |
---|
| 105 | case Ogre::TextAreaOverlayElement::Left: |
---|
| 106 | return "left"; |
---|
| 107 | default: |
---|
| 108 | assert(false); return ""; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
[1615] | 112 | void OverlayText::sizeChanged() |
---|
| 113 | { |
---|
[1632] | 114 | if (this->rotState_ == Horizontal) |
---|
| 115 | this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y); |
---|
| 116 | else if (this->rotState_ == Vertical) |
---|
| 117 | this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y); |
---|
| 118 | else |
---|
| 119 | this->overlay_->setScale(size_.y, size_.y); |
---|
| 120 | |
---|
[1615] | 121 | positionChanged(); |
---|
| 122 | } |
---|
[3196] | 123 | |
---|
| 124 | void OverlayText::setCaption(const std::string& caption) |
---|
| 125 | { |
---|
| 126 | this->text_->setCaption(caption); |
---|
| 127 | this->changedCaption(); |
---|
| 128 | } |
---|
| 129 | std::string OverlayText::getCaption() const |
---|
| 130 | { |
---|
| 131 | return this->text_->getCaption(); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | void OverlayText::setFont(const std::string& font) |
---|
| 135 | { |
---|
[6417] | 136 | if (!font.empty()) |
---|
[3196] | 137 | this->text_->setFontName(font); |
---|
| 138 | } |
---|
| 139 | const std::string& OverlayText::getFont() const |
---|
| 140 | { |
---|
| 141 | return this->text_->getFontName(); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | void OverlayText::setSpaceWidth(float width) |
---|
| 145 | { |
---|
| 146 | this->text_->setSpaceWidth(width); |
---|
| 147 | } |
---|
| 148 | float OverlayText::getSpaceWidth() const |
---|
| 149 | { |
---|
| 150 | return this->text_->getSpaceWidth(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | void OverlayText::setColour(const ColourValue& colour) |
---|
| 154 | { |
---|
| 155 | this->text_->setColour(colour); this->changedColour(); |
---|
| 156 | } |
---|
| 157 | const ColourValue& OverlayText::getColour() const |
---|
| 158 | { |
---|
| 159 | return this->text_->getColour(); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void OverlayText::setAlignment(OverlayText::Alignment alignment) |
---|
| 163 | { |
---|
| 164 | this->text_->setAlignment(static_cast<Ogre::TextAreaOverlayElement::Alignment>(alignment)); |
---|
| 165 | } |
---|
| 166 | OverlayText::Alignment OverlayText::getAlignment() const |
---|
| 167 | { |
---|
| 168 | return static_cast<OverlayText::Alignment>(this->text_->getAlignment()); |
---|
| 169 | } |
---|
[1588] | 170 | } |
---|