Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/overlay/src/orxonox/overlays/OverlayText.cc @ 2099

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

Added minimal test files for a statistics overlay.

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