Changeset 1564 for code/trunk/src/orxonox/hud/BarOverlayElement.cc
- Timestamp:
- Jun 8, 2008, 5:46:52 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/BarOverlayElement.cc
r1505 r1564 31 31 #include <OgreOverlayManager.h> 32 32 #include "GraphicsEngine.h" 33 #include "util/Math.h" 33 34 34 35 namespace orxonox … … 36 37 using namespace Ogre; 37 38 38 BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){ 39 BarOverlayElement::BarOverlayElement(const String& name) : PanelOverlayElement(name) 40 { 39 41 name_ = name; 42 widthratio_ = 100.0f / 800.0f; // calculates the ratio (backgroundwidth - barwidth) / backgroundwidth 40 43 } 41 44 42 BarOverlayElement::~BarOverlayElement(){} 45 BarOverlayElement::~BarOverlayElement() 46 { 47 OverlayManager::getSingleton().destroyOverlayElement(this->background_); 48 } 43 49 44 50 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 45 51 // init some values... 46 container_ = container;47 om = &OverlayManager::getSingleton();48 52 value_ = 0; 49 colo r_ = 2;50 autoColo r_ = true;51 left2Right = false; // default is right to left progress53 colour_ = 2; 54 autoColour_ = true; 55 right2Left_ = false; // default is left to right progress 52 56 leftRel_ = leftRel; 53 57 topRel_ = topRel; … … 55 59 56 60 // create background... 57 background_ = static_cast<OverlayContainer*>( om->createOverlayElement("Panel", name_+"container"));61 background_ = static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement("Panel", name_+"container")); 58 62 background_->show(); 59 container _->addChild(background_);63 container->addChild(background_); 60 64 background_->setMetricsMode(GMM_PIXELS); 61 65 background_->setMaterialName("Orxonox/BarBackground"); … … 71 75 72 76 void BarOverlayElement::resize(){ 73 windowW_ = GraphicsEngine::getSingleton().getWindowWidth();74 windowH_ = GraphicsEngine::getSingleton().getWindowHeight();75 77 // calculate new absolute coordinates... 76 left_ = (int) (leftRel_ * windowW_); 77 top_ = (int) (topRel_ * windowH_); 78 width_ = (int) (dimRel_ * windowW_); 79 height_ = (int) (0.1*width_); // the texture has dimensions height:length = 1:10 78 left_ = (int) (leftRel_ * GraphicsEngine::getSingleton().getWindowWidth()); 79 top_ = (int) (topRel_ * GraphicsEngine::getSingleton().getWindowHeight()); 80 width_ = (int) (dimRel_ * GraphicsEngine::getSingleton().getWindowWidth()); 81 height_ = (int) (0.1 * width_); // the texture has dimensions height:length = 1:10 82 offset_ = (int) (width_ * widthratio_ * 0.5); 83 barwidth_ = (int) (width_ * (1.0f - widthratio_)); 84 80 85 // adapt background 81 86 background_->setPosition(left_, top_); … … 86 91 87 92 void BarOverlayElement::setValue(float value){ 88 value_ = value;89 // set colo r, if nescessary90 if(autoColo r_){91 if (value_>0.5) {setColo r(BarOverlayElement::GREEN);}92 else if (value_>0.25) {setColo r(BarOverlayElement::YELLOW);}93 else setColo r(BarOverlayElement::RED);93 value_ = clamp<float>(value, 0, 1); 94 // set colour, if nescessary 95 if(autoColour_){ 96 if (value_>0.5) {setColour(BarOverlayElement::GREEN);} 97 else if (value_>0.25) {setColour(BarOverlayElement::YELLOW);} 98 else setColour(BarOverlayElement::RED); 94 99 } 100 95 101 // set value 96 if( left2Right){ // backward case97 setPosition( 0+width_-width_*value_, 0);98 setDimensions( width_*value_,height_);102 if(right2Left_){ // backward case 103 setPosition(offset_ + barwidth_ * (1 - value_), 0); 104 setDimensions(barwidth_ * value_, height_); 99 105 }else{ // default case 100 setPosition( 0, 0);101 setDimensions( width_*value_,height_);106 setPosition(offset_, 0); 107 setDimensions(barwidth_ * value_, height_); 102 108 } 103 109 if(value_ != 0) setTiling(value_, 1.0); 104 110 } 105 111 106 void BarOverlayElement::setColo r(int color){107 colo r_ = color;108 switch(colo r){112 void BarOverlayElement::setColour(int colour){ 113 colour_ = colour; 114 switch(colour){ 109 115 case 0: 110 116 setMaterialName("Orxonox/Red"); … … 117 123 } 118 124 } 119 120 float BarOverlayElement::getValue(){121 return(value_);122 }123 124 int BarOverlayElement::getBarColor(){125 return(color_);126 }127 125 }
Note: See TracChangeset
for help on using the changeset viewer.