| [3357] | 1 |  | 
|---|
 | 2 |  | 
|---|
| [4597] | 3 | /* | 
|---|
| [3357] | 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 | 
|---|
| [4597] | 15 |    co-programmer: | 
|---|
| [3357] | 16 | */ | 
|---|
 | 17 |  | 
|---|
| [5300] | 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD | 
|---|
| [3357] | 19 |  | 
|---|
 | 20 | #include "glmenu_imagescreen.h" | 
|---|
| [3428] | 21 |  | 
|---|
| [4099] | 22 | #include "graphics_engine.h" | 
|---|
| [3484] | 23 | #include "material.h" | 
|---|
| [4261] | 24 | #include "factory.h" | 
|---|
| [5155] | 25 | #include "load_param.h" | 
|---|
| [3357] | 26 |  | 
|---|
| [4101] | 27 | CREATE_FACTORY(GLMenuImageScreen); | 
|---|
 | 28 |  | 
|---|
| [3357] | 29 | using namespace std; | 
|---|
 | 30 | /** | 
|---|
| [4836] | 31 |  * @param root The Element to load the GLMenu from | 
|---|
 | 32 |  */ | 
|---|
| [4261] | 33 | GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root) | 
|---|
| [4101] | 34 | { | 
|---|
| [4597] | 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 |  | 
|---|
| [5090] | 47 |   if (root != NULL) | 
|---|
| [4597] | 48 |     this->loadParams(root); | 
|---|
| [4104] | 49 | } | 
|---|
 | 50 |  | 
|---|
 | 51 | /** | 
|---|
| [4836] | 52 |  *  Loads a GLMenu from an inputElement | 
|---|
 | 53 |  * @param root The Element to load the GLMenu from | 
|---|
| [4104] | 54 | */ | 
|---|
| [4261] | 55 | void GLMenuImageScreen::loadParams(const TiXmlElement* root) | 
|---|
| [4104] | 56 | { | 
|---|
| [4261] | 57 |   LoadParam<GLMenuImageScreen>(root, "BackgroundImage", this, &GLMenuImageScreen::setBackgroundImage) | 
|---|
 | 58 |     .describe("sets the image to load onto the loadscreen"); | 
|---|
| [4101] | 59 |  | 
|---|
| [4261] | 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"); | 
|---|
| [4104] | 62 |  | 
|---|
| [4261] | 63 |   LoadParam<GLMenuImageScreen>(root, "BarImage", this, &GLMenuImageScreen::setBarImage) | 
|---|
 | 64 |     .describe("sets the image of the LoadingBar"); | 
|---|
| [4597] | 65 |  | 
|---|
| [4261] | 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"); | 
|---|
| [4104] | 68 |  | 
|---|
| [4261] | 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)"); | 
|---|
| [4101] | 71 | } | 
|---|
 | 72 |  | 
|---|
| [3357] | 73 | /** | 
|---|
| [4836] | 74 |  *  standard deconstructor | 
|---|
 | 75 |    @todo this deconstructor is not jet implemented - do it | 
|---|
| [3543] | 76 | */ | 
|---|
| [4597] | 77 | GLMenuImageScreen::~GLMenuImageScreen() | 
|---|
| [3543] | 78 | { | 
|---|
| [4099] | 79 |   delete this->backMat; | 
|---|
| [4136] | 80 |   delete this->barMat; | 
|---|
| [3394] | 81 | } | 
|---|
| [3357] | 82 |  | 
|---|
 | 83 | /** | 
|---|
| [4836] | 84 |   *  sets the background image name | 
|---|
 | 85 |   * @param backImageName name of the backgroun-image | 
|---|
| [3357] | 86 |  */ | 
|---|
| [4099] | 87 | void GLMenuImageScreen::setBackgroundImage (const char* backImageName) | 
|---|
 | 88 | { | 
|---|
 | 89 |   this->backMat->setDiffuseMap(backImageName); | 
|---|
 | 90 | } | 
|---|
| [3357] | 91 |  | 
|---|
 | 92 | /** | 
|---|
| [4836] | 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 | 
|---|
| [3357] | 96 | */ | 
|---|
 | 97 | void GLMenuImageScreen::setPosition(float offsetX, float offsetY) | 
|---|
| [4099] | 98 | { | 
|---|
 | 99 |   this->offsetX = offsetX; | 
|---|
 | 100 |   this->offsetY = offsetY; | 
|---|
 | 101 | } | 
|---|
| [3357] | 102 |  | 
|---|
| [4453] | 103 | /** | 
|---|
| [3357] | 104 |   \brief sets size of the ImageScreen | 
|---|
| [4836] | 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)) | 
|---|
| [3357] | 107 | */ | 
|---|
| [4099] | 108 | void GLMenuImageScreen::setScale(float scaleX, float scaleY) | 
|---|
 | 109 | { | 
|---|
 | 110 |   this->scaleX = scaleX; | 
|---|
 | 111 |   this->scaleY = scaleY; | 
|---|
 | 112 | } | 
|---|
| [3363] | 113 |  | 
|---|
| [4453] | 114 | /** | 
|---|
| [4261] | 115 |   \brief sets position and size of the ImageScreen | 
|---|
| [4836] | 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)) | 
|---|
| [4261] | 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 |  | 
|---|
| [4099] | 127 | /** | 
|---|
| [4836] | 128 |  * @param barImage An image for the Bar | 
|---|
| [4099] | 129 | */ | 
|---|
 | 130 | void GLMenuImageScreen::setBarImage(const char* barImage) | 
|---|
 | 131 | { | 
|---|
 | 132 |   this->barMat->setDiffuseMap(barImage); | 
|---|
 | 133 | } | 
|---|
| [3363] | 134 |  | 
|---|
 | 135 | /** | 
|---|
| [4836] | 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) | 
|---|
| [4099] | 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 | /** | 
|---|
| [4836] | 152 |  *  set the maximum of countable steps | 
|---|
 | 153 |  * @param maxValue of steps | 
|---|
| [3363] | 154 | */ | 
|---|
| [3368] | 155 | void GLMenuImageScreen::setMaximum(int maxValue) | 
|---|
| [3363] | 156 | { | 
|---|
| [3368] | 157 |   this->maxValue = maxValue; | 
|---|
| [3363] | 158 | } | 
|---|
 | 159 |  | 
|---|
 | 160 | /** | 
|---|
| [4836] | 161 |  *  set current value | 
|---|
 | 162 |  * @param currentValue value to set | 
|---|
| [3363] | 163 | */ | 
|---|
 | 164 | void GLMenuImageScreen::setValue(int currentValue) | 
|---|
 | 165 | { | 
|---|
 | 166 |   this->currentValue = currentValue; | 
|---|
 | 167 |   this->draw(); | 
|---|
 | 168 | } | 
|---|
 | 169 |  | 
|---|
 | 170 |  | 
|---|
 | 171 | /** | 
|---|
| [4836] | 172 |  *  get the current value | 
|---|
| [3363] | 173 |  */ | 
|---|
 | 174 | int GLMenuImageScreen::getValue() | 
|---|
 | 175 | { | 
|---|
 | 176 |   return this->currentValue; | 
|---|
 | 177 | } | 
|---|
 | 178 |  | 
|---|
 | 179 |  | 
|---|
| [4597] | 180 | /** | 
|---|
| [4836] | 181 |   *  call this to trigger a progress event | 
|---|
| [4597] | 182 |  | 
|---|
| [3363] | 183 |     this has to redraw the progress bar and the whole image | 
|---|
 | 184 |  */ | 
|---|
 | 185 | void GLMenuImageScreen::step () | 
|---|
 | 186 | { | 
|---|
| [4834] | 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); | 
|---|
| [3363] | 194 | } | 
|---|
| [4099] | 195 |  | 
|---|
 | 196 |  | 
|---|
 | 197 |  | 
|---|
 | 198 | /** | 
|---|
| [4836] | 199 |  *  draws the ImageScreen to the screenbuffer | 
|---|
| [4099] | 200 | */ | 
|---|
 | 201 | void GLMenuImageScreen::draw () | 
|---|
 | 202 | { | 
|---|
 | 203 |   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); | 
|---|
 | 204 |  | 
|---|
| [4597] | 205 |   PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", | 
|---|
 | 206 |             this->currentValue, this->maxValue); | 
|---|
| [4099] | 207 |  | 
|---|
 | 208 |   /* screen size */ | 
|---|
 | 209 |   int screenWidth = GraphicsEngine::getInstance()->getResolutionX(); | 
|---|
 | 210 |   int screenHeight = GraphicsEngine::getInstance()->getResolutionY(); | 
|---|
| [4597] | 211 |  | 
|---|
| [4099] | 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); | 
|---|
| [4597] | 223 |  | 
|---|
| [4104] | 224 |   float val = (float)this->currentValue/(float)this->maxValue; | 
|---|
| [4597] | 225 |  | 
|---|
| [4099] | 226 |   if( val > barW) | 
|---|
 | 227 |     val = barW; | 
|---|
 | 228 |  | 
|---|
 | 229 |   GraphicsEngine::enter2DMode(); | 
|---|
 | 230 |  | 
|---|
 | 231 |   /* draw the BackGround */ | 
|---|
 | 232 |   backMat->select(); | 
|---|
 | 233 |   glBegin(GL_TRIANGLE_STRIP); | 
|---|
| [4357] | 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); | 
|---|
| [4099] | 238 |   glEnd(); | 
|---|
| [4597] | 239 |  | 
|---|
| [4100] | 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(); | 
|---|
| [4597] | 250 |  | 
|---|
| [4099] | 251 |   /* draw the progress bar */ | 
|---|
 | 252 |   barMat->select(); | 
|---|
 | 253 |   glBegin(GL_TRIANGLE_STRIP); | 
|---|
| [4357] | 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); | 
|---|
| [4099] | 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(); | 
|---|
| [4597] | 269 |  | 
|---|
 | 270 |     /* draw black border | 
|---|
| [4099] | 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(); | 
|---|
| [4597] | 279 |  | 
|---|
| [4099] | 280 |   */ | 
|---|
 | 281 |  | 
|---|
 | 282 |   GraphicsEngine::leave2DMode(); | 
|---|
 | 283 |  | 
|---|
| [4597] | 284 |   SDL_GL_SwapBuffers(); | 
|---|
| [4099] | 285 | } | 
|---|