Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

rewritten navigation algebra… very ugly, and not optimized

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