Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: glmis-refitted

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