Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/glmenu/glmenu_imagescreen.cc @ 4227

Last change on this file since 4227 was 4139, checked in by patrick, 20 years ago

orxonox/branches/md2_loader: merged trunk into branche using: svn merge ../trunk/ md2_loader -r 4063:HEAD

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