[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 | |
---|
[4099] | 21 | #include "graphics_engine.h" |
---|
[3484] | 22 | #include "material.h" |
---|
[4261] | 23 | #include "factory.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 | */ |
---|
[4261] | 40 | GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root) |
---|
[4101] | 41 | { |
---|
| 42 | this->init(); |
---|
[4261] | 43 | this->loadParams(root); |
---|
[4104] | 44 | } |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | \brief Loads a GLMenu from an inputElement |
---|
| 48 | \param root The Element to load the GLMenu from |
---|
| 49 | */ |
---|
[4261] | 50 | void GLMenuImageScreen::loadParams(const TiXmlElement* root) |
---|
[4104] | 51 | { |
---|
[4261] | 52 | LoadParam<GLMenuImageScreen>(root, "BackgroundImage", this, &GLMenuImageScreen::setBackgroundImage) |
---|
| 53 | .describe("sets the image to load onto the loadscreen"); |
---|
[4101] | 54 | |
---|
[4261] | 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"); |
---|
[4104] | 57 | |
---|
[4261] | 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"); |
---|
[4104] | 63 | |
---|
[4261] | 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)"); |
---|
[4101] | 66 | } |
---|
| 67 | |
---|
[3357] | 68 | /** |
---|
| 69 | \brief standard deconstructor |
---|
[3544] | 70 | \todo this deconstructor is not jet implemented - do it |
---|
[3543] | 71 | */ |
---|
| 72 | GLMenuImageScreen::~GLMenuImageScreen() |
---|
| 73 | { |
---|
[4099] | 74 | delete this->backMat; |
---|
[4136] | 75 | delete this->barMat; |
---|
[3394] | 76 | } |
---|
[3357] | 77 | |
---|
| 78 | /** |
---|
| 79 | \brief function to init the screen |
---|
| 80 | */ |
---|
| 81 | void GLMenuImageScreen::init () |
---|
[3358] | 82 | { |
---|
[4320] | 83 | this->setClassID(CL_GLMENU_IMAGE_SCREEN, "GLMenuImageScreen"); |
---|
[4104] | 84 | |
---|
[3361] | 85 | // Select Our VU Meter Background Texture |
---|
[3394] | 86 | this->backMat = new Material("load_screen"); |
---|
[4099] | 87 | this->barMat = new Material("bar"); |
---|
[3368] | 88 | this->maxValue = 10; |
---|
| 89 | this->currentValue = 0; |
---|
[4099] | 90 | this->setPosition(0,0); |
---|
| 91 | this->setScale(1,1); |
---|
[4100] | 92 | this->setBarPosScale( .6, .75, .3, .1); |
---|
[3361] | 93 | // End of Background image code. |
---|
[3358] | 94 | } |
---|
| 95 | |
---|
[3357] | 96 | /** |
---|
| 97 | \brief sets the background image name |
---|
[4453] | 98 | \param backImageName name of the backgroun-image |
---|
[3357] | 99 | */ |
---|
[4099] | 100 | void GLMenuImageScreen::setBackgroundImage (const char* backImageName) |
---|
| 101 | { |
---|
| 102 | this->backMat->setDiffuseMap(backImageName); |
---|
| 103 | } |
---|
[3357] | 104 | |
---|
| 105 | /** |
---|
| 106 | \brief sets position of the ImageScreen |
---|
[4453] | 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 |
---|
[3357] | 109 | */ |
---|
| 110 | void GLMenuImageScreen::setPosition(float offsetX, float offsetY) |
---|
[4099] | 111 | { |
---|
| 112 | this->offsetX = offsetX; |
---|
| 113 | this->offsetY = offsetY; |
---|
| 114 | } |
---|
[3357] | 115 | |
---|
[4453] | 116 | /** |
---|
[3357] | 117 | \brief sets size of the ImageScreen |
---|
[4099] | 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)) |
---|
[3357] | 120 | */ |
---|
[4099] | 121 | void GLMenuImageScreen::setScale(float scaleX, float scaleY) |
---|
| 122 | { |
---|
| 123 | this->scaleX = scaleX; |
---|
| 124 | this->scaleY = scaleY; |
---|
| 125 | } |
---|
[3363] | 126 | |
---|
[4453] | 127 | /** |
---|
[4261] | 128 | \brief sets position and size of the ImageScreen |
---|
[4453] | 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 |
---|
[4261] | 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 | |
---|
[4099] | 140 | /** |
---|
| 141 | \param barImage An image for the Bar |
---|
| 142 | */ |
---|
| 143 | void GLMenuImageScreen::setBarImage(const char* barImage) |
---|
| 144 | { |
---|
| 145 | this->barMat->setDiffuseMap(barImage); |
---|
| 146 | } |
---|
[3363] | 147 | |
---|
| 148 | /** |
---|
[4099] | 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 | /** |
---|
[3363] | 165 | \brief set the maximum of countable steps |
---|
[4453] | 166 | \param maxValue of steps |
---|
[3363] | 167 | */ |
---|
[3368] | 168 | void GLMenuImageScreen::setMaximum(int maxValue) |
---|
[3363] | 169 | { |
---|
[3368] | 170 | this->maxValue = maxValue; |
---|
[3363] | 171 | } |
---|
| 172 | |
---|
| 173 | /** |
---|
| 174 | \brief set current value |
---|
[4453] | 175 | \param currentValue value to set |
---|
[3363] | 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++; |
---|
[3368] | 201 | this->draw(); |
---|
[3363] | 202 | } |
---|
[4099] | 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", |
---|
[4104] | 214 | this->currentValue, this->maxValue); |
---|
[4099] | 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 | |
---|
[4104] | 232 | float val = (float)this->currentValue/(float)this->maxValue; |
---|
| 233 | |
---|
[4099] | 234 | if( val > barW) |
---|
| 235 | val = barW; |
---|
| 236 | |
---|
| 237 | GraphicsEngine::enter2DMode(); |
---|
| 238 | |
---|
| 239 | /* draw the BackGround */ |
---|
| 240 | backMat->select(); |
---|
| 241 | glBegin(GL_TRIANGLE_STRIP); |
---|
[4357] | 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); |
---|
[4099] | 246 | glEnd(); |
---|
| 247 | |
---|
[4100] | 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(); |
---|
[4099] | 258 | |
---|
| 259 | /* draw the progress bar */ |
---|
| 260 | barMat->select(); |
---|
| 261 | glBegin(GL_TRIANGLE_STRIP); |
---|
[4357] | 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); |
---|
[4099] | 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 | |
---|