Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4818 was 4597, checked in by bensch, 20 years ago

orxonox/trunk: setClassID implemented in all files

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