Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

  • Property svn:eol-style set to native
File size: 4.9 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        XMLPortParamTemplate(OverlayText, "align", setAlignment, getAlignment, xmlElement, mode, const std::string&).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    void OverlayText::setAlignment(const std::string& alignment)
109    {
110        if (alignment == "right")
111            this->setAlignment(Ogre::TextAreaOverlayElement::Right);
112        else if (alignment == "center")
113            this->setAlignment(Ogre::TextAreaOverlayElement::Center);
114        else // "left" and default
115            this->setAlignment(Ogre::TextAreaOverlayElement::Left);
116    }
117
118    std::string OverlayText::getAlignment() const
119    {
120        if (this->text_)
121        {
122            Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment();
123
124            switch (alignment)
125            {
126                case Ogre::TextAreaOverlayElement::Right:
127                    return "right";
128                case Ogre::TextAreaOverlayElement::Center:
129                    return "center";
130                case Ogre::TextAreaOverlayElement::Left:
131                default:;
132            }
133        }
134        return "left";
135    }
136
137    void OverlayText::setCaption(const std::string& caption)
138    {
139        this->caption_ = caption;
140        this->text_->setCaption(caption);
141    }
142
143    void OverlayText::sizeChanged()
144    {
145        if (!this->overlay_)
146            return;
147
148        if (this->rotState_ == Horizontal)
149            this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
150        else if (this->rotState_ == Vertical)
151            this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
152        else
153            this->overlay_->setScale(size_.y, size_.y);
154
155        positionChanged();
156    }
157}
Note: See TracBrowser for help on using the repository browser.