Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added spaceship

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
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"
30#include "OverlayText.h"
31
32#include <OgreOverlayManager.h>
33#include <OgrePanelOverlayElement.h>
34
35#include "util/String.h"
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38
39namespace orxonox
40{
41    CreateFactory(OverlayText);
42
43    OverlayText::OverlayText(BaseObject* creator) : OrxonoxOverlay(creator), text_(0)
44    {
45        RegisterObject(OverlayText);
46    }
47
48    OverlayText::~OverlayText()
49    {
50        if (this->text_)
51            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
52    }
53
54    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
55    {
56        SUPER(OverlayText, XMLPort, xmlElement, mode);
57
58        if (mode == XMLPort::LoadObject)
59        {
60            this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
61                .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString()));
62            this->text_->setCharHeight(1.0);
63
64            this->background_->addChild(this->text_);
65        }
66
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");
72    }
73
74    void OverlayText::setFont(const std::string& font)
75    {
76        if (this->text_ && font != "")
77            this->text_->setFontName(font);
78    }
79
80    const std::string& OverlayText::getFont() const
81    {
82        if (this->text_)
83            return this->text_->getFontName();
84        else
85            return BLANKSTRING;
86    }
87
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
108    Ogre::TextAreaOverlayElement::Alignment OverlayText::getAlignment() const
109    {
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    {
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
126    std::string OverlayText::getAlignmentString() const
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
151    void OverlayText::sizeChanged()
152    {
153        if (!this->overlay_)
154            return;
155
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
163        positionChanged();
164    }
165}
Note: See TracBrowser for help on using the repository browser.