Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud/src/orxonox/hud/Bar.cc @ 980

Last change on this file since 980 was 980, checked in by chaiy, 16 years ago

hallo

File size: 2.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*      ...
25*
26*/
27
28#include <OgreOverlayManager.h>
29#include <OgreOverlayElement.h>
30#include <OgreTextAreaOverlayElement.h>
31#include <OgreStringConverter.h>
32#include <string.h>
33
34#include "Bar.h"
35
36namespace orxonox
37{
38  using namespace Ogre;
39   
40  Bar::Bar(Real left, Real top, Real width, Real height,
41          int dir,  int colour, std::string name){
42    Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
43    element = overlayManager.createOverlayElement("Panel",name);
44    element->setMetricsMode(Ogre::GMM_PIXELS);
45    dir_ = dir;
46    left_ = left;
47    top_ = top;
48    width_ = width;
49    height_ = height;
50    element->setPosition(left_,top_);
51    element->setDimensions(width_,height_);
52    setColour(colour);
53  }
54 
55  Bar::~Bar(void){}
56 
57 
58  void Bar::reset(int percentage){
59    switch(dir_){
60      case 1:
61        element->setPosition(left_,top_);
62        element->setDimensions(width_,height_*percentage/100);
63        break;
64      case 2:
65        element->setPosition(left_+width_-width_*percentage/100,top_);
66        element->setDimensions(width_*percentage/100,height_);
67        break;
68      case 3:
69        element->setPosition(left_,top_+height_-height_*percentage/100);
70        element->setDimensions(width_,height_*percentage/100);
71        break;
72      default:
73        element->setPosition(left_,top_);
74        element->setDimensions(width_*percentage/100,height_); 
75    }
76  }
77
78  void Bar::setColour(int colour){
79    switch(colour){
80     case 0:
81        element->setMaterialName("Orxonox/Red");
82        break;
83     case 1:
84        element->setMaterialName("Orxonox/Yellow");
85        break;
86     case 2:
87        element->setMaterialName("Orxonox/Green");
88    }
89  }
90
91  void Bar::show(){element->show();}
92
93  void Bar::hide(){element->hide();}
94
95  SmartBar::SmartBar(Ogre::Real left, Ogre::Real top, Ogre::Real width, Ogre::Real height,
96        int dir, std::string name) : Bar::Bar(left, top, width, height, dir, Bar::YELLOW, name){
97  }
98
99  SmartBar::~SmartBar(void){}
100
101
102  void SmartBar::reset(int percentage){
103    if (percentage>50) {setColour(Bar::GREEN);}
104    else if (percentage>25) {setColour(Bar::YELLOW);}
105    else setColour(Bar::RED);
106    Bar::reset(percentage);
107  }
108
109}
110
111
Note: See TracBrowser for help on using the repository browser.