Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/glmenu/glmenu_imagescreen.cc @ 4309

Last change on this file since 4309 was 4283, checked in by bensch, 20 years ago

orxonox/branches/physics: merged the trunk back to branches/physics
merged with command
svn merge -r 4223:HEAD ../../trunk/ .
conflicts additively included

File size: 8.2 KB
Line 
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"
20
21#include "graphics_engine.h"
22#include "material.h"
23#include "factory.h"
24
25CREATE_FACTORY(GLMenuImageScreen);
26
27
28using namespace std;
29/**
30   \brief standard constructor
31*/
32GLMenuImageScreen::GLMenuImageScreen () 
33{
34   this->init();
35}
36
37/**
38   \param root The Element to load the GLMenu from
39*/
40GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root)
41{
42  this->init();
43  this->loadParams(root);
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*/
57void GLMenuImageScreen::loadParams(const TiXmlElement* root)
58{
59  LoadParam<GLMenuImageScreen>(root, "BackgroundImage", this, &GLMenuImageScreen::setBackgroundImage)
60    .describe("sets the image to load onto the loadscreen");
61
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");
64
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");
70
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)");
73}
74
75/**
76   \brief standard deconstructor
77   \todo this deconstructor is not jet implemented - do it
78*/
79GLMenuImageScreen::~GLMenuImageScreen() 
80{
81  delete this->backMat;
82  delete this->barMat;
83}
84
85/**
86   \brief function to init the screen
87*/
88void GLMenuImageScreen::init ()
89{
90  this->setClassName ("GLMenuImageScreen");
91
92  // Select Our VU Meter Background Texture
93  this->backMat = new Material("load_screen");
94  this->barMat = new Material("bar");
95  this->maxValue = 10;
96  this->currentValue = 0;
97  this->setPosition(0,0);
98  this->setScale(1,1);
99  this->setBarPosScale( .6, .75, .3, .1);
100  // End of Background image code.
101}
102
103/**
104    \brief sets the background image name
105    \param file name of the backgroun-image
106 */
107void GLMenuImageScreen::setBackgroundImage (const char* backImageName)
108{
109  this->backMat->setDiffuseMap(backImageName);
110}
111
112
113/**
114   \brief sets position of the ImageScreen
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
117*/
118void GLMenuImageScreen::setPosition(float offsetX, float offsetY)
119{
120  this->offsetX = offsetX;
121  this->offsetY = offsetY;
122}
123
124
125/*
126  \brief sets size of the ImageScreen
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))
129*/
130void GLMenuImageScreen::setScale(float scaleX, float scaleY)
131{
132  this->scaleX = scaleX;
133  this->scaleY = scaleY;
134}
135
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
149/**
150   \param barImage An image for the Bar
151*/
152void GLMenuImageScreen::setBarImage(const char* barImage)
153{
154  this->barMat->setDiffuseMap(barImage);
155}
156
157/**
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/**
174   \brief set the maximum of countable steps
175   \param maximum of steps
176*/
177void GLMenuImageScreen::setMaximum(int maxValue)
178{
179  this->maxValue = maxValue;
180}
181
182
183/**
184   \brief gets the maximum of countable steps
185*/
186int GLMenuImageScreen::getMaximum()
187{
188  return this->maxValue;
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++;
220  this->draw();
221}
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", 
233            this->currentValue, this->maxValue);
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 
251  float val = (float)this->currentValue/(float)this->maxValue;
252                 
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 
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();
277 
278  /* draw the progress bar */
279  barMat->select();
280  glBegin(GL_TRIANGLE_STRIP);
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);
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.