Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud3/src/orxonox/hud/BarOverlayElement.cc @ 1328

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

edited bar, removed smartbar and replaced functionality with a boolean autoColor to indicate whether the bar should change color automatically

File size: 4.2 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 <OgreOverlayElement.h>
30#include <OgrePanelOverlayElement.h>
31#include "GraphicsEngine.h"
32#include "BarOverlayElement.h"
33
34namespace orxonox
35{
36  using namespace Ogre;
37
38    BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
39        name_ = name;
40    }
41
42    BarOverlayElement::~BarOverlayElement(){}
43
44    void BarOverlayElement::init(Real leftRel, Real topRel, Real widthRel, Real heightRel, Ogre::OverlayContainer* container){
45        // init some values...
46        container_ = container;
47        om = &Ogre::OverlayManager::getSingleton();
48        value_ = 0;
49        color_ = 2;
50        autoColor_ = true;
51        dir_ = BarOverlayElement::RIGHT;
52
53        // get window data...
54        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
55        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
56        leftRel_ = leftRel;
57        topRel_ = topRel;
58        widthRel_ = widthRel;
59        heightRel_ = heightRel;
60
61        // cálculate absolute coordinates...
62        left_ = leftRel_ * windowW_;
63        top_ = topRel_ * windowH_;
64        width_ = widthRel_ * windowW_;
65        height_ = heightRel_ * windowH_;
66
67        // create background...
68        bar_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", name_+"Bar"));
69        bar_->show();
70        container_->addChild(bar_);
71        bar_->setPosition(left_, top_);
72        bar_->setDimensions(width_, height_);
73        bar_->setMetricsMode(Ogre::GMM_PIXELS);
74        bar_->setMaterialName("Orxonox/Green");
75
76        setPosition(left_,top_);
77        setDimensions(width_,height_);
78        setMetricsMode(Ogre::GMM_PIXELS);
79        setMaterialName("Orxonox/BarBackground");
80        setValue(value_);
81    }
82
83
84   void BarOverlayElement::setValue(float value){
85        value_ = value;
86        // set color, if nescessary
87        if(autoColor_){
88            if (value_>0.5) {setColor(BarOverlayElement::GREEN);}
89            else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);}
90            else setColor(BarOverlayElement::RED);
91        }
92        // set value
93        switch(dir_){
94        case BarOverlayElement::DOWN:
95            bar_->setPosition(left_,top_);
96            bar_->setDimensions(width_,height_*value_);
97            break;
98        case BarOverlayElement::LEFT:
99            bar_->setPosition(left_+width_-width_*value_,top_);
100            bar_->setDimensions(width_*value_,height_);
101            break;
102        case BarOverlayElement::UP:
103            bar_->setPosition(left_,top_+height_-height_*value_);
104            bar_->setDimensions(width_,height_*value_);
105            break;
106        default:
107            bar_->setPosition(left_,top_);
108            bar_->setDimensions(width_*value_,height_);
109            break;
110        }
111    }
112
113    void BarOverlayElement::setDir(int dir){
114    }
115
116    void BarOverlayElement::setColor(int color){
117        color_ = color;
118        switch(color){
119        case 0:
120            bar_->setMaterialName("Orxonox/Red");
121            break;
122        case 1:
123            bar_->setMaterialName("Orxonox/Yellow");
124            break;
125        case 2:
126            bar_->setMaterialName("Orxonox/Green");
127        }
128    }
129
130    float BarOverlayElement::getValue(){
131        return(value_);
132    }
133
134    int BarOverlayElement::getBarColor(){
135        return(color_);
136    }
137}
138
139
Note: See TracBrowser for help on using the repository browser.