Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2031 was 1784, checked in by rgrieder, 16 years ago
  • removed obsolete Convert.h includes (possibly from old XML loading)
  • replaced tabs in audio library, plus minor code cleanup because removing the tabs screwed layout
  • replaced all "#define name number" with "const Type name = number" if possible
  • Property svn:eol-style set to native
File size: 3.1 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 <OgreTextAreaOverlayElement.h>
34#include <OgrePanelOverlayElement.h>
[1588]35
[1615]36#include "util/String.h"
[1616]37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
[1588]39
40namespace orxonox
41{
[1615]42    CreateFactory(OverlayText);
[1588]43
[1615]44    OverlayText::OverlayText()
45        : text_(0)
46    {
47        RegisterObject(OverlayText);
48    }
[1588]49
[1615]50    OverlayText::~OverlayText()
[1588]51    {
[1615]52        if (this->text_)
53            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
[1588]54    }
55
[1615]56    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
[1590]57    {
[1747]58        SUPER(OverlayText, XMLPort, xmlElement, mode);
[1615]59
60        if (mode == XMLPort::LoadObject)
61        {
62            this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
63                .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr()));
[1632]64            this->text_->setCharHeight(1.0);
[1615]65
66            this->background_->addChild(this->text_);
67        }
68
[1627]69        XMLPortParam(OverlayText, "font",     setFont,     getFont,     xmlElement, mode).defaultValues("Monofur");
70        XMLPortParam(OverlayText, "caption",  setCaption,  getCaption,  xmlElement, mode).defaultValues("");
71        XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f);
[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
85            return blankString;
[1590]86    }
[1588]87
[1615]88    void OverlayText::sizeChanged()
89    {
[1627]90        if (!this->overlay_)
91            return;
92
[1632]93        if (this->rotState_ == Horizontal)
94            this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
95        else if (this->rotState_ == Vertical)
96            this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
97        else
98            this->overlay_->setScale(size_.y, size_.y);
99
[1615]100        positionChanged();
101    }
[1588]102}
Note: See TracBrowser for help on using the repository browser.