Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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