Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/hud/BarOverlayElement.cc @ 1505

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

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 4.0 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
[1502]4 *
[1505]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 *
[1502]22 *   Author:
23 *      Yuning Chai
24 *   Co-authors:
25 *      Felix Schulthess
26 *
27 */
[1283]28
[1502]29#include "OrxonoxStableHeaders.h"
30#include "BarOverlayElement.h"
[1283]31#include <OgreOverlayManager.h>
[1314]32#include "GraphicsEngine.h"
[1283]33
34namespace orxonox
35{
[1502]36    using namespace Ogre;
[1283]37
[1502]38    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
[1328]39        name_ = name;
40    }
[1283]41
42    BarOverlayElement::~BarOverlayElement(){}
43
[1502]44    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
[1328]45        // init some values...
46        container_ = container;
[1502]47        om = &OverlayManager::getSingleton();
[1328]48        value_ = 0;
49        color_ = 2;
50        autoColor_ = true;
[1342]51        left2Right = false;     // default is right to left progress
[1314]52        leftRel_ = leftRel;
53        topRel_ = topRel;
[1342]54        dimRel_ = dimRel;
[1502]55
[1328]56        // create background...
[1329]57        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
58        background_->show();
59        container_->addChild(background_);
[1502]60        background_->setMetricsMode(GMM_PIXELS);
[1329]61        background_->setMaterialName("Orxonox/BarBackground");
[1328]62
[1342]63        // calculate absolute coordinates...
64        resize();
65
[1329]66        show();
[1502]67        setMetricsMode(GMM_PIXELS);
[1329]68        setMaterialName("Orxonox/Green");
[1342]69        background_->addChild(this);
[1329]70    }
71
72    void BarOverlayElement::resize(){
73        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
74        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
[1342]75        // calculate new absolute coordinates...
76        left_ = (int) (leftRel_ * windowW_);
77        top_ = (int) (topRel_ * windowH_);
78        width_ = (int) (dimRel_ * windowW_);
79        height_ = (int) (0.1*width_);   // the texture has dimensions height:length = 1:10
[1329]80        // adapt background
81        background_->setPosition(left_, top_);
82        background_->setDimensions(width_, height_);
83        // adapt bar
[1328]84        setValue(value_);
[1283]85    }
86
[1329]87    void BarOverlayElement::setValue(float value){
[1328]88        value_ = value;
89        // set color, if nescessary
90        if(autoColor_){
91            if (value_>0.5) {setColor(BarOverlayElement::GREEN);}
92            else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);}
93            else setColor(BarOverlayElement::RED);
94        }
95        // set value
[1329]96        if(left2Right){ // backward case
97            setPosition(0+width_-width_*value_, 0);
98            setDimensions(width_*value_,height_);
99        }else{          // default case
100            setPosition(0, 0);
101            setDimensions(width_*value_,height_);
[1314]102        }
[1329]103        if(value_ != 0) setTiling(value_, 1.0);
[1283]104    }
[1314]105
[1328]106    void BarOverlayElement::setColor(int color){
107        color_ = color;
108        switch(color){
[1314]109        case 0:
[1329]110            setMaterialName("Orxonox/Red");
[1314]111            break;
112        case 1:
[1329]113            setMaterialName("Orxonox/Yellow");
[1314]114            break;
115        case 2:
[1329]116            setMaterialName("Orxonox/Green");
[1314]117        }
[1283]118    }
119
[1328]120    float BarOverlayElement::getValue(){
121        return(value_);
[1283]122    }
123
[1328]124    int BarOverlayElement::getBarColor(){
125        return(color_);
[1283]126    }
127}
Note: See TracBrowser for help on using the repository browser.