Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/hud/BarOverlayElement.cc @ 1494

Last change on this file since 1494 was 1494, checked in by rgrieder, 17 years ago
  • set the svn:eol-style property to all files so, that where ever you check out, you'll get the right line endings (had to change every file with mixed endings to windows in order to set the property)
  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
2 *   Author:
3 *      Yuning Chai
4 *   Co-authors:
5 *      Felix Schulthess
6 *
7 */
8
9#include "OrxonoxStableHeaders.h"
10#include "BarOverlayElement.h"
11#include <OgreOverlayManager.h>
12#include "GraphicsEngine.h"
13
14namespace orxonox
15{
16    using namespace Ogre;
17
18    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
19        name_ = name;
20    }
21
22    BarOverlayElement::~BarOverlayElement(){}
23
24    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
25        // init some values...
26        container_ = container;
27        om = &OverlayManager::getSingleton();
28        value_ = 0;
29        color_ = 2;
30        autoColor_ = true;
31        left2Right = false;     // default is right to left progress
32        leftRel_ = leftRel;
33        topRel_ = topRel;
34        dimRel_ = dimRel;
35
36        // create background...
37        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
38        background_->show();
39        container_->addChild(background_);
40        background_->setMetricsMode(GMM_PIXELS);
41        background_->setMaterialName("Orxonox/BarBackground");
42
43        // calculate absolute coordinates...
44        resize();
45
46        show();
47        setMetricsMode(GMM_PIXELS);
48        setMaterialName("Orxonox/Green");
49        background_->addChild(this);
50    }
51
52    void BarOverlayElement::resize(){
53        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
54        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
55        // calculate new absolute coordinates...
56        left_ = (int) (leftRel_ * windowW_);
57        top_ = (int) (topRel_ * windowH_);
58        width_ = (int) (dimRel_ * windowW_);
59        height_ = (int) (0.1*width_);   // the texture has dimensions height:length = 1:10
60        // adapt background
61        background_->setPosition(left_, top_);
62        background_->setDimensions(width_, height_);
63        // adapt bar
64        setValue(value_);
65    }
66
67    void BarOverlayElement::setValue(float value){
68        value_ = value;
69        // set color, if nescessary
70        if(autoColor_){
71            if (value_>0.5) {setColor(BarOverlayElement::GREEN);}
72            else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);}
73            else setColor(BarOverlayElement::RED);
74        }
75        // set value
76        if(left2Right){ // backward case
77            setPosition(0+width_-width_*value_, 0);
78            setDimensions(width_*value_,height_);
79        }else{          // default case
80            setPosition(0, 0);
81            setDimensions(width_*value_,height_);
82        }
83        if(value_ != 0) setTiling(value_, 1.0);
84    }
85
86    void BarOverlayElement::setColor(int color){
87        color_ = color;
88        switch(color){
89        case 0:
90            setMaterialName("Orxonox/Red");
91            break;
92        case 1:
93            setMaterialName("Orxonox/Yellow");
94            break;
95        case 2:
96            setMaterialName("Orxonox/Green");
97        }
98    }
99
100    float BarOverlayElement::getValue(){
101        return(value_);
102    }
103
104    int BarOverlayElement::getBarColor(){
105        return(color_);
106    }
107}
Note: See TracBrowser for help on using the repository browser.