Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1402 was 1392, checked in by FelixSchulthess, 17 years ago

moved #includes to .cc from .h where possible

File size: 3.9 KB
RevLine 
[1283]1/*
2*   ORXONOX - the hottest 3D action shooter ever to exist
3*
4*
5*   License notice:
6*
7*   This program is free software; you can redistribute it and/or
8*   modify it under the terms of the GNU General Public License
9*   as published by the Free Software Foundation; either version 2
10*   of the License, or (at your option) any later version.
11*
12*   This program is distributed in the hope that it will be useful,
13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*   GNU General Public License for more details.
16*
17*   You should have received a copy of the GNU General Public License
18*   along with this program; if not, write to the Free Software
19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*
21*   Author:
22*      Yuning Chai
23*   Co-authors:
[1328]24*      Felix Schulthess
[1283]25*
26*/
27
28#include <OgreOverlayManager.h>
[1314]29#include "GraphicsEngine.h"
[1283]30#include "BarOverlayElement.h"
31
32namespace orxonox
33{
34  using namespace Ogre;
35
[1392]36    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
[1328]37        name_ = name;
38    }
[1283]39
40    BarOverlayElement::~BarOverlayElement(){}
41
[1392]42    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
[1328]43        // init some values...
44        container_ = container;
[1392]45        om = &OverlayManager::getSingleton();
[1328]46        value_ = 0;
47        color_ = 2;
48        autoColor_ = true;
[1342]49        left2Right = false;     // default is right to left progress
[1314]50        leftRel_ = leftRel;
51        topRel_ = topRel;
[1342]52        dimRel_ = dimRel;
[1392]53
[1328]54        // create background...
[1329]55        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
56        background_->show();
57        container_->addChild(background_);
[1392]58        background_->setMetricsMode(GMM_PIXELS);
[1329]59        background_->setMaterialName("Orxonox/BarBackground");
[1328]60
[1342]61        // calculate absolute coordinates...
62        resize();
63
[1329]64        show();
[1392]65        setMetricsMode(GMM_PIXELS);
[1329]66        setMaterialName("Orxonox/Green");
[1342]67        background_->addChild(this);
[1329]68    }
69
70    void BarOverlayElement::resize(){
71        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
72        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
[1342]73        // calculate new absolute coordinates...
74        left_ = (int) (leftRel_ * windowW_);
75        top_ = (int) (topRel_ * windowH_);
76        width_ = (int) (dimRel_ * windowW_);
77        height_ = (int) (0.1*width_);   // the texture has dimensions height:length = 1:10
[1329]78        // adapt background
79        background_->setPosition(left_, top_);
80        background_->setDimensions(width_, height_);
81        // adapt bar
[1328]82        setValue(value_);
[1283]83    }
84
[1329]85    void BarOverlayElement::setValue(float value){
[1328]86        value_ = value;
87        // set color, if nescessary
88        if(autoColor_){
89            if (value_>0.5) {setColor(BarOverlayElement::GREEN);}
90            else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);}
91            else setColor(BarOverlayElement::RED);
92        }
93        // set value
[1329]94        if(left2Right){ // backward case
95            setPosition(0+width_-width_*value_, 0);
96            setDimensions(width_*value_,height_);
97        }else{          // default case
98            setPosition(0, 0);
99            setDimensions(width_*value_,height_);
[1314]100        }
[1329]101        if(value_ != 0) setTiling(value_, 1.0);
[1283]102    }
[1314]103
[1328]104    void BarOverlayElement::setColor(int color){
105        color_ = color;
106        switch(color){
[1314]107        case 0:
[1329]108            setMaterialName("Orxonox/Red");
[1314]109            break;
110        case 1:
[1329]111            setMaterialName("Orxonox/Yellow");
[1314]112            break;
113        case 2:
[1329]114            setMaterialName("Orxonox/Green");
[1314]115        }
[1283]116    }
117
[1328]118    float BarOverlayElement::getValue(){
119        return(value_);
[1283]120    }
121
[1328]122    int BarOverlayElement::getBarColor(){
123        return(color_);
[1283]124    }
125}
126
127
Note: See TracBrowser for help on using the repository browser.