Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 22, 2008, 12:06:55 AM (16 years ago)
Author:
rgrieder
Message:
  • 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
File:
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/hud/src/orxonox/overlays/OverlayText.cc

    r1614 r1615  
    2828
    2929#include "OrxonoxStableHeaders.h"
    30 #include "HUDText.h"
     30#include "OverlayText.h"
    3131
    3232#include <OgreOverlayManager.h>
     
    3535
    3636#include "util/Convert.h"
     37#include "util/String.h"
    3738
    3839namespace orxonox
    3940{
    40   CreateFactory(HUDText);
     41    CreateFactory(OverlayText);
    4142
    42   using namespace Ogre;
    43 
    44   HUDText::HUDText()
    45     : text_(0)
    46   {
    47     RegisterObject(HUDText);
    48   }
    49 
    50   HUDText::~HUDText()
    51   {
    52     if (this->isInitialized())
     43    OverlayText::OverlayText()
     44        : text_(0)
    5345    {
    54       if (this->text_)
    55           OverlayManager::getSingleton().destroyOverlayElement(this->text_);
    56     }
    57   }
    58 
    59   void HUDText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
    60   {
    61     OrxonoxOverlay::XMLPort(xmlElement, mode);
    62 
    63     if (mode == XMLPort::LoadObject)
    64     {
    65       this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text"));
    66       this->text_->setCharHeight(1.0f);
    67       this->text_->setFontName("Monofur");
    68 
    69       this->background_->addChild(this->text_);
     46        RegisterObject(OverlayText);
    7047    }
    7148
    72     XMLPortParam(HUDText, "font", setFont, getFont, xmlElement, mode);
    73     XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode);
     49    OverlayText::~OverlayText()
     50    {
     51        if (this->text_)
     52            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
     53    }
    7454
    75     if (mode == XMLPort::LoadObject)
     55    void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode)
    7656    {
    77       this->text_->setCaption(this->caption_);
     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        }
    7884    }
    79   }
    8085
    81   void HUDText::setCaption(const std::string& caption)
    82   {
    83     this->caption_ = caption;
    84   }
     86    void OverlayText::setFont(const std::string& font)
     87    {
     88        if (this->text_ && font != "")
     89            this->text_->setFontName(font);
     90    }
    8591
    86   const std::string& HUDText::getCaption() const
    87   {
    88     return this->caption_;
    89   }
     92    const std::string& OverlayText::getFont() const
     93    {
     94        if (this->text_)
     95            return this->text_->getFontName();
     96        else
     97            return blankString;
     98    }
    9099
    91   void HUDText::setFont(const std::string& font)
    92   {
    93     if (this->text_ && font != "")
    94       this->text_->setFontName(font);
    95   }
    96 
    97   std::string HUDText::getFont() const
    98   {
    99     if (this->text_)
    100       return this->text_->getFontName();
    101     else
    102       return "";
    103   }
     100    void OverlayText::sizeChanged()
     101    {
     102        this->overlay_->setScale(getSize().y, getSize().y);
     103        positionChanged();
     104    }
    104105}
Note: See TracChangeset for help on using the changeset viewer.