1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "glmenu_imagescreen.h" |
---|
20 | |
---|
21 | #include "graphics_engine.h" |
---|
22 | #include "material.h" |
---|
23 | #include "factory.h" |
---|
24 | #include "load_param.h" |
---|
25 | |
---|
26 | CREATE_FACTORY(GLMenuImageScreen); |
---|
27 | |
---|
28 | |
---|
29 | using namespace std; |
---|
30 | /** |
---|
31 | * @param root The Element to load the GLMenu from |
---|
32 | */ |
---|
33 | GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root) |
---|
34 | { |
---|
35 | this->setClassID(CL_GLMENU_IMAGE_SCREEN, "GLMenuImageScreen"); |
---|
36 | this->setName("GLMenuLoadScreen"); |
---|
37 | // Select Our VU Meter Background Texture |
---|
38 | this->backMat = new Material("load_screen"); |
---|
39 | this->barMat = new Material("bar"); |
---|
40 | this->maxValue = 10; |
---|
41 | this->currentValue = 0; |
---|
42 | this->setPosition(0,0); |
---|
43 | this->setScale(1,1); |
---|
44 | this->setBarPosScale( .6, .75, .3, .1); |
---|
45 | // End of Background image code. |
---|
46 | |
---|
47 | if (root != NULL) |
---|
48 | this->loadParams(root); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Loads a GLMenu from an inputElement |
---|
53 | * @param root The Element to load the GLMenu from |
---|
54 | */ |
---|
55 | void GLMenuImageScreen::loadParams(const TiXmlElement* root) |
---|
56 | { |
---|
57 | LoadParam<GLMenuImageScreen>(root, "BackgroundImage", this, &GLMenuImageScreen::setBackgroundImage) |
---|
58 | .describe("sets the image to load onto the loadscreen"); |
---|
59 | |
---|
60 | LoadParam<GLMenuImageScreen>(root, "BackgroundPS", this, &GLMenuImageScreen::setPosScale) |
---|
61 | .describe("The Position and Scale of the Background Image in %(0-1.0). PosX, PosY, SizeX, SizeY"); |
---|
62 | |
---|
63 | LoadParam<GLMenuImageScreen>(root, "BarImage", this, &GLMenuImageScreen::setBarImage) |
---|
64 | .describe("sets the image of the LoadingBar"); |
---|
65 | |
---|
66 | LoadParam<GLMenuImageScreen>(root, "BarPS", this, &GLMenuImageScreen::setBarPosScale) |
---|
67 | .describe("The Position and Scale of the Loading Bar in %(0-1.0). PosX, PosY, SizeX, SizeY"); |
---|
68 | |
---|
69 | LoadParam<GLMenuImageScreen>(root, "ElementCount", this, &GLMenuImageScreen::setMaximum) |
---|
70 | .describe("The Count of elements to load into the bar (this is only a maximum value)"); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * standard deconstructor |
---|
75 | @todo this deconstructor is not jet implemented - do it |
---|
76 | */ |
---|
77 | GLMenuImageScreen::~GLMenuImageScreen() |
---|
78 | { |
---|
79 | delete this->backMat; |
---|
80 | delete this->barMat; |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * sets the background image name |
---|
85 | * @param backImageName name of the backgroun-image |
---|
86 | */ |
---|
87 | void GLMenuImageScreen::setBackgroundImage (const char* backImageName) |
---|
88 | { |
---|
89 | this->backMat->setDiffuseMap(backImageName); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * sets position of the ImageScreen |
---|
94 | * @param offsetX offset from the top left corner in percent(0-1) of the screensize |
---|
95 | * @param offsetY offset from the top left corner in percent(0-1) of the screensize |
---|
96 | */ |
---|
97 | void GLMenuImageScreen::setPosition(float offsetX, float offsetY) |
---|
98 | { |
---|
99 | this->offsetX = offsetX; |
---|
100 | this->offsetY = offsetY; |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | \brief sets size of the ImageScreen |
---|
105 | * @param scaleX the scaleing of the image into the x-direction (in percent (0-1)) |
---|
106 | * @param scaleY the scaleing of the image into the y-direction (in percent (0-1)) |
---|
107 | */ |
---|
108 | void GLMenuImageScreen::setScale(float scaleX, float scaleY) |
---|
109 | { |
---|
110 | this->scaleX = scaleX; |
---|
111 | this->scaleY = scaleY; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | \brief sets position and size of the ImageScreen |
---|
116 | * @param offsetX offset from the top left corner in percent(0-1) of the screensize |
---|
117 | * @param offsetY offset from the top left corner in percent(0-1) of the screensize |
---|
118 | * @param scaleX the scaleing of the image into the x-direction (in percent (0-1)) |
---|
119 | * @param scaleY the scaleing of the image into the y-direction (in percent (0-1)) |
---|
120 | */ |
---|
121 | void GLMenuImageScreen::setPosScale(float offsetX, float offsetY, float scaleX, float scaleY) |
---|
122 | { |
---|
123 | this->setPosition(offsetX, offsetY); |
---|
124 | this->setScale(scaleX, scaleY); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * @param barImage An image for the Bar |
---|
129 | */ |
---|
130 | void GLMenuImageScreen::setBarImage(const char* barImage) |
---|
131 | { |
---|
132 | this->barMat->setDiffuseMap(barImage); |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * sets the Position and the Size of the bar |
---|
137 | * @param barX The Position in the x-direction in percent of the screen (0-1) |
---|
138 | * @param barY The Position in the y-direction in percent of the screen (0-1) |
---|
139 | * @param barW The Size in the x-direction in percent of the screen (0-1) |
---|
140 | * @param barH The Size in the y-direction in percent of the screen (0-1) |
---|
141 | */ |
---|
142 | void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH) |
---|
143 | { |
---|
144 | this->barX = barX; |
---|
145 | this->barY = barY; |
---|
146 | this->barW = barW; |
---|
147 | this->barH = barH; |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | /** |
---|
152 | * set the maximum of countable steps |
---|
153 | * @param maxValue of steps |
---|
154 | */ |
---|
155 | void GLMenuImageScreen::setMaximum(int maxValue) |
---|
156 | { |
---|
157 | this->maxValue = maxValue; |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * set current value |
---|
162 | * @param currentValue value to set |
---|
163 | */ |
---|
164 | void GLMenuImageScreen::setValue(int currentValue) |
---|
165 | { |
---|
166 | this->currentValue = currentValue; |
---|
167 | this->draw(); |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | /** |
---|
172 | * get the current value |
---|
173 | */ |
---|
174 | int GLMenuImageScreen::getValue() |
---|
175 | { |
---|
176 | return this->currentValue; |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | /** |
---|
181 | * call this to trigger a progress event |
---|
182 | |
---|
183 | this has to redraw the progress bar and the whole image |
---|
184 | */ |
---|
185 | void GLMenuImageScreen::step () |
---|
186 | { |
---|
187 | if (this->currentValue < this->maxValue) |
---|
188 | { |
---|
189 | this->currentValue++; |
---|
190 | this->draw(); |
---|
191 | } |
---|
192 | else |
---|
193 | PRINTF(2)("ImageScreen-loadbar exceeds maximum value %d\n", this->maxValue); |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | /** |
---|
199 | * draws the ImageScreen to the screenbuffer |
---|
200 | */ |
---|
201 | void GLMenuImageScreen::draw () |
---|
202 | { |
---|
203 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
204 | |
---|
205 | PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", |
---|
206 | this->currentValue, this->maxValue); |
---|
207 | |
---|
208 | /* screen size */ |
---|
209 | int screenWidth = GraphicsEngine::getInstance()->getResolutionX(); |
---|
210 | int screenHeight = GraphicsEngine::getInstance()->getResolutionY(); |
---|
211 | |
---|
212 | int imageWidth = (int)(screenWidth * this->scaleX); |
---|
213 | int imageHeight = (int)(screenHeight * this->scaleY); |
---|
214 | |
---|
215 | int offsetX = (int)(this->offsetX * screenWidth); |
---|
216 | int offsetY = (int)(this->offsetY * screenHeight); |
---|
217 | |
---|
218 | /* loadbar pos */ |
---|
219 | int barX = (int)(this->barX *screenWidth); |
---|
220 | int barY = (int)(this->barY *screenHeight); |
---|
221 | int barW = (int)(this->barW *screenWidth); |
---|
222 | int barH = (int)(this->barH *screenHeight); |
---|
223 | |
---|
224 | float val = (float)this->currentValue/(float)this->maxValue; |
---|
225 | |
---|
226 | if( val > barW) |
---|
227 | val = barW; |
---|
228 | |
---|
229 | GraphicsEngine::enter2DMode(); |
---|
230 | |
---|
231 | /* draw the BackGround */ |
---|
232 | backMat->select(); |
---|
233 | glBegin(GL_TRIANGLE_STRIP); |
---|
234 | glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight); |
---|
235 | glTexCoord2i(1, 1); glVertex2i(offsetX +imageWidth, offsetY + imageHeight); |
---|
236 | glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY); |
---|
237 | glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY); |
---|
238 | glEnd(); |
---|
239 | |
---|
240 | glDisable(GL_TEXTURE_2D); |
---|
241 | /* draw white border */ |
---|
242 | glBegin(GL_LINE_LOOP); |
---|
243 | glColor3f(1.0, 1.0, 1.0); |
---|
244 | glVertex2i(barX - 2, barY - 2); |
---|
245 | glVertex2i(barX + barW + 2, barY - 2); |
---|
246 | glVertex2i(barX + barW + 2, barY + barH + 2); |
---|
247 | glVertex2i(barX - 2, barY + barH + 2); |
---|
248 | glColor3f(1.0, 1.0, 1.0); |
---|
249 | glEnd(); |
---|
250 | |
---|
251 | /* draw the progress bar */ |
---|
252 | barMat->select(); |
---|
253 | glBegin(GL_TRIANGLE_STRIP); |
---|
254 | glTexCoord2f(0, 1); glVertex2i(barX, barY + barH); |
---|
255 | glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH); |
---|
256 | glTexCoord2f(0, 0); glVertex2i(barX, barY); |
---|
257 | glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY); |
---|
258 | glEnd(); |
---|
259 | |
---|
260 | /* |
---|
261 | glBegin(GL_QUADS); |
---|
262 | glColor3f(0.0, 0.0, 0.0); |
---|
263 | glVertex2i(barX, barY); |
---|
264 | glVertex2i(barX + barWidth, barY); |
---|
265 | glVertex2i(barX + barWidth, barY + barHeight); |
---|
266 | glVertex2i(barX, barY + barHeight); |
---|
267 | glColor3f(1.0, 1.0, 1.0); |
---|
268 | glEnd(); |
---|
269 | |
---|
270 | /* draw black border |
---|
271 | glBegin(GL_QUADS); |
---|
272 | glColor3f(0.0, 0.0, 0.0); |
---|
273 | glVertex2i(barX-1, barY-1); |
---|
274 | glVertex2i(barX + barWidth +1, barY-1); |
---|
275 | glVertex2i(barX + barWidth+1, barY + barHeight+1); |
---|
276 | glVertex2i(barX - 1, barY + barHeight +1); |
---|
277 | glColor3f(1.0, 1.0, 1.0); |
---|
278 | glEnd(); |
---|
279 | |
---|
280 | */ |
---|
281 | |
---|
282 | GraphicsEngine::leave2DMode(); |
---|
283 | |
---|
284 | SDL_GL_SwapBuffers(); |
---|
285 | } |
---|
286 | |
---|
287 | |
---|