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 <OgreOverlayManager.h> |
---|
29 | #include <OgreOverlayElement.h> |
---|
30 | #include <OgrePanelOverlayElement.h> |
---|
31 | |
---|
32 | |
---|
33 | #include "BarOverlayElement.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | using namespace Ogre; |
---|
38 | |
---|
39 | |
---|
40 | BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){} |
---|
41 | |
---|
42 | BarOverlayElement::~BarOverlayElement(){} |
---|
43 | |
---|
44 | void BarOverlayElement::initialise(){ |
---|
45 | PanelOverlayElement::initialise(); |
---|
46 | /* setDimensions(100,100); |
---|
47 | setPosition(10,10); |
---|
48 | setMaterialName("Orxonox/Green"); |
---|
49 | setMetricsMode(Ogre::GMM_PIXELS); |
---|
50 | */ } |
---|
51 | |
---|
52 | |
---|
53 | void BarOverlayElement::initBarOverlayElement(Real left, Real top, Real width, Real height, |
---|
54 | int dir, int colour){ |
---|
55 | setMetricsMode(Ogre::GMM_PIXELS); |
---|
56 | dir_ = dir; |
---|
57 | left_ = left; |
---|
58 | top_ = top; |
---|
59 | width_ = width; |
---|
60 | height_ = height; |
---|
61 | setPosition(left_,top_); |
---|
62 | setDimensions(width_,height_); |
---|
63 | setColour(colour); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | void BarOverlayElement::reset(int percentage){ |
---|
68 | switch(dir_){ |
---|
69 | case 1: |
---|
70 | setPosition(left_,top_); |
---|
71 | setDimensions(width_,height_*percentage/100); |
---|
72 | break; |
---|
73 | case 2: |
---|
74 | setPosition(left_+width_-width_*percentage/100,top_); |
---|
75 | setDimensions(width_*percentage/100,height_); |
---|
76 | break; |
---|
77 | case 3: |
---|
78 | setPosition(left_,top_+height_-height_*percentage/100); |
---|
79 | setDimensions(width_,height_*percentage/100); |
---|
80 | break; |
---|
81 | default: |
---|
82 | setPosition(left_,top_); |
---|
83 | setDimensions(width_*percentage/100,height_); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | void BarOverlayElement::setColour(int colour){ |
---|
89 | switch(colour){ |
---|
90 | case 0: |
---|
91 | setMaterialName("Orxonox/Red"); |
---|
92 | break; |
---|
93 | case 1: |
---|
94 | setMaterialName("Orxonox/Yellow"); |
---|
95 | break; |
---|
96 | case 2: |
---|
97 | setMaterialName("Orxonox/Green"); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | SmartBarOverlayElement::SmartBarOverlayElement(const String& name):BarOverlayElement(name){} |
---|
103 | |
---|
104 | SmartBarOverlayElement::~SmartBarOverlayElement(void){} |
---|
105 | |
---|
106 | |
---|
107 | void SmartBarOverlayElement::initialise(){ |
---|
108 | PanelOverlayElement::initialise(); |
---|
109 | /* setDimensions(100,100); |
---|
110 | setPosition(10,10); |
---|
111 | setMaterialName("Orxonox/Green"); |
---|
112 | setMetricsMode(Ogre::GMM_PIXELS); |
---|
113 | */ } |
---|
114 | |
---|
115 | void SmartBarOverlayElement::initSmartBarOverlayElement(Real left, Real top, Real width, Real height, int dir) |
---|
116 | { |
---|
117 | BarOverlayElement::initBarOverlayElement(left, top, width, height, dir, BarOverlayElement::GREEN); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | void SmartBarOverlayElement::reset(int percentage){ |
---|
122 | if (percentage>50) {setColour(BarOverlayElement::GREEN);} |
---|
123 | else if (percentage>25) {setColour(BarOverlayElement::YELLOW);} |
---|
124 | else setColour(BarOverlayElement::RED); |
---|
125 | BarOverlayElement::reset(percentage); |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | |
---|