Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader2: imagescreen gets loaded by the new format

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