Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: simple loading facility

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