Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc @ 9716

Last change on this file since 9716 was 9716, checked in by bensch, 18 years ago

more renamings

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