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
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 *      Yuning Chai
24 *   Co-authors:
25 *      Felix Schulthess
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "BarOverlayElement.h"
31#include <OgreOverlayManager.h>
32#include "GraphicsEngine.h"
33
34namespace orxonox
35{
36    using namespace Ogre;
37
38    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
39        name_ = name;
40    }
41
42    BarOverlayElement::~BarOverlayElement(){}
43
44    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
45        // init some values...
46        container_ = container;
47        om = &OverlayManager::getSingleton();
48        value_ = 0;
49        color_ = 2;
50        autoColor_ = true;
51        left2Right = false;     // default is right to left progress
52        leftRel_ = leftRel;
53        topRel_ = topRel;
54        dimRel_ = dimRel;
55
56        // create background...
57        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
58        background_->show();
59        container_->addChild(background_);
60        background_->setMetricsMode(GMM_PIXELS);
61        background_->setMaterialName("Orxonox/BarBackground");
62
63        // calculate absolute coordinates...
64        resize();
65
66        show();
67        setMetricsMode(GMM_PIXELS);
68        setMaterialName("Orxonox/Green");
69        background_->addChild(this);
70    }
71
72    void BarOverlayElement::resize(){
73        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
74        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
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
80        // adapt background
81        background_->setPosition(left_, top_);
82        background_->setDimensions(width_, height_);
83        // adapt bar
84        setValue(value_);
85    }
86
87    void BarOverlayElement::setValue(float value){
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
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_);
102        }
103        if(value_ != 0) setTiling(value_, 1.0);
104    }
105
106    void BarOverlayElement::setColor(int color){
107        color_ = color;
108        switch(color){
109        case 0:
110            setMaterialName("Orxonox/Red");
111            break;
112        case 1:
113            setMaterialName("Orxonox/Yellow");
114            break;
115        case 2:
116            setMaterialName("Orxonox/Green");
117        }
118    }
119
120    float BarOverlayElement::getValue(){
121        return(value_);
122    }
123
124    int BarOverlayElement::getBarColor(){
125        return(color_);
126    }
127}
Note: See TracBrowser for help on using the repository browser.