Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/OverlayText.cc @ 3176

Last change on this file since 3176 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

  • Property svn:eol-style set to native
File size: 4.2 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>
[1588]33
[1615]34#include "util/String.h"
[1616]35#include "core/CoreIncludes.h"
36#include "core/XMLPort.h"
[1588]37
38namespace orxonox
39{
[1615]40    CreateFactory(OverlayText);
[1588]41
[2087]42    OverlayText::OverlayText(BaseObject* creator)
43        : OrxonoxOverlay(creator)
[1615]44    {
45        RegisterObject(OverlayText);
[2087]46
47        this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
48            .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString()));
49        this->text_->setCharHeight(1.0);
50
[2662]51        this->setFont("Monofur");
52        this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
53        this->setCaption("");
54        this->setTextSize(1.0f);
55        this->setAlignmentString("left");
[2087]56
57        this->background_->addChild(this->text_);
[1615]58    }
[1588]59
[1615]60    OverlayText::~OverlayText()
[1588]61    {
[2087]62        if (this->isInitialized())
[1615]63            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
[1588]64    }
65
[1615]66    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
[1590]67    {
[1747]68        SUPER(OverlayText, XMLPort, xmlElement, mode);
[1615]69
[2662]70        XMLPortParam(OverlayText, "font",       setFont,            getFont,            xmlElement, mode);
71        XMLPortParam(OverlayText, "colour",     setColour,          getColour,          xmlElement, mode);
72        XMLPortParam(OverlayText, "caption",    setCaption,         getCaption,         xmlElement, mode);
73        XMLPortParam(OverlayText, "textsize",   setTextSize,        getTextSize,        xmlElement, mode);
74        XMLPortParam(OverlayText, "align",      setAlignmentString, getAlignmentString, xmlElement, mode);
75        XMLPortParam(OverlayText, "spacewidth", setSpaceWidth,      getSpaceWidth,      xmlElement, mode);
[1590]76    }
[1588]77
[1615]78    void OverlayText::setFont(const std::string& font)
79    {
[2087]80        if (font != "")
[1615]81            this->text_->setFontName(font);
82    }
[1588]83
[2087]84    void OverlayText::setAlignmentString(const std::string& alignment)
[1590]85    {
[2087]86        if (alignment == "right")
87            this->setAlignment(Ogre::TextAreaOverlayElement::Right);
88        else if (alignment == "center")
89            this->setAlignment(Ogre::TextAreaOverlayElement::Center);
90        else // "left" and default
91            this->setAlignment(Ogre::TextAreaOverlayElement::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    {
[1632]113        if (this->rotState_ == Horizontal)
114            this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
115        else if (this->rotState_ == Vertical)
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    }
[1588]122}
Note: See TracBrowser for help on using the repository browser.