Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

File size: 7.6 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   \brief 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   \brief 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    \brief 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   \brief 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   \brief 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   \brief 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   \brief 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   \brief get the current value
172 */
173int GLMenuImageScreen::getValue()
174{
175  return this->currentValue;
176}
177
178
179/**
180    \brief 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  this->currentValue++;
187  this->draw();
188}
189
190
191
192/**
193   \brief draws the ImageScreen to the screenbuffer
194*/
195void GLMenuImageScreen::draw ()
196{
197  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
198
199  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n",
200            this->currentValue, this->maxValue);
201
202  /* screen size */
203  int screenWidth = GraphicsEngine::getInstance()->getResolutionX();
204  int screenHeight = GraphicsEngine::getInstance()->getResolutionY();
205
206  int imageWidth = (int)(screenWidth * this->scaleX);
207  int imageHeight = (int)(screenHeight * this->scaleY);
208
209  int offsetX = (int)(this->offsetX * screenWidth);
210  int offsetY = (int)(this->offsetY * screenHeight);
211
212  /* loadbar pos */
213  int barX = (int)(this->barX *screenWidth);
214  int barY = (int)(this->barY *screenHeight);
215  int barW = (int)(this->barW *screenWidth);
216  int barH = (int)(this->barH *screenHeight);
217
218  float val = (float)this->currentValue/(float)this->maxValue;
219
220  if( val > barW)
221    val = barW;
222
223  GraphicsEngine::enter2DMode();
224
225  /* draw the BackGround */
226  backMat->select();
227  glBegin(GL_TRIANGLE_STRIP);
228  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight);
229  glTexCoord2i(1, 1); glVertex2i(offsetX +imageWidth, offsetY + imageHeight);
230  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY);
231  glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY);
232  glEnd();
233
234  glDisable(GL_TEXTURE_2D);
235  /* draw white border */
236  glBegin(GL_LINE_LOOP);
237  glColor3f(1.0, 1.0, 1.0);
238  glVertex2i(barX - 2, barY - 2);
239  glVertex2i(barX + barW + 2, barY - 2);
240  glVertex2i(barX + barW + 2, barY + barH + 2);
241  glVertex2i(barX - 2, barY + barH + 2);
242  glColor3f(1.0, 1.0, 1.0);
243  glEnd();
244
245  /* draw the progress bar */
246  barMat->select();
247  glBegin(GL_TRIANGLE_STRIP);
248  glTexCoord2f(0,   1); glVertex2i(barX, barY + barH);
249  glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH);
250  glTexCoord2f(0,   0); glVertex2i(barX, barY);
251  glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY);
252  glEnd();
253
254  /*
255    glBegin(GL_QUADS);
256    glColor3f(0.0, 0.0, 0.0);
257    glVertex2i(barX, barY);
258    glVertex2i(barX + barWidth, barY);
259    glVertex2i(barX + barWidth, barY + barHeight);
260    glVertex2i(barX, barY + barHeight);
261    glColor3f(1.0, 1.0, 1.0);
262    glEnd();
263
264    /* draw black border
265    glBegin(GL_QUADS);
266    glColor3f(0.0, 0.0, 0.0);
267    glVertex2i(barX-1, barY-1);
268    glVertex2i(barX + barWidth +1, barY-1);
269    glVertex2i(barX + barWidth+1, barY + barHeight+1);
270    glVertex2i(barX - 1, barY + barHeight +1);
271    glColor3f(1.0, 1.0, 1.0);
272    glEnd();
273
274  */
275
276  GraphicsEngine::leave2DMode();
277
278  SDL_GL_SwapBuffers();
279}
280
281
Note: See TracBrowser for help on using the repository browser.