Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (17 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/overlays/hud/HUDBar.cc

    r1854 r2087  
    3838
    3939#include "util/Convert.h"
     40#include "util/String.h"
    4041#include "core/CoreIncludes.h"
    4142#include "core/XMLPort.h"
     
    4546    CreateFactory(BarColour);
    4647
    47     BarColour::BarColour()
    48         : position_(0.0)
     48    BarColour::BarColour(BaseObject* creator)
     49        : BaseObject(creator)
    4950    {
    5051        RegisterObject(BarColour);
     52
     53        setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
     54        setPosition(0.0);
    5155    }
    5256
     
    5559        SUPER(BarColour, XMLPort, xmlElement, mode);
    5660
    57         XMLPortParam(BarColour, "colour", setColour, getColour, xmlElement, mode)
    58             .defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0));
    59         XMLPortParam(BarColour, "position", setPosition, getPosition, xmlElement, mode).defaultValues(0.0f);
     61        XMLPortParam(BarColour, "colour", setColour, getColour, xmlElement, mode);
     62        XMLPortParam(BarColour, "position", setPosition, getPosition, xmlElement, mode);
    6063    }
    6164
     
    6366    unsigned int HUDBar::materialcount_s = 0;
    6467
    65     HUDBar::HUDBar()
    66         : bar_(0)
    67         , textureUnitState_(0)
     68    HUDBar::HUDBar(BaseObject* creator)
     69        : OrxonoxOverlay(creator)
    6870    {
    6971        RegisterObject(HUDBar);
     72
     73        // create new material
     74        std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++);
     75        Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General");
     76        material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
     77        this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState();
     78        this->textureUnitState_->setTextureName("bar2.tga");
     79        // use the default colour
     80        this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2));
     81
     82        this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
     83            .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString()));
     84        this->bar_->setMaterialName(materialname);
     85
     86        setValue(0.4567654f);
     87        setRightToLeft(false);
     88        setAutoColour(true);
     89
     90        this->background_->addChild(bar_);
    7091    }
    7192
    7293    HUDBar::~HUDBar()
    7394    {
    74         if (this->bar_)
     95        if (this->isInitialized())
    7596            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->bar_);
    7697    }
     
    80101        SUPER(HUDBar, XMLPort, xmlElement, mode);
    81102
    82         if (mode == XMLPort::LoadObject)
    83         {
    84             // create new material
    85             std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++);
    86             Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General");
    87             material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
    88             this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState();
    89             this->textureUnitState_->setTextureName("bar2.tga");
    90             // use the default colour
    91             this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2));
    92 
    93             this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    94                 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberStr()));
    95             this->bar_->setMaterialName(materialname);
    96             this->background_->addChild(bar_);
    97         }
    98 
    99         XMLPortParam(HUDBar, "initialValue", setValue,       getValue,       xmlElement, mode).defaultValues(0.4567654f);
    100         XMLPortParam(HUDBar, "rightToLeft",  setRightToLeft, getRightToLeft, xmlElement, mode).defaultValues(false);
    101         XMLPortParam(HUDBar, "autoColour",   setAutoColour,  getAutoColour,  xmlElement, mode).defaultValues(true);
     103        XMLPortParam(HUDBar, "initialValue", setValue,       getValue,       xmlElement, mode);
     104        XMLPortParam(HUDBar, "rightToLeft",  setRightToLeft, getRightToLeft, xmlElement, mode);
     105        XMLPortParam(HUDBar, "autoColour",   setAutoColour,  getAutoColour,  xmlElement, mode);
    102106        XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlElement, mode);
    103107    }
Note: See TracChangeset for help on using the changeset viewer.