Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud/src/orxonox/overlays/OverlayText.cc @ 1615

Last change on this file since 1615 was 1615, checked in by rgrieder, 16 years ago
  • added blankString to String so you can return ""; even if it's a const std::string&
  • fixed several bugs with aspect correct and margin alignment
  • added console commands for OrxonoxOverlays and OverlayGroups for rotate, scale and scroll (you can access the by name (from name=.. in xml file), e.g. "OrxonoxOverlay rotateOverlay SpeedBar 90)
  • converted everything in overlays/ to 4 spaces/tab ;)
  • removed all using namespace Ogre;
  • added background_ Panel to OrxonoxOverlay, since most of the derived classes can use that
  • should work now, but I'll have to test on a tardis box first
  • Property svn:eol-style set to native
File size: 3.1 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
39namespace orxonox
40{
41    CreateFactory(OverlayText);
42
43    OverlayText::OverlayText()
44        : text_(0)
45    {
46        RegisterObject(OverlayText);
47    }
48
49    OverlayText::~OverlayText()
50    {
51        if (this->text_)
52            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
53    }
54
55    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
56    {
57        if (mode == XMLPort::LoadObject)
58        {
59            // setting this to true makes the text more readable when the
60            // resolution aspect is far from 1.0
61            this->bCorrectAspect_ = true; // can be overridden by xml
62        }
63
64        OrxonoxOverlay::XMLPort(xmlElement, mode);
65
66        if (mode == XMLPort::LoadObject)
67        {
68            this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
69                .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr()));
70            this->text_->setCharHeight(1.0f);
71            this->text_->setFontName("Monofur");
72
73            this->background_->addChild(this->text_);
74        }
75
76        XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode);
77        XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode);
78        XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode);
79
80        if (mode == XMLPort::LoadObject)
81        {
82            this->text_->setCaption(this->caption_);
83        }
84    }
85
86    void OverlayText::setFont(const std::string& font)
87    {
88        if (this->text_ && font != "")
89            this->text_->setFontName(font);
90    }
91
92    const std::string& OverlayText::getFont() const
93    {
94        if (this->text_)
95            return this->text_->getFontName();
96        else
97            return blankString;
98    }
99
100    void OverlayText::sizeChanged()
101    {
102        this->overlay_->setScale(getSize().y, getSize().y);
103        positionChanged();
104    }
105}
Note: See TracBrowser for help on using the repository browser.