Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4289 was 4261, checked in by bensch, 20 years ago

orxonox/trunk: merged the levelLoader-branche back into the trunk, because it seems to be stable.
merged with command:
svn merge -r 4230:HEAD levelLoader ../trunk
no conflicts of any interesst

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