Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/glmenu/glmenu_imagescreen.cc @ 5054

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

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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