| 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 | * Felix Schulthess |
|---|
| 25 | * |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #include "OrxonoxStableHeaders.h" |
|---|
| 29 | #include <OgreOverlayManager.h> |
|---|
| 30 | #include <OgreOverlayElement.h> |
|---|
| 31 | #include <OgrePanelOverlayElement.h> |
|---|
| 32 | #include "GraphicsEngine.h" |
|---|
| 33 | #include "BarOverlayElement.h" |
|---|
| 34 | |
|---|
| 35 | namespace orxonox |
|---|
| 36 | { |
|---|
| 37 | using namespace Ogre; |
|---|
| 38 | |
|---|
| 39 | BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ |
|---|
| 40 | name_ = name; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | BarOverlayElement::~BarOverlayElement(){} |
|---|
| 44 | |
|---|
| 45 | void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ |
|---|
| 46 | // init some values... |
|---|
| 47 | container_ = container; |
|---|
| 48 | om = &Ogre::OverlayManager::getSingleton(); |
|---|
| 49 | value_ = 0; |
|---|
| 50 | color_ = 2; |
|---|
| 51 | autoColor_ = true; |
|---|
| 52 | left2Right = false; // default is right to left progress |
|---|
| 53 | leftRel_ = leftRel; |
|---|
| 54 | topRel_ = topRel; |
|---|
| 55 | dimRel_ = dimRel; |
|---|
| 56 | |
|---|
| 57 | // create background... |
|---|
| 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"); |
|---|
| 63 | |
|---|
| 64 | // calculate absolute coordinates... |
|---|
| 65 | resize(); |
|---|
| 66 | |
|---|
| 67 | show(); |
|---|
| 68 | setMetricsMode(Ogre::GMM_PIXELS); |
|---|
| 69 | setMaterialName("Orxonox/Green"); |
|---|
| 70 | background_->addChild(this); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void BarOverlayElement::resize(){ |
|---|
| 74 | windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); |
|---|
| 75 | windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); |
|---|
| 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 |
|---|
| 81 | // adapt background |
|---|
| 82 | background_->setPosition(left_, top_); |
|---|
| 83 | background_->setDimensions(width_, height_); |
|---|
| 84 | // adapt bar |
|---|
| 85 | setValue(value_); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void BarOverlayElement::setValue(float value){ |
|---|
| 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 |
|---|
| 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_); |
|---|
| 103 | } |
|---|
| 104 | if(value_ != 0) setTiling(value_, 1.0); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | void BarOverlayElement::setColor(int color){ |
|---|
| 108 | color_ = color; |
|---|
| 109 | switch(color){ |
|---|
| 110 | case 0: |
|---|
| 111 | setMaterialName("Orxonox/Red"); |
|---|
| 112 | break; |
|---|
| 113 | case 1: |
|---|
| 114 | setMaterialName("Orxonox/Yellow"); |
|---|
| 115 | break; |
|---|
| 116 | case 2: |
|---|
| 117 | setMaterialName("Orxonox/Green"); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | float BarOverlayElement::getValue(){ |
|---|
| 122 | return(value_); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | int BarOverlayElement::getBarColor(){ |
|---|
| 126 | return(color_); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|