| [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" | 
|---|
| [3484] | 22 | #include "material.h" | 
|---|
| [3357] | 23 |  | 
|---|
 | 24 | using namespace std; | 
|---|
 | 25 |  | 
|---|
| [3367] | 26 | GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0; | 
|---|
| [3357] | 27 |  | 
|---|
| [3367] | 28 | GLMenuImageScreen* GLMenuImageScreen::getInstance() | 
|---|
 | 29 | { | 
|---|
| [3543] | 30 |   if(!singletonRef) | 
|---|
| [3367] | 31 |     singletonRef = new GLMenuImageScreen (); | 
|---|
 | 32 |   return singletonRef; | 
|---|
 | 33 | } | 
|---|
 | 34 |  | 
|---|
| [3357] | 35 | /** | 
|---|
 | 36 |    \brief standard constructor | 
|---|
 | 37 |  | 
|---|
 | 38 |    \todo this constructor is not jet implemented - do it | 
|---|
 | 39 | */ | 
|---|
 | 40 | GLMenuImageScreen::GLMenuImageScreen ()  | 
|---|
 | 41 | { | 
|---|
 | 42 |    this->setClassName ("GLMenuImageScreen"); | 
|---|
| [3678] | 43 |    this->init(); | 
|---|
| [3357] | 44 | } | 
|---|
 | 45 |  | 
|---|
 | 46 |  | 
|---|
 | 47 | /** | 
|---|
 | 48 |    \brief standard deconstructor | 
|---|
| [3544] | 49 |    \todo this deconstructor is not jet implemented - do it | 
|---|
| [3543] | 50 | */ | 
|---|
 | 51 | GLMenuImageScreen::~GLMenuImageScreen()  | 
|---|
 | 52 | { | 
|---|
| [3677] | 53 |   if (this->backMat) | 
|---|
 | 54 |     delete this->backMat; | 
|---|
| [3394] | 55 | } | 
|---|
| [3357] | 56 |  | 
|---|
 | 57 | /** | 
|---|
 | 58 |    \brief function to init the screen | 
|---|
 | 59 | */ | 
|---|
 | 60 | void GLMenuImageScreen::init () | 
|---|
| [3358] | 61 | { | 
|---|
| [3361] | 62 |   /* | 
|---|
| [3358] | 63 |   int w = 680; | 
|---|
 | 64 |   int h = 480; | 
|---|
| [3357] | 65 |  | 
|---|
| [3358] | 66 |   glViewport(0,0,w,h); | 
|---|
 | 67 |    | 
|---|
 | 68 |   glMatrixMode(GL_PROJECTION); | 
|---|
 | 69 |   glLoadIdentity();  | 
|---|
 | 70 |   gluPerspective(45.0f,(GLfloat)w/(GLfloat)h, .5f ,150.0f); | 
|---|
 | 71 |   glMatrixMode(GL_MODELVIEW);  | 
|---|
| [3357] | 72 |  | 
|---|
| [3358] | 73 |   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 
|---|
 | 74 |   glLoadIdentity(); | 
|---|
 | 75 |   gluLookAt(0, 0, 6,     0, 0, 0,     0, 1, 0); | 
|---|
 | 76 |  | 
|---|
 | 77 |   // Bind the texture stored at the zero index of g_Texture[] | 
|---|
 | 78 |   //glBindTexture(GL_TEXTURE_2D, g_Texture[0]); | 
|---|
| [3361] | 79 |   */ | 
|---|
 | 80 |  | 
|---|
 | 81 |    | 
|---|
 | 82 |   // Select Our VU Meter Background Texture | 
|---|
| [3394] | 83 |   this->backMat = new Material("load_screen"); | 
|---|
| [3658] | 84 |   this->backMat->setDiffuseMap("pictures/load_screen.jpg"); | 
|---|
| [3368] | 85 |   this->maxValue = 10; | 
|---|
 | 86 |   this->currentValue = 0; | 
|---|
 | 87 |  | 
|---|
| [3361] | 88 |   // End of Background image code. | 
|---|
| [3358] | 89 | } | 
|---|
 | 90 |  | 
|---|
 | 91 |  | 
|---|
| [3357] | 92 | /** | 
|---|
 | 93 |    \brief function to innit screen with all attributes set | 
|---|
 | 94 |    \param name of the background-image file | 
|---|
 | 95 |    \param height of the ImageScreen | 
|---|
 | 96 |    \param width of the Image Screen | 
|---|
 | 97 |    \param x offset from (0, 0) | 
|---|
 | 98 |    \param y offset from (0, 0) | 
|---|
 | 99 |  | 
|---|
 | 100 |    GLMenu uses its own coordinating system: upper left corner is (0, 0). x-axis is down=height,  | 
|---|
 | 101 |    right axis is right direction (=width) | 
|---|
 | 102 | */ | 
|---|
 | 103 | void GLMenuImageScreen::init (char* backImageName, float height, float width,  | 
|---|
 | 104 |                               float offsetX, float offsetY) | 
|---|
 | 105 | {} | 
|---|
 | 106 |  | 
|---|
 | 107 |  | 
|---|
 | 108 | /** | 
|---|
 | 109 |    \brief draws the ImageScreen to the screenbuffer | 
|---|
 | 110 | */ | 
|---|
 | 111 | void GLMenuImageScreen::draw () | 
|---|
| [3358] | 112 | { | 
|---|
| [3357] | 113 |  | 
|---|
| [3362] | 114 |   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); | 
|---|
 | 115 |  | 
|---|
| [3675] | 116 |  | 
|---|
 | 117 |   //PRINTF()(); | 
|---|
 | 118 |   printf("GLMenuImagEscreen::draw() - drawing step %i/%i\n",  | 
|---|
 | 119 |          this->currentValue, this->maxValue); | 
|---|
 | 120 |  | 
|---|
| [3367] | 121 |   /* screen size */ | 
|---|
| [3364] | 122 |   int screenWidth = 640; | 
|---|
 | 123 |   int screenHeight = 480; | 
|---|
| [3361] | 124 |    | 
|---|
| [3367] | 125 |   /* set image size */ | 
|---|
| [3364] | 126 |   int imageWidth = 640; | 
|---|
 | 127 |   int imageHeight = 480; | 
|---|
| [3362] | 128 |    | 
|---|
| [3367] | 129 |   /* start pos of image */ | 
|---|
| [3364] | 130 |   int offsetX = (screenWidth - imageWidth)/2; | 
|---|
 | 131 |   int offsetY = (screenHeight - imageHeight)/2; | 
|---|
| [3362] | 132 |    | 
|---|
| [3367] | 133 |   /* loadbar pos */ | 
|---|
| [3368] | 134 |   int barX = 390; | 
|---|
| [3367] | 135 |   int barY = 50; | 
|---|
 | 136 |   int barWidth = 230; | 
|---|
 | 137 |   int barHeight = 30; | 
|---|
| [3675] | 138 |    | 
|---|
 | 139 |   float val = ((float)this->currentValue/(float)this->maxValue) * barWidth; | 
|---|
 | 140 |   if( val > (float)barWidth) | 
|---|
 | 141 |     val = (float)barWidth; | 
|---|
| [3362] | 142 |  | 
|---|
 | 143 |   glMatrixMode(GL_PROJECTION); | 
|---|
 | 144 |   glPushMatrix(); | 
|---|
 | 145 |   glLoadIdentity(); | 
|---|
| [3364] | 146 |   /* set up an ortho screen */ | 
|---|
 | 147 |   glOrtho(0, screenWidth, 0, screenHeight, -1, 1);  | 
|---|
| [3362] | 148 |   glMatrixMode(GL_MODELVIEW); | 
|---|
 | 149 |   glLoadIdentity(); | 
|---|
 | 150 |   glPushMatrix(); | 
|---|
| [3367] | 151 |  | 
|---|
| [3362] | 152 |   glEnable(GL_BLEND); | 
|---|
| [3367] | 153 |   glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT); | 
|---|
 | 154 |   glDisable(GL_LIGHTING); | 
|---|
| [3362] | 155 |  | 
|---|
| [3675] | 156 |   /* draw the progress bar */ | 
|---|
| [3362] | 157 |   glBegin(GL_QUADS); | 
|---|
| [3367] | 158 |   glColor3f(0.96, 0.84, 0.34); | 
|---|
 | 159 |   glVertex2i(barX, barY); | 
|---|
| [3675] | 160 |   glVertex2i(barX + (int)val, barY); | 
|---|
 | 161 |   glVertex2i(barX + (int)val, barY + barHeight); | 
|---|
| [3368] | 162 |   glVertex2i(barX, barY + barHeight); | 
|---|
 | 163 |   glColor3f(1.0, 1.0, 1.0); | 
|---|
 | 164 |   glEnd(); | 
|---|
 | 165 |  | 
|---|
 | 166 |   glBegin(GL_QUADS); | 
|---|
 | 167 |   glColor3f(0.0, 0.0, 0.0); | 
|---|
 | 168 |   glVertex2i(barX, barY); | 
|---|
| [3367] | 169 |   glVertex2i(barX + barWidth, barY); | 
|---|
 | 170 |   glVertex2i(barX + barWidth, barY + barHeight); | 
|---|
 | 171 |   glVertex2i(barX, barY + barHeight); | 
|---|
 | 172 |   glColor3f(1.0, 1.0, 1.0); | 
|---|
| [3362] | 173 |   glEnd(); | 
|---|
 | 174 |  | 
|---|
| [3368] | 175 |   /* draw black border */ | 
|---|
 | 176 |   glBegin(GL_QUADS); | 
|---|
 | 177 |   glColor3f(0.0, 0.0, 0.0); | 
|---|
 | 178 |   glVertex2i(barX-1, barY-1); | 
|---|
 | 179 |   glVertex2i(barX + barWidth +1, barY-1); | 
|---|
 | 180 |   glVertex2i(barX + barWidth+1, barY + barHeight+1); | 
|---|
 | 181 |   glVertex2i(barX - 1, barY + barHeight +1); | 
|---|
 | 182 |   glColor3f(1.0, 1.0, 1.0); | 
|---|
 | 183 |   glEnd(); | 
|---|
 | 184 |  | 
|---|
 | 185 |   /* draw white border */ | 
|---|
 | 186 |   glBegin(GL_QUADS); | 
|---|
 | 187 |   glColor3f(1.0, 1.0, 1.0); | 
|---|
 | 188 |   glVertex2i(barX-2, barY-2); | 
|---|
 | 189 |   glVertex2i(barX + barWidth +2, barY-2); | 
|---|
 | 190 |   glVertex2i(barX + barWidth+2, barY + barHeight+2); | 
|---|
 | 191 |   glVertex2i(barX - 2, barY + barHeight +2); | 
|---|
 | 192 |   glColor3f(1.0, 1.0, 1.0); | 
|---|
 | 193 |   glEnd(); | 
|---|
 | 194 |  | 
|---|
| [3536] | 195 |   backMat->select(); | 
|---|
| [3364] | 196 |   glBegin(GL_QUADS); | 
|---|
| [3367] | 197 |   glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY); | 
|---|
 | 198 |   glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY); | 
|---|
 | 199 |   glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY + imageHeight); | 
|---|
 | 200 |   glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight); | 
|---|
| [3364] | 201 |   glEnd(); | 
|---|
| [3367] | 202 |   glDisable(GL_TEXTURE_2D); | 
|---|
| [3364] | 203 |  | 
|---|
| [3362] | 204 |   glDisable(GL_BLEND); | 
|---|
 | 205 |   glPopMatrix(); | 
|---|
 | 206 |   glMatrixMode(GL_PROJECTION); | 
|---|
 | 207 |   glPopMatrix(); | 
|---|
 | 208 |   glPopAttrib(); | 
|---|
 | 209 |  | 
|---|
| [3675] | 210 |   SDL_GL_SwapBuffers();               | 
|---|
| [3358] | 211 | } | 
|---|
| [3363] | 212 |   | 
|---|
| [3358] | 213 |  | 
|---|
| [3357] | 214 | /**  | 
|---|
 | 215 |     \brief sets the background image name | 
|---|
 | 216 |     \param file name of the backgroun-image | 
|---|
 | 217 |  */ | 
|---|
 | 218 | void GLMenuImageScreen::setBackImageName (char* backImageName) | 
|---|
 | 219 | {} | 
|---|
 | 220 |  | 
|---|
 | 221 |  | 
|---|
 | 222 | /** | 
|---|
 | 223 |    \brief sets position of the ImageScreen | 
|---|
 | 224 |    \param x offset from (0, 0) | 
|---|
 | 225 |    \param y offset from (0, 0) | 
|---|
 | 226 | */ | 
|---|
 | 227 | void GLMenuImageScreen::setPosition(float offsetX, float offsetY) | 
|---|
 | 228 | {} | 
|---|
 | 229 |  | 
|---|
 | 230 |  | 
|---|
 | 231 | /* | 
|---|
 | 232 |   \brief sets size of the ImageScreen | 
|---|
 | 233 |   \param height of the ImageScreen | 
|---|
 | 234 |   \param width of the Image Screen | 
|---|
 | 235 | */ | 
|---|
 | 236 | void GLMenuImageScreen::setSize(float height, float width) | 
|---|
 | 237 | {} | 
|---|
| [3363] | 238 |  | 
|---|
 | 239 |  | 
|---|
 | 240 | /** | 
|---|
 | 241 |    \brief set the maximum of countable steps | 
|---|
 | 242 |    \param maximum of steps | 
|---|
 | 243 | */ | 
|---|
| [3368] | 244 | void GLMenuImageScreen::setMaximum(int maxValue) | 
|---|
| [3363] | 245 | { | 
|---|
| [3368] | 246 |   this->maxValue = maxValue; | 
|---|
| [3363] | 247 | } | 
|---|
 | 248 |  | 
|---|
 | 249 |  | 
|---|
 | 250 | /** | 
|---|
 | 251 |    \brief gets the maximum of countable steps | 
|---|
 | 252 | */ | 
|---|
 | 253 | int GLMenuImageScreen::getMaximum() | 
|---|
 | 254 | { | 
|---|
| [3368] | 255 |   return this->maxValue; | 
|---|
| [3363] | 256 | } | 
|---|
 | 257 |  | 
|---|
 | 258 |  | 
|---|
 | 259 | /** | 
|---|
 | 260 |    \brief set current value | 
|---|
 | 261 |    \param current value | 
|---|
 | 262 | */ | 
|---|
 | 263 | void GLMenuImageScreen::setValue(int currentValue) | 
|---|
 | 264 | { | 
|---|
 | 265 |   this->currentValue = currentValue; | 
|---|
 | 266 |   this->draw(); | 
|---|
 | 267 | } | 
|---|
 | 268 |  | 
|---|
 | 269 |  | 
|---|
 | 270 | /** | 
|---|
 | 271 |    \brief get the current value | 
|---|
 | 272 |  */ | 
|---|
 | 273 | int GLMenuImageScreen::getValue() | 
|---|
 | 274 | { | 
|---|
 | 275 |   return this->currentValue; | 
|---|
 | 276 | } | 
|---|
 | 277 |  | 
|---|
 | 278 |  | 
|---|
 | 279 | /**  | 
|---|
 | 280 |     \brief call this to trigger a progress event | 
|---|
 | 281 |      | 
|---|
 | 282 |     this has to redraw the progress bar and the whole image | 
|---|
 | 283 |  */ | 
|---|
 | 284 | void GLMenuImageScreen::step () | 
|---|
 | 285 | { | 
|---|
 | 286 |   this->currentValue++; | 
|---|
| [3368] | 287 |   this->draw(); | 
|---|
| [3363] | 288 | } | 
|---|