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 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #include "OrxonoxStableHeaders.h" |
---|
29 | |
---|
30 | #include <OgreOverlayManager.h> |
---|
31 | #include <OgreOverlayElement.h> |
---|
32 | #include <OgreTextAreaOverlayElement.h> |
---|
33 | #include <OgreStringConverter.h> |
---|
34 | #include <string.h> |
---|
35 | |
---|
36 | #include "Bar.h" |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | using namespace Ogre; |
---|
41 | |
---|
42 | Bar::Bar(Real left, Real top, Real width, Real height, |
---|
43 | int dir, int colour, std::string name){ |
---|
44 | Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); |
---|
45 | element = overlayManager.createOverlayElement("Panel",name); |
---|
46 | element->setMetricsMode(Ogre::GMM_PIXELS); |
---|
47 | dir_ = dir; |
---|
48 | left_ = left; |
---|
49 | top_ = top; |
---|
50 | width_ = width; |
---|
51 | height_ = height; |
---|
52 | element->setPosition(left_,top_); |
---|
53 | element->setDimensions(width_,height_); |
---|
54 | setColour(colour); |
---|
55 | } |
---|
56 | |
---|
57 | Bar::~Bar(void){} |
---|
58 | |
---|
59 | |
---|
60 | void Bar::reset(int percentage){ |
---|
61 | switch(dir_){ |
---|
62 | case 1: |
---|
63 | element->setPosition(left_,top_); |
---|
64 | element->setDimensions(width_,height_*percentage/100); |
---|
65 | break; |
---|
66 | case 2: |
---|
67 | element->setPosition(left_+width_-width_*percentage/100,top_); |
---|
68 | element->setDimensions(width_*percentage/100,height_); |
---|
69 | break; |
---|
70 | case 3: |
---|
71 | element->setPosition(left_,top_+height_-height_*percentage/100); |
---|
72 | element->setDimensions(width_,height_*percentage/100); |
---|
73 | break; |
---|
74 | default: |
---|
75 | element->setPosition(left_,top_); |
---|
76 | element->setDimensions(width_*percentage/100,height_); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | void Bar::setColour(int colour){ |
---|
81 | switch(colour){ |
---|
82 | case 0: |
---|
83 | element->setMaterialName("Orxonox/Red"); |
---|
84 | break; |
---|
85 | case 1: |
---|
86 | element->setMaterialName("Orxonox/Yellow"); |
---|
87 | break; |
---|
88 | case 2: |
---|
89 | element->setMaterialName("Orxonox/Green"); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | void Bar::show(){element->show();} |
---|
94 | |
---|
95 | void Bar::hide(){element->hide();} |
---|
96 | |
---|
97 | SmartBar::SmartBar(Ogre::Real left, Ogre::Real top, Ogre::Real width, Ogre::Real height, |
---|
98 | int dir, std::string name) : Bar(left, top, width, height, dir, Bar::YELLOW, name){ |
---|
99 | } |
---|
100 | |
---|
101 | SmartBar::~SmartBar(void){} |
---|
102 | |
---|
103 | |
---|
104 | void SmartBar::reset(int percentage){ |
---|
105 | if (percentage>50) {setColour(Bar::GREEN);} |
---|
106 | else if (percentage>25) {setColour(Bar::YELLOW);} |
---|
107 | else setColour(Bar::RED); |
---|
108 | Bar::reset(percentage); |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | |
---|