[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; |
---|
| 51 | dir_ = BarOverlayElement::RIGHT; |
---|
[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... |
---|
| 68 | bar_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", name_+"Bar")); |
---|
| 69 | bar_->show(); |
---|
| 70 | container_->addChild(bar_); |
---|
| 71 | bar_->setPosition(left_, top_); |
---|
| 72 | bar_->setDimensions(width_, height_); |
---|
| 73 | bar_->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 74 | bar_->setMaterialName("Orxonox/Green"); |
---|
| 75 | |
---|
[1314] | 76 | setPosition(left_,top_); |
---|
| 77 | setDimensions(width_,height_); |
---|
[1328] | 78 | setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 79 | setMaterialName("Orxonox/BarBackground"); |
---|
| 80 | setValue(value_); |
---|
[1283] | 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
[1328] | 84 | void BarOverlayElement::setValue(float value){ |
---|
| 85 | value_ = value; |
---|
| 86 | // set color, if nescessary |
---|
| 87 | if(autoColor_){ |
---|
| 88 | if (value_>0.5) {setColor(BarOverlayElement::GREEN);} |
---|
| 89 | else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);} |
---|
| 90 | else setColor(BarOverlayElement::RED); |
---|
| 91 | } |
---|
| 92 | // set value |
---|
[1314] | 93 | switch(dir_){ |
---|
[1328] | 94 | case BarOverlayElement::DOWN: |
---|
| 95 | bar_->setPosition(left_,top_); |
---|
| 96 | bar_->setDimensions(width_,height_*value_); |
---|
[1314] | 97 | break; |
---|
[1328] | 98 | case BarOverlayElement::LEFT: |
---|
| 99 | bar_->setPosition(left_+width_-width_*value_,top_); |
---|
| 100 | bar_->setDimensions(width_*value_,height_); |
---|
[1314] | 101 | break; |
---|
[1328] | 102 | case BarOverlayElement::UP: |
---|
| 103 | bar_->setPosition(left_,top_+height_-height_*value_); |
---|
| 104 | bar_->setDimensions(width_,height_*value_); |
---|
[1314] | 105 | break; |
---|
| 106 | default: |
---|
[1328] | 107 | bar_->setPosition(left_,top_); |
---|
| 108 | bar_->setDimensions(width_*value_,height_); |
---|
| 109 | break; |
---|
[1314] | 110 | } |
---|
[1283] | 111 | } |
---|
[1314] | 112 | |
---|
[1328] | 113 | void BarOverlayElement::setDir(int dir){ |
---|
| 114 | } |
---|
[1314] | 115 | |
---|
[1328] | 116 | void BarOverlayElement::setColor(int color){ |
---|
| 117 | color_ = color; |
---|
| 118 | switch(color){ |
---|
[1314] | 119 | case 0: |
---|
[1328] | 120 | bar_->setMaterialName("Orxonox/Red"); |
---|
[1314] | 121 | break; |
---|
| 122 | case 1: |
---|
[1328] | 123 | bar_->setMaterialName("Orxonox/Yellow"); |
---|
[1314] | 124 | break; |
---|
| 125 | case 2: |
---|
[1328] | 126 | bar_->setMaterialName("Orxonox/Green"); |
---|
[1314] | 127 | } |
---|
[1283] | 128 | } |
---|
| 129 | |
---|
[1328] | 130 | float BarOverlayElement::getValue(){ |
---|
| 131 | return(value_); |
---|
[1283] | 132 | } |
---|
| 133 | |
---|
[1328] | 134 | int BarOverlayElement::getBarColor(){ |
---|
| 135 | return(color_); |
---|
[1283] | 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|