Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem5/src/orxonox/overlays/OverlayText.cc @ 2916

Last change on this file since 2916 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 4.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)
44        : OrxonoxOverlay(creator)
45    {
46        RegisterObject(OverlayText);
47
48        this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
49            .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString()));
50        this->text_->setCharHeight(1.0);
51
52        this->setFont("Monofur");
53        this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
54        this->setCaption("");
55        this->setTextSize(1.0f);
56        this->setAlignmentString("left");
57
58        this->background_->addChild(this->text_);
59    }
60
61    OverlayText::~OverlayText()
62    {
63        if (this->isInitialized())
64            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
65    }
66
67    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
68    {
69        SUPER(OverlayText, XMLPort, xmlElement, mode);
70
71        XMLPortParam(OverlayText, "font",       setFont,            getFont,            xmlElement, mode);
72        XMLPortParam(OverlayText, "colour",     setColour,          getColour,          xmlElement, mode);
73        XMLPortParam(OverlayText, "caption",    setCaption,         getCaption,         xmlElement, mode);
74        XMLPortParam(OverlayText, "textsize",   setTextSize,        getTextSize,        xmlElement, mode);
75        XMLPortParam(OverlayText, "align",      setAlignmentString, getAlignmentString, xmlElement, mode);
76        XMLPortParam(OverlayText, "spacewidth", setSpaceWidth,      getSpaceWidth,      xmlElement, mode);
77    }
78
79    void OverlayText::setFont(const std::string& font)
80    {
81        if (font != "")
82            this->text_->setFontName(font);
83    }
84
85    void OverlayText::setAlignmentString(const std::string& alignment)
86    {
87        if (alignment == "right")
88            this->setAlignment(Ogre::TextAreaOverlayElement::Right);
89        else if (alignment == "center")
90            this->setAlignment(Ogre::TextAreaOverlayElement::Center);
91        else // "left" and default
92            this->setAlignment(Ogre::TextAreaOverlayElement::Left);
93    }
94
95    std::string OverlayText::getAlignmentString() const
96    {
97        Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment();
98
99        switch (alignment)
100        {
101            case Ogre::TextAreaOverlayElement::Right:
102                return "right";
103            case Ogre::TextAreaOverlayElement::Center:
104                return "center";
105            case Ogre::TextAreaOverlayElement::Left:
106                return "left";
107            default:
108                assert(false); return "";
109        }
110    }
111
112    void OverlayText::sizeChanged()
113    {
114        if (this->rotState_ == Horizontal)
115            this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
116        else if (this->rotState_ == Vertical)
117            this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
118        else
119            this->overlay_->setScale(size_.y, size_.y);
120
121        positionChanged();
122    }
123}
Note: See TracBrowser for help on using the repository browser.