Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/OverlayText.cc @ 11231

Last change on this file since 11231 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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