[3357] | 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" |
---|
[3428] | 20 | |
---|
[3543] | 21 | #include "stdincl.h" |
---|
[4099] | 22 | #include "graphics_engine.h" |
---|
[3484] | 23 | #include "material.h" |
---|
[3357] | 24 | |
---|
[4101] | 25 | CREATE_FACTORY(GLMenuImageScreen); |
---|
| 26 | |
---|
| 27 | |
---|
[3357] | 28 | using namespace std; |
---|
| 29 | /** |
---|
| 30 | \brief standard constructor |
---|
| 31 | */ |
---|
| 32 | GLMenuImageScreen::GLMenuImageScreen () |
---|
| 33 | { |
---|
[3678] | 34 | this->init(); |
---|
[3357] | 35 | } |
---|
| 36 | |
---|
[4104] | 37 | /** |
---|
| 38 | \param root The Element to load the GLMenu from |
---|
| 39 | */ |
---|
[4101] | 40 | GLMenuImageScreen::GLMenuImageScreen (TiXmlElement* root) |
---|
| 41 | { |
---|
| 42 | this->init(); |
---|
[4104] | 43 | this->load(root); |
---|
[4101] | 44 | |
---|
[4104] | 45 | } |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | \brief Loads a GLMenu from an inputElement |
---|
| 49 | \param root The Element to load the GLMenu from |
---|
| 50 | |
---|
| 51 | Tags are: |
---|
| 52 | \li BackgroundImage STRING: the background Image |
---|
| 53 | \li BarImage: STRING: the Image on the Bar |
---|
| 54 | \li BackgroundPS: FLOAT FLOAT FLOAT FLOAT: posX posY scaleX scaleY |
---|
| 55 | \li BarPS: FLOAT FLOAT FLOAT FLOAT: posX posY scaleX scaleY |
---|
| 56 | \li ElementCount: INT: how many elements will be loaded |
---|
| 57 | */ |
---|
| 58 | void GLMenuImageScreen::load(TiXmlElement* root) |
---|
| 59 | { |
---|
[4101] | 60 | const char* string; |
---|
| 61 | |
---|
| 62 | // Model Loading |
---|
| 63 | string = grabParameter( root, "BackgroundImage"); |
---|
| 64 | if( string != NULL) |
---|
| 65 | this->setBackgroundImage(string); |
---|
[4104] | 66 | |
---|
| 67 | string = grabParameter(root, "BackgroundPS"); |
---|
| 68 | if (string != NULL) |
---|
| 69 | { |
---|
| 70 | float f1, f2, f3, f4; |
---|
| 71 | sscanf (string, "%f %f %f %f", &f1, &f2, &f3, &f4); |
---|
| 72 | this->setPosition(f1,f2); |
---|
| 73 | this->setScale(f3,f4); |
---|
| 74 | } |
---|
| 75 | |
---|
[4101] | 76 | string = grabParameter( root, "BarImage"); |
---|
| 77 | if (string != NULL) |
---|
| 78 | this->setBarImage(string); |
---|
[4104] | 79 | string = grabParameter(root, "BarPS"); |
---|
| 80 | if (string != NULL) |
---|
| 81 | { |
---|
| 82 | float f1, f2, f3, f4; |
---|
| 83 | sscanf (string, "%f %f %f %f", &f1, &f2, &f3, &f4); |
---|
| 84 | this->setBarPosScale(f1,f2,f3,f4); |
---|
| 85 | } |
---|
[4101] | 86 | |
---|
[4104] | 87 | string = grabParameter( root, "ElementCount"); |
---|
| 88 | if (string != NULL) |
---|
| 89 | this->setMaximum(atoi(string)); |
---|
[4101] | 90 | } |
---|
| 91 | |
---|
[3357] | 92 | /** |
---|
| 93 | \brief standard deconstructor |
---|
[3544] | 94 | \todo this deconstructor is not jet implemented - do it |
---|
[3543] | 95 | */ |
---|
| 96 | GLMenuImageScreen::~GLMenuImageScreen() |
---|
| 97 | { |
---|
[4099] | 98 | delete this->backMat; |
---|
| 99 | delete barMat; |
---|
[3394] | 100 | } |
---|
[3357] | 101 | |
---|
| 102 | /** |
---|
| 103 | \brief function to init the screen |
---|
| 104 | */ |
---|
| 105 | void GLMenuImageScreen::init () |
---|
[3358] | 106 | { |
---|
[4104] | 107 | this->setClassName ("GLMenuImageScreen"); |
---|
| 108 | |
---|
[3361] | 109 | // Select Our VU Meter Background Texture |
---|
[3394] | 110 | this->backMat = new Material("load_screen"); |
---|
[4099] | 111 | this->barMat = new Material("bar"); |
---|
[3368] | 112 | this->maxValue = 10; |
---|
| 113 | this->currentValue = 0; |
---|
[4099] | 114 | this->setPosition(0,0); |
---|
| 115 | this->setScale(1,1); |
---|
[4100] | 116 | this->setBarPosScale( .6, .75, .3, .1); |
---|
[3361] | 117 | // End of Background image code. |
---|
[3358] | 118 | } |
---|
| 119 | |
---|
[3357] | 120 | /** |
---|
| 121 | \brief sets the background image name |
---|
| 122 | \param file name of the backgroun-image |
---|
| 123 | */ |
---|
[4099] | 124 | void GLMenuImageScreen::setBackgroundImage (const char* backImageName) |
---|
| 125 | { |
---|
| 126 | this->backMat->setDiffuseMap(backImageName); |
---|
| 127 | } |
---|
[3357] | 128 | |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | \brief sets position of the ImageScreen |
---|
[4099] | 132 | \param x offset from the top left corner in percent(0-1) of the screensize |
---|
| 133 | \param y offset from the top left corner in percent(0-1) of the screensize |
---|
[3357] | 134 | */ |
---|
| 135 | void GLMenuImageScreen::setPosition(float offsetX, float offsetY) |
---|
[4099] | 136 | { |
---|
| 137 | this->offsetX = offsetX; |
---|
| 138 | this->offsetY = offsetY; |
---|
| 139 | } |
---|
[3357] | 140 | |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | \brief sets size of the ImageScreen |
---|
[4099] | 144 | \param scaleX the scaleing of the image into the x-direction (in percent (0-1)) |
---|
| 145 | \param scaleY the scaleing of the image into the y-direction (in percent (0-1)) |
---|
[3357] | 146 | */ |
---|
[4099] | 147 | void GLMenuImageScreen::setScale(float scaleX, float scaleY) |
---|
| 148 | { |
---|
| 149 | this->scaleX = scaleX; |
---|
| 150 | this->scaleY = scaleY; |
---|
| 151 | } |
---|
[3363] | 152 | |
---|
[4099] | 153 | /** |
---|
| 154 | \param barImage An image for the Bar |
---|
| 155 | */ |
---|
| 156 | void GLMenuImageScreen::setBarImage(const char* barImage) |
---|
| 157 | { |
---|
| 158 | this->barMat->setDiffuseMap(barImage); |
---|
| 159 | } |
---|
[3363] | 160 | |
---|
| 161 | /** |
---|
[4099] | 162 | \brief sets the Position and the Size of the bar |
---|
| 163 | \param barX The Position in the x-direction in percent of the screen (0-1) |
---|
| 164 | \param barY The Position in the y-direction in percent of the screen (0-1) |
---|
| 165 | \param barW The Size in the x-direction in percent of the screen (0-1) |
---|
| 166 | \param barH The Size in the y-direction in percent of the screen (0-1) |
---|
| 167 | */ |
---|
| 168 | void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH) |
---|
| 169 | { |
---|
| 170 | this->barX = barX; |
---|
| 171 | this->barY = barY; |
---|
| 172 | this->barW = barW; |
---|
| 173 | this->barH = barH; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | /** |
---|
[3363] | 178 | \brief set the maximum of countable steps |
---|
| 179 | \param maximum of steps |
---|
| 180 | */ |
---|
[3368] | 181 | void GLMenuImageScreen::setMaximum(int maxValue) |
---|
[3363] | 182 | { |
---|
[3368] | 183 | this->maxValue = maxValue; |
---|
[3363] | 184 | } |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | /** |
---|
| 188 | \brief gets the maximum of countable steps |
---|
| 189 | */ |
---|
| 190 | int GLMenuImageScreen::getMaximum() |
---|
| 191 | { |
---|
[3368] | 192 | return this->maxValue; |
---|
[3363] | 193 | } |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | /** |
---|
| 197 | \brief set current value |
---|
| 198 | \param current value |
---|
| 199 | */ |
---|
| 200 | void GLMenuImageScreen::setValue(int currentValue) |
---|
| 201 | { |
---|
| 202 | this->currentValue = currentValue; |
---|
| 203 | this->draw(); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | /** |
---|
| 208 | \brief get the current value |
---|
| 209 | */ |
---|
| 210 | int GLMenuImageScreen::getValue() |
---|
| 211 | { |
---|
| 212 | return this->currentValue; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | /** |
---|
| 217 | \brief call this to trigger a progress event |
---|
| 218 | |
---|
| 219 | this has to redraw the progress bar and the whole image |
---|
| 220 | */ |
---|
| 221 | void GLMenuImageScreen::step () |
---|
| 222 | { |
---|
| 223 | this->currentValue++; |
---|
[3368] | 224 | this->draw(); |
---|
[3363] | 225 | } |
---|
[4099] | 226 | |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | /** |
---|
| 230 | \brief draws the ImageScreen to the screenbuffer |
---|
| 231 | */ |
---|
| 232 | void GLMenuImageScreen::draw () |
---|
| 233 | { |
---|
| 234 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 235 | |
---|
| 236 | PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", |
---|
[4104] | 237 | this->currentValue, this->maxValue); |
---|
[4099] | 238 | |
---|
| 239 | /* screen size */ |
---|
| 240 | int screenWidth = GraphicsEngine::getInstance()->getResolutionX(); |
---|
| 241 | int screenHeight = GraphicsEngine::getInstance()->getResolutionY(); |
---|
| 242 | |
---|
| 243 | int imageWidth = (int)(screenWidth * this->scaleX); |
---|
| 244 | int imageHeight = (int)(screenHeight * this->scaleY); |
---|
| 245 | |
---|
| 246 | int offsetX = (int)(this->offsetX * screenWidth); |
---|
| 247 | int offsetY = (int)(this->offsetY * screenHeight); |
---|
| 248 | |
---|
| 249 | /* loadbar pos */ |
---|
| 250 | int barX = (int)(this->barX *screenWidth); |
---|
| 251 | int barY = (int)(this->barY *screenHeight); |
---|
| 252 | int barW = (int)(this->barW *screenWidth); |
---|
| 253 | int barH = (int)(this->barH *screenHeight); |
---|
| 254 | |
---|
[4104] | 255 | float val = (float)this->currentValue/(float)this->maxValue; |
---|
| 256 | |
---|
[4099] | 257 | if( val > barW) |
---|
| 258 | val = barW; |
---|
| 259 | |
---|
| 260 | GraphicsEngine::enter2DMode(); |
---|
| 261 | |
---|
| 262 | /* draw the BackGround */ |
---|
| 263 | backMat->select(); |
---|
| 264 | glBegin(GL_TRIANGLE_STRIP); |
---|
| 265 | glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY + imageHeight); |
---|
| 266 | glTexCoord2i(1, 0); glVertex2i(offsetX +imageWidth, offsetY + imageHeight); |
---|
| 267 | glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY); |
---|
| 268 | glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY); |
---|
| 269 | glEnd(); |
---|
| 270 | |
---|
[4100] | 271 | glDisable(GL_TEXTURE_2D); |
---|
| 272 | /* draw white border */ |
---|
| 273 | glBegin(GL_LINE_LOOP); |
---|
| 274 | glColor3f(1.0, 1.0, 1.0); |
---|
| 275 | glVertex2i(barX - 2, barY - 2); |
---|
| 276 | glVertex2i(barX + barW + 2, barY - 2); |
---|
| 277 | glVertex2i(barX + barW + 2, barY + barH + 2); |
---|
| 278 | glVertex2i(barX - 2, barY + barH + 2); |
---|
| 279 | glColor3f(1.0, 1.0, 1.0); |
---|
| 280 | glEnd(); |
---|
[4099] | 281 | |
---|
| 282 | /* draw the progress bar */ |
---|
| 283 | barMat->select(); |
---|
| 284 | glBegin(GL_TRIANGLE_STRIP); |
---|
[4104] | 285 | glTexCoord2f(0, 0); glVertex2i(barX, barY + barH); |
---|
| 286 | glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH); |
---|
| 287 | glTexCoord2f(0, 1); glVertex2i(barX, barY); |
---|
| 288 | glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY); |
---|
[4099] | 289 | glEnd(); |
---|
| 290 | |
---|
| 291 | /* |
---|
| 292 | glBegin(GL_QUADS); |
---|
| 293 | glColor3f(0.0, 0.0, 0.0); |
---|
| 294 | glVertex2i(barX, barY); |
---|
| 295 | glVertex2i(barX + barWidth, barY); |
---|
| 296 | glVertex2i(barX + barWidth, barY + barHeight); |
---|
| 297 | glVertex2i(barX, barY + barHeight); |
---|
| 298 | glColor3f(1.0, 1.0, 1.0); |
---|
| 299 | glEnd(); |
---|
| 300 | |
---|
| 301 | /* draw black border |
---|
| 302 | glBegin(GL_QUADS); |
---|
| 303 | glColor3f(0.0, 0.0, 0.0); |
---|
| 304 | glVertex2i(barX-1, barY-1); |
---|
| 305 | glVertex2i(barX + barWidth +1, barY-1); |
---|
| 306 | glVertex2i(barX + barWidth+1, barY + barHeight+1); |
---|
| 307 | glVertex2i(barX - 1, barY + barHeight +1); |
---|
| 308 | glColor3f(1.0, 1.0, 1.0); |
---|
| 309 | glEnd(); |
---|
| 310 | |
---|
| 311 | */ |
---|
| 312 | |
---|
| 313 | GraphicsEngine::leave2DMode(); |
---|
| 314 | |
---|
| 315 | SDL_GL_SwapBuffers(); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | |
---|