Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl_gui/glmenu/glmenu_imagescreen.cc @ 5652

Last change on this file since 5652 was 5652, checked in by bensch, 18 years ago

orxonox/trunk: new LoadParam procedure with all NON-cycling load-options, and it works perfectly (on first sight :))

now going to make the same for cycling LoadOptions

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