Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: better positioning

File size: 6.1 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( .6, .75, .3, .1);
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  GraphicsEngine::enter2DMode();
204
205  /* draw the BackGround */
206  backMat->select();
207  glBegin(GL_TRIANGLE_STRIP);
208  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY + imageHeight);
209  glTexCoord2i(1, 0); glVertex2i(offsetX +imageWidth, offsetY + imageHeight);
210  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY);
211  glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY);
212  glEnd();
213 
214  glDisable(GL_TEXTURE_2D);
215  /* draw white border */
216  glBegin(GL_LINE_LOOP);
217  glColor3f(1.0, 1.0, 1.0);
218  glVertex2i(barX - 2, barY - 2);
219  glVertex2i(barX + barW + 2, barY - 2);
220  glVertex2i(barX + barW + 2, barY + barH + 2);
221  glVertex2i(barX - 2, barY + barH + 2);
222  glColor3f(1.0, 1.0, 1.0);
223  glEnd();
224 
225  /* draw the progress bar */
226  barMat->select();
227  glBegin(GL_TRIANGLE_STRIP);
228  glTexCoord2i(0, 0); glVertex2i(barX, barY + barH);
229  glTexCoord2i(1, 0); glVertex2i(barX + val, barY + barH);
230  glTexCoord2i(0, 1); glVertex2i(barX, barY);
231  glTexCoord2i(1, 1); glVertex2i(barX + val, barY);
232  glEnd();
233
234  /*
235    glBegin(GL_QUADS);
236    glColor3f(0.0, 0.0, 0.0);
237    glVertex2i(barX, barY);
238    glVertex2i(barX + barWidth, barY);
239    glVertex2i(barX + barWidth, barY + barHeight);
240    glVertex2i(barX, barY + barHeight);
241    glColor3f(1.0, 1.0, 1.0);
242    glEnd();
243   
244    /* draw black border
245    glBegin(GL_QUADS);
246    glColor3f(0.0, 0.0, 0.0);
247    glVertex2i(barX-1, barY-1);
248    glVertex2i(barX + barWidth +1, barY-1);
249    glVertex2i(barX + barWidth+1, barY + barHeight+1);
250    glVertex2i(barX - 1, barY + barHeight +1);
251    glColor3f(1.0, 1.0, 1.0);
252    glEnd();
253   
254  */
255
256  GraphicsEngine::leave2DMode();
257
258  SDL_GL_SwapBuffers();             
259}
260 
261
Note: See TracBrowser for help on using the repository browser.