Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.cc @ 2034

Last change on this file since 2034 was 2024, checked in by landauf, 17 years ago

added spaceship

  • Property svn:eol-style set to native
File size: 5.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
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
39namespace 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
[2024]67        XMLPortParam(OverlayText, "font",     setFont,            getFont,            xmlElement, mode).defaultValues("Monofur");
68        XMLPortParam(OverlayText, "colour",   setColour,          getColour,          xmlElement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0));
69        XMLPortParam(OverlayText, "caption",  setCaption,         getCaption,         xmlElement, mode).defaultValues("");
70        XMLPortParam(OverlayText, "textSize", setTextSize,        getTextSize,        xmlElement, mode).defaultValues(1.0f);
71        XMLPortParam(OverlayText, "align",    setAlignmentString, getAlignmentString, xmlElement, mode).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
[2024]108    Ogre::TextAreaOverlayElement::Alignment OverlayText::getAlignment() const
[1993]109    {
[2024]110        if (this->text_)
111            return this->text_->getAlignment();
112        else
113            return Ogre::TextAreaOverlayElement::Left;
114    }
115
116    void OverlayText::setAlignmentString(const std::string& alignment)
117    {
[1993]118        if (alignment == "right")
119            this->setAlignment(Ogre::TextAreaOverlayElement::Right);
120        else if (alignment == "center")
121            this->setAlignment(Ogre::TextAreaOverlayElement::Center);
122        else // "left" and default
123            this->setAlignment(Ogre::TextAreaOverlayElement::Left);
124    }
125
[2024]126    std::string OverlayText::getAlignmentString() const
[1993]127    {
128        if (this->text_)
129        {
130            Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment();
131
132            switch (alignment)
133            {
134                case Ogre::TextAreaOverlayElement::Right:
135                    return "right";
136                case Ogre::TextAreaOverlayElement::Center:
137                    return "center";
138                case Ogre::TextAreaOverlayElement::Left:
139                default:;
140            }
141        }
142        return "left";
143    }
144
145    void OverlayText::setCaption(const std::string& caption)
146    {
147        this->caption_ = caption;
148        this->text_->setCaption(caption);
149    }
150
[1615]151    void OverlayText::sizeChanged()
152    {
[1627]153        if (!this->overlay_)
154            return;
155
[1632]156        if (this->rotState_ == Horizontal)
157            this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
158        else if (this->rotState_ == Vertical)
159            this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
160        else
161            this->overlay_->setScale(size_.y, size_.y);
162
[1615]163        positionChanged();
164    }
[1588]165}
Note: See TracBrowser for help on using the repository browser.