Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/hud/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc @ 10671

Last change on this file since 10671 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

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: Benjamin GRauer
16*/
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
19
20#include "glmenu_imagescreen.h"
21
22#include "graphics_engine.h"
23#include "material.h"
24#include "util/loading/factory.h"
25#include "util/loading/load_param.h"
26#include "debug.h"
27
28ObjectListDefinition(GLMenuImageScreen);
29CREATE_FACTORY(GLMenuImageScreen);
30
31/**
32 * @param root The Element to load the GLMenu from
33 */
34GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root)
35{
36  this->registerObject(this, GLMenuImageScreen::_objectList);
37  this->setName("GLMenuLoadScreen");
38  // Select Our VU Meter Background Texture
39  this->backMat = new Material("load_screen");
40  this->barMat = new Material("bar");
41  this->barMat->setDiffuse(1,1,1);
42  this->backMat->setDiffuse(1,1,1);
43  this->maxValue = 10;
44  this->currentValue = 0;
45  this->setPosition(0,0);
46  this->setScale(1,1);
47  this->setBarPosScale( .6, .75, .3, .1);
48  // End of Background image code.
49
50  if (root != NULL)
51    this->loadParams(root);
52}
53
54/**
55 *  Loads a GLMenu from an inputElement
56 * @param root The Element to load the GLMenu from
57*/
58void GLMenuImageScreen::loadParams(const TiXmlElement* root)
59{
60  LoadParam(root, "BackgroundImage", this, GLMenuImageScreen, setBackgroundImage)
61  .describe("sets the image to load onto the loadscreen");
62
63  LoadParam(root, "BackgroundPS", this, GLMenuImageScreen, setPosScale)
64  .describe("The Position and Scale of the Background Image in %(0-1.0). PosX, PosY, SizeX, SizeY");
65
66  LoadParam(root, "BarImage", this, GLMenuImageScreen, setBarImage)
67  .describe("sets the image of the LoadingBar");
68
69  LoadParam(root, "BarPS", this, GLMenuImageScreen, setBarPosScale)
70  .describe("The Position and Scale of the Loading Bar in %(0-1.0). PosX, PosY, SizeX, SizeY");
71
72  LoadParam(root, "ElementCount", this, GLMenuImageScreen, setMaximum)
73  .describe("The Count of elements to load into the bar (this is only a maximum value)");
74}
75
76/**
77 *  standard deconstructor
78   @todo this deconstructor is not jet implemented - do it
79*/
80GLMenuImageScreen::~GLMenuImageScreen()
81{
82  delete this->backMat;
83  delete this->barMat;
84}
85
86/**
87  * @brief sets the background image name
88  * @param backImageName name of the backgroun-image
89 */
90void GLMenuImageScreen::setBackgroundImage (const std::string& backImageName)
91{
92  this->backMat->setDiffuseMap(backImageName);
93}
94
95/**
96 * @brief sets position of the ImageScreen
97 * @param offsetX offset from the top left corner in percent(0-1) of the screensize
98 * @param offsetY offset from the top left corner in percent(0-1) of the screensize
99*/
100void GLMenuImageScreen::setPosition(float offsetX, float offsetY)
101{
102  this->offsetX = offsetX;
103  this->offsetY = offsetY;
104}
105
106/**
107 * @brief sets size of the ImageScreen
108 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1))
109 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1))
110*/
111void GLMenuImageScreen::setScale(float scaleX, float scaleY)
112{
113  this->scaleX = scaleX;
114  this->scaleY = scaleY;
115}
116
117/**
118 * @brief sets position and size of the ImageScreen
119 * @param offsetX offset from the top left corner in percent(0-1) of the screensize
120 * @param offsetY offset from the top left corner in percent(0-1) of the screensize
121 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1))
122 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1))
123*/
124void GLMenuImageScreen::setPosScale(float offsetX, float offsetY, float scaleX, float scaleY)
125{
126  this->setPosition(offsetX, offsetY);
127  this->setScale(scaleX, scaleY);
128}
129
130/**
131 * @param barImage An image for the Bar
132*/
133void GLMenuImageScreen::setBarImage(const std::string& barImage)
134{
135  this->barMat->setDiffuseMap(barImage);
136}
137
138/**
139 * @brief sets the Position and the Size of the bar
140 * @param barX The Position in the x-direction in percent of the screen (0-1)
141 * @param barY The Position in the y-direction in percent of the screen (0-1)
142 * @param barW The Size in the x-direction in percent of the screen (0-1)
143 * @param barH The Size in the y-direction in percent of the screen (0-1)
144*/
145void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH)
146{
147  this->barX = barX;
148  this->barY = barY;
149  this->barW = barW;
150  this->barH = barH;
151}
152
153
154/**
155 * @brief set the maximum of countable steps
156 * @param maxValue of steps
157*/
158void GLMenuImageScreen::setMaximum(int maxValue)
159{
160  this->maxValue = maxValue;
161}
162
163/**
164 * @brief set current value
165 * @param currentValue value to set
166*/
167void GLMenuImageScreen::setValue(int currentValue)
168{
169  this->currentValue = currentValue;
170  this->draw();
171}
172
173
174/**
175 * @brief get the current value
176 */
177int GLMenuImageScreen::getValue()
178{
179  return this->currentValue;
180}
181
182
183/**
184 * @brief call this to trigger a progress event
185 *
186 * this has to redraw the progress bar and the whole image
187 */
188void GLMenuImageScreen::step ()
189{
190  if (this->currentValue < this->maxValue)
191  {
192    this->currentValue++;
193    this->draw();
194  }
195  else
196    PRINTF(2)("ImageScreen-loadbar exceeds maximum value %d\n", this->maxValue);
197}
198
199
200
201/**
202 * @brief draws the ImageScreen to the screenbuffer
203*/
204void GLMenuImageScreen::draw ()
205{
206  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
207
208  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n",
209            this->currentValue, this->maxValue);
210
211  /* screen size */
212  int screenWidth = GraphicsEngine::getInstance()->getResolutionX();
213  int screenHeight = GraphicsEngine::getInstance()->getResolutionY();
214
215  int imageWidth = (int)(screenWidth * this->scaleX);
216  int imageHeight = (int)(screenHeight * this->scaleY);
217
218  int offsetX = (int)(this->offsetX * screenWidth);
219  int offsetY = (int)(this->offsetY * screenHeight);
220
221  /* loadbar pos */
222  int barX = (int)(this->barX *screenWidth);
223  int barY = (int)(this->barY *screenHeight);
224  int barW = (int)(this->barW *screenWidth);
225  int barH = (int)(this->barH *screenHeight);
226
227  float val = (float)this->currentValue/(float)this->maxValue;
228
229  if( val > barW)
230    val = barW;
231
232  GraphicsEngine::enter2DMode();
233
234  /* draw the BackGround */
235  backMat->select();
236  glBegin(GL_TRIANGLE_STRIP);
237  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight);
238  glTexCoord2i(1, 1); glVertex2i(offsetX +imageWidth, offsetY + imageHeight);
239  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY);
240  glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY);
241  glEnd();
242
243  /* draw white border */
244  glBegin(GL_LINE_LOOP);
245  glColor3f(1.0, 1.0, 1.0);
246  glVertex2i(barX - 2, barY - 2);
247  glVertex2i(barX + barW + 2, barY - 2);
248  glVertex2i(barX + barW + 2, barY + barH + 2);
249  glVertex2i(barX - 2, barY + barH + 2);
250  glColor3f(1.0, 1.0, 1.0);
251  glEnd();
252
253  /* draw the progress bar */
254  barMat->select();
255  glBegin(GL_TRIANGLE_STRIP);
256  glTexCoord2f(0,   1); glVertex2i(barX, barY + barH);
257  glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH);
258  glTexCoord2f(0,   0); glVertex2i(barX, barY);
259  glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY);
260  glEnd();
261
262  /*
263    glBegin(GL_QUADS);
264    glColor3f(0.0, 0.0, 0.0);
265    glVertex2i(barX, barY);
266    glVertex2i(barX + barWidth, barY);
267    glVertex2i(barX + barWidth, barY + barHeight);
268    glVertex2i(barX, barY + barHeight);
269    glColor3f(1.0, 1.0, 1.0);
270    glEnd();
271
272    glBegin(GL_QUADS);
273    glColor3f(0.0, 0.0, 0.0);
274    glVertex2i(barX-1, barY-1);
275    glVertex2i(barX + barWidth +1, barY-1);
276    glVertex2i(barX + barWidth+1, barY + barHeight+1);
277    glVertex2i(barX - 1, barY + barHeight +1);
278    glColor3f(1.0, 1.0, 1.0);
279    glEnd();
280
281  */
282
283  GraphicsEngine::leave2DMode();
284
285  SDL_GL_SwapBuffers();
286}
Note: See TracBrowser for help on using the repository browser.