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