Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1362 was 1362, checked in by scheusso, 17 years ago

merged hud3 branch into trunk and changed camera orientation

File size: 4.0 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 dimRel, 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        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(Ogre::GMM_PIXELS);
61        background_->setMaterialName("Orxonox/BarBackground");
62
63        // calculate absolute coordinates...
64        resize();
65
66        show();
67        setMetricsMode(Ogre::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}
128
129
Note: See TracBrowser for help on using the repository browser.