Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/glmenu/glmenu_imagescreen.cc @ 5045

Last change on this file since 5045 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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