Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

moved #includes to .cc from .h where possible

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