Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

progress bars now resize automatically and have a new look

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        left2Right = false; // default: right to left progress
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        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
69        background_->show();
70        container_->addChild(background_);
71        background_->setMetricsMode(Ogre::GMM_PIXELS);
72        background_->setMaterialName("Orxonox/BarBackground");
73
74        show();
75        background_->addChild(this);
76        setMetricsMode(Ogre::GMM_PIXELS);
77        setMaterialName("Orxonox/Green");
78        resize();
79    }
80
81    void BarOverlayElement::resize(){
82        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
83        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
84        // cálculate new absolute coordinates...
85        left_ = leftRel_ * windowW_;
86        top_ = topRel_ * windowH_;
87        width_ = widthRel_ * windowW_;
88        height_ = heightRel_ * windowH_;
89        // adapt background
90        background_->setPosition(left_, top_);
91        background_->setDimensions(width_, height_);
92        // adapt bar
93        setValue(value_);
94    }
95
96    void BarOverlayElement::setValue(float value){
97        value_ = value;
98        // set color, if nescessary
99        if(autoColor_){
100            if (value_>0.5) {setColor(BarOverlayElement::GREEN);}
101            else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);}
102            else setColor(BarOverlayElement::RED);
103        }
104        // set value
105        if(left2Right){ // backward case
106            setPosition(0+width_-width_*value_, 0);
107            setDimensions(width_*value_,height_);
108        }else{          // default case
109            setPosition(0, 0);
110            setDimensions(width_*value_,height_);
111        }
112        if(value_ != 0) setTiling(value_, 1.0);
113    }
114
115    void BarOverlayElement::setColor(int color){
116        color_ = color;
117        switch(color){
118        case 0:
119            setMaterialName("Orxonox/Red");
120            break;
121        case 1:
122            setMaterialName("Orxonox/Yellow");
123            break;
124        case 2:
125            setMaterialName("Orxonox/Green");
126        }
127    }
128
129    float BarOverlayElement::getValue(){
130        return(value_);
131    }
132
133    int BarOverlayElement::getBarColor(){
134        return(color_);
135    }
136}
137
138
Note: See TracBrowser for help on using the repository browser.