Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc @ 10009

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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