Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some adjustment to the default value setting in the overlay files

  • Property svn:eol-style set to native
File size: 2.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 <OgreTextAreaOverlayElement.h>
34#include <OgrePanelOverlayElement.h>
35
36#include "util/Convert.h"
37#include "util/String.h"
38#include "core/CoreIncludes.h"
39#include "core/XMLPort.h"
40
41namespace orxonox
42{
43    CreateFactory(OverlayText);
44
45    OverlayText::OverlayText()
46        : text_(0)
47    {
48        RegisterObject(OverlayText);
49    }
50
51    OverlayText::~OverlayText()
52    {
53        if (this->text_)
54            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
55    }
56
57    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
58    {
59        OrxonoxOverlay::XMLPort(xmlElement, mode);
60
61        if (mode == XMLPort::LoadObject)
62        {
63            this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
64                .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr()));
65
66            this->background_->addChild(this->text_);
67
68            this->setFont("Monofur");
69            this->caption_ = "";
70            this->setTextSize(1.0f);
71        }
72
73        XMLPortParam(OverlayText, "font",     setFont,     getFont,     xmlElement, mode).defaultValues("Monofur");
74        XMLPortParam(OverlayText, "caption",  setCaption,  getCaption,  xmlElement, mode).defaultValues("");
75        XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f);
76    }
77
78    void OverlayText::setFont(const std::string& font)
79    {
80        if (this->text_ && font != "")
81            this->text_->setFontName(font);
82    }
83
84    const std::string& OverlayText::getFont() const
85    {
86        if (this->text_)
87            return this->text_->getFontName();
88        else
89            return blankString;
90    }
91
92    void OverlayText::sizeChanged()
93    {
94        if (!this->overlay_)
95            return;
96
97        this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
98        positionChanged();
99    }
100}
Note: See TracBrowser for help on using the repository browser.