Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader/src/glmenu/glmenu_imagescreen.cc @ 4242

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

orxonox/branches/levelLoader: better compatibility with more functions

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