Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1406 was 1406, checked in by rgrieder, 16 years ago
  • merged Felix's changes from trunk to network branch
  • added "svn:eol-style native" property to keybindings.ini
File size: 3.9 KB
RevLine 
[1283]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:
[1328]24*      Felix Schulthess
[1283]25*
26*/
27
[1373]28#include "OrxonoxStableHeaders.h"
[1283]29#include <OgreOverlayManager.h>
[1314]30#include "GraphicsEngine.h"
[1283]31#include "BarOverlayElement.h"
32
33namespace orxonox
34{
35  using namespace Ogre;
36
[1406]37    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
[1328]38        name_ = name;
39    }
[1283]40
41    BarOverlayElement::~BarOverlayElement(){}
42
[1406]43    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
[1328]44        // init some values...
45        container_ = container;
[1406]46        om = &OverlayManager::getSingleton();
[1328]47        value_ = 0;
48        color_ = 2;
49        autoColor_ = true;
[1342]50        left2Right = false;     // default is right to left progress
[1314]51        leftRel_ = leftRel;
52        topRel_ = topRel;
[1342]53        dimRel_ = dimRel;
[1406]54
[1328]55        // create background...
[1329]56        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
57        background_->show();
58        container_->addChild(background_);
[1406]59        background_->setMetricsMode(GMM_PIXELS);
[1329]60        background_->setMaterialName("Orxonox/BarBackground");
[1328]61
[1342]62        // calculate absolute coordinates...
63        resize();
64
[1329]65        show();
[1406]66        setMetricsMode(GMM_PIXELS);
[1329]67        setMaterialName("Orxonox/Green");
[1342]68        background_->addChild(this);
[1329]69    }
70
71    void BarOverlayElement::resize(){
72        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
73        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
[1342]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
[1329]79        // adapt background
80        background_->setPosition(left_, top_);
81        background_->setDimensions(width_, height_);
82        // adapt bar
[1328]83        setValue(value_);
[1283]84    }
85
[1329]86    void BarOverlayElement::setValue(float value){
[1328]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
[1329]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_);
[1314]101        }
[1329]102        if(value_ != 0) setTiling(value_, 1.0);
[1283]103    }
[1314]104
[1328]105    void BarOverlayElement::setColor(int color){
106        color_ = color;
107        switch(color){
[1314]108        case 0:
[1329]109            setMaterialName("Orxonox/Red");
[1314]110            break;
111        case 1:
[1329]112            setMaterialName("Orxonox/Yellow");
[1314]113            break;
114        case 2:
[1329]115            setMaterialName("Orxonox/Green");
[1314]116        }
[1283]117    }
118
[1328]119    float BarOverlayElement::getValue(){
120        return(value_);
[1283]121    }
122
[1328]123    int BarOverlayElement::getBarColor(){
124        return(color_);
[1283]125    }
126}
127
128
[1373]129
Note: See TracBrowser for help on using the repository browser.