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