Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud/src/orxonox/hud/HUDText.cc @ 1590

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

svn save, just in case our house burns down over night…

  • Property svn:eol-style set to native
File size: 3.5 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 "HUDText.h"
31
32#include <OgreOverlayManager.h>
33
34#include "util/Convert.h"
35
36namespace orxonox
37{
38  CreateFactory(HUDText);
39
40  using namespace Ogre;
41
42  HUDText::HUDText()
43    : background_(0)
44    , text_(0)
45  {
46    RegisterObject(HUDText);
47  }
48
49  HUDText::~HUDText()
50  {
51    if (this->isInitialized())
52    {
53      if (this->text_)
54          OverlayManager::getSingleton().destroyOverlayElement(this->text_);
55      if (this->background_)
56          OverlayManager::getSingleton().destroyOverlayElement(this->background_);
57    }
58  }
59
60  void HUDText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
61  {
62    HUDOverlay::XMLPort(xmlElement, mode);
63
64    if (mode == XMLPort::LoadObject)
65    {
66      // create background
67      this->background_ = static_cast<PanelOverlayElement*>(
68              OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background"));
69      this->background_->setMetricsMode(GMM_RELATIVE);
70      this->background_->setDimensions(1.0f, 1.0f);
71      this->background_->setPosition(0.0f, 0.0f);
72
73      this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text"));
74      this->text_->setMetricsMode(Ogre::GMM_RELATIVE);
75      this->text_->setPosition(0.0f, 0.0f);
76      this->text_->setCharHeight(1.0f);
77      this->text_->setFontName("Monofur");
78
79      this->overlay_->add2D(this->background_);
80      this->background_->addChild(this->text_);
81    }
82
83    XMLPortParam(HUDText, "material", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode);
84    XMLPortParam(HUDText, "font", setFont, getFont, xmlElement, mode);
85    XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode);
86
87    if (mode == XMLPort::LoadObject)
88    {
89      this->text_->setCaption(this->caption_);
90    }
91  }
92
93  void HUDText::setBackgroundMaterial(const std::string& material)
94  {
95    if (this->background_ && material != "")
96      this->background_->setMaterialName(material);
97  }
98
99  std::string HUDText::getBackgroundMaterial() const
100  {
101    if (this->background_)
102      return this->background_->getMaterialName();
103    else
104      return "";
105  }
106
107  void HUDText::setCaption(const std::string& caption)
108  {
109    this->caption_ = caption;
110  }
111
112  const std::string& HUDText::getCaption() const
113  {
114    return this->caption_;
115  }
116
117  void HUDText::setFont(const std::string& font)
118  {
119    if (this->text_ && font != "")
120      this->text_->setFontName(font);
121  }
122
123  std::string HUDText::getFont() const
124  {
125    if (this->text_)
126      return this->text_->getFontName();
127    else
128      return "";
129  }
130}
Note: See TracBrowser for help on using the repository browser.