Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1588 was 1588, checked in by rgrieder, 16 years ago
  • added XML loadable HUD
  • Radar and navi are not yet done
  • explanations follow with when things are finished
  • Property svn:eol-style set to native
File size: 3.4 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    // create background
65    this->background_ = static_cast<PanelOverlayElement*>(
66            OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background"));
67    this->background_->setMetricsMode(GMM_RELATIVE);
68    this->background_->setDimensions(1.0f, 1.0f);
69    this->background_->setPosition(0.0f, 0.0f);
70
71    this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text"));
72    this->text_->setMetricsMode(Ogre::GMM_RELATIVE);
73    this->text_->setDimensions(1.0f, 1.0f);
74    this->text_->setPosition(0.0f, 0.0f);
75    this->text_->setCharHeight(1.0f);
76
77    this->overlay_->add2D(this->background_);
78    this->background_->addChild(this->text_);
79
80    XMLPortParam(HUDText, "material", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode);
81    XMLPortParam(HUDText, "font", setFont, getFont, xmlElement, mode);
82    XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode);
83
84    this->text_->setCaption(this->caption_);
85  }
86
87  void HUDText::setBackgroundMaterial(const std::string& material)
88  {
89    if (this->background_ && material != "")
90      this->background_->setMaterialName(material);
91  }
92
93  std::string HUDText::getBackgroundMaterial() const
94  {
95    if (this->background_)
96      return this->background_->getMaterialName();
97    else
98      return "";
99  }
100
101  void HUDText::setCaption(const std::string& caption)
102  {
103    this->caption_ = caption;
104  }
105
106  const std::string& HUDText::getCaption() const
107  {
108    return this->caption_;
109  }
110
111  void HUDText::setFont(const std::string& font)
112  {
113    if (this->text_ && font != "")
114      this->text_->setFontName(font);
115  }
116
117  std::string HUDText::getFont() const
118  {
119    if (this->text_)
120      return this->text_->getFontName();
121    else
122      return "";
123  }
124}
Note: See TracBrowser for help on using the repository browser.