Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc @ 9135

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

trunk: fixed most -Wall warnings… but there are still many missing :/

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
27CREATE_FACTORY(GLMenuImageScreen, CL_GLMENU_IMAGE_SCREEN);
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  LoadParam(root, "BackgroundImage", this, GLMenuImageScreen, setBackgroundImage)
60    .describe("sets the image to load onto the loadscreen");
61
62  LoadParam(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  LoadParam(root, "BarImage", this, GLMenuImageScreen, setBarImage)
66    .describe("sets the image of the LoadingBar");
67
68  LoadParam(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  LoadParam(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  * @brief sets the background image name
87  * @param backImageName name of the backgroun-image
88 */
89void GLMenuImageScreen::setBackgroundImage (const std::string& backImageName)
90{
91  this->backMat->setDiffuseMap(backImageName);
92}
93
94/**
95 * @brief 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  this->setPosition(offsetX, offsetY);
126  this->setScale(scaleX, scaleY);
127}
128
129/**
130 * @param barImage An image for the Bar
131*/
132void GLMenuImageScreen::setBarImage(const std::string& barImage)
133{
134  this->barMat->setDiffuseMap(barImage);
135}
136
137/**
138 * @brief sets the Position and the Size of the bar
139 * @param barX The Position in the x-direction in percent of the screen (0-1)
140 * @param barY The Position in the y-direction in percent of the screen (0-1)
141 * @param barW The Size in the x-direction in percent of the screen (0-1)
142 * @param barH The Size in the y-direction in percent of the screen (0-1)
143*/
144void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH)
145{
146  this->barX = barX;
147  this->barY = barY;
148  this->barW = barW;
149  this->barH = barH;
150}
151
152
153/**
154 * @brief set the maximum of countable steps
155 * @param maxValue of steps
156*/
157void GLMenuImageScreen::setMaximum(int maxValue)
158{
159  this->maxValue = maxValue;
160}
161
162/**
163 * @brief set current value
164 * @param currentValue value to set
165*/
166void GLMenuImageScreen::setValue(int currentValue)
167{
168  this->currentValue = currentValue;
169  this->draw();
170}
171
172
173/**
174 * @brief get the current value
175 */
176int GLMenuImageScreen::getValue()
177{
178  return this->currentValue;
179}
180
181
182/**
183 * @brief call this to trigger a progress event
184 *
185 * this has to redraw the progress bar and the whole image
186 */
187void GLMenuImageScreen::step ()
188{
189  if (this->currentValue < this->maxValue)
190  {
191    this->currentValue++;
192    this->draw();
193  }
194  else
195    PRINTF(2)("ImageScreen-loadbar exceeds maximum value %d\n", this->maxValue);
196}
197
198
199
200/**
201 * @brief draws the ImageScreen to the screenbuffer
202*/
203void GLMenuImageScreen::draw ()
204{
205  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
206
207  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n",
208            this->currentValue, this->maxValue);
209
210  /* screen size */
211  int screenWidth = GraphicsEngine::getInstance()->getResolutionX();
212  int screenHeight = GraphicsEngine::getInstance()->getResolutionY();
213
214  int imageWidth = (int)(screenWidth * this->scaleX);
215  int imageHeight = (int)(screenHeight * this->scaleY);
216
217  int offsetX = (int)(this->offsetX * screenWidth);
218  int offsetY = (int)(this->offsetY * screenHeight);
219
220  /* loadbar pos */
221  int barX = (int)(this->barX *screenWidth);
222  int barY = (int)(this->barY *screenHeight);
223  int barW = (int)(this->barW *screenWidth);
224  int barH = (int)(this->barH *screenHeight);
225
226  float val = (float)this->currentValue/(float)this->maxValue;
227
228  if( val > barW)
229    val = barW;
230
231  GraphicsEngine::enter2DMode();
232
233  /* draw the BackGround */
234  backMat->select();
235  glBegin(GL_TRIANGLE_STRIP);
236  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight);
237  glTexCoord2i(1, 1); glVertex2i(offsetX +imageWidth, offsetY + imageHeight);
238  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY);
239  glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY);
240  glEnd();
241
242  /* draw white border */
243  glBegin(GL_LINE_LOOP);
244  glColor3f(1.0, 1.0, 1.0);
245  glVertex2i(barX - 2, barY - 2);
246  glVertex2i(barX + barW + 2, barY - 2);
247  glVertex2i(barX + barW + 2, barY + barH + 2);
248  glVertex2i(barX - 2, barY + barH + 2);
249  glColor3f(1.0, 1.0, 1.0);
250  glEnd();
251
252  /* draw the progress bar */
253  barMat->select();
254  glBegin(GL_TRIANGLE_STRIP);
255  glTexCoord2f(0,   1); glVertex2i(barX, barY + barH);
256  glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH);
257  glTexCoord2f(0,   0); glVertex2i(barX, barY);
258  glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY);
259  glEnd();
260
261  /*
262    glBegin(GL_QUADS);
263    glColor3f(0.0, 0.0, 0.0);
264    glVertex2i(barX, barY);
265    glVertex2i(barX + barWidth, barY);
266    glVertex2i(barX + barWidth, barY + barHeight);
267    glVertex2i(barX, barY + barHeight);
268    glColor3f(1.0, 1.0, 1.0);
269    glEnd();
270
271    glBegin(GL_QUADS);
272    glColor3f(0.0, 0.0, 0.0);
273    glVertex2i(barX-1, barY-1);
274    glVertex2i(barX + barWidth +1, barY-1);
275    glVertex2i(barX + barWidth+1, barY + barHeight+1);
276    glVertex2i(barX - 1, barY + barHeight +1);
277    glColor3f(1.0, 1.0, 1.0);
278    glEnd();
279
280  */
281
282  GraphicsEngine::leave2DMode();
283
284  SDL_GL_SwapBuffers();
285}
Note: See TracBrowser for help on using the repository browser.