Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/overlays/OverlayText.cc @ 12065

Last change on this file since 12065 was 11795, checked in by landauf, 7 years ago

merged ogre1.9 (including cegui0.8) into new branch

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