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