Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9900 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
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
[7221]15   co-programmer: Benjamin GRauer
[3357]16*/
17
[5300]18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
[3357]19
20#include "glmenu_imagescreen.h"
[3428]21
[4099]22#include "graphics_engine.h"
[3484]23#include "material.h"
[7193]24#include "util/loading/factory.h"
25#include "util/loading/load_param.h"
[9869]26#include "debug.h"
[3357]27
[9869]28#include "class_id_DEPRECATED.h"
29ObjectListDefinitionID(GLMenuImageScreen, CL_GLMENU_IMAGE_SCREEN);
30CREATE_FACTORY(GLMenuImageScreen);
[4101]31
[3357]32/**
[4836]33 * @param root The Element to load the GLMenu from
34 */
[4261]35GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root)
[4101]36{
[9869]37  this->registerObject(this, GLMenuImageScreen::_objectList);
[4597]38  this->setName("GLMenuLoadScreen");
39  // Select Our VU Meter Background Texture
40  this->backMat = new Material("load_screen");
41  this->barMat = new Material("bar");
[5373]42  this->barMat->setDiffuse(1,1,1);
43  this->backMat->setDiffuse(1,1,1);
[4597]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
[5090]51  if (root != NULL)
[4597]52    this->loadParams(root);
[4104]53}
54
55/**
[4836]56 *  Loads a GLMenu from an inputElement
57 * @param root The Element to load the GLMenu from
[4104]58*/
[4261]59void GLMenuImageScreen::loadParams(const TiXmlElement* root)
[4104]60{
[5671]61  LoadParam(root, "BackgroundImage", this, GLMenuImageScreen, setBackgroundImage)
[9869]62  .describe("sets the image to load onto the loadscreen");
[4101]63
[5671]64  LoadParam(root, "BackgroundPS", this, GLMenuImageScreen, setPosScale)
[9869]65  .describe("The Position and Scale of the Background Image in %(0-1.0). PosX, PosY, SizeX, SizeY");
[4104]66
[5671]67  LoadParam(root, "BarImage", this, GLMenuImageScreen, setBarImage)
[9869]68  .describe("sets the image of the LoadingBar");
[4597]69
[5671]70  LoadParam(root, "BarPS", this, GLMenuImageScreen, setBarPosScale)
[9869]71  .describe("The Position and Scale of the Loading Bar in %(0-1.0). PosX, PosY, SizeX, SizeY");
[4104]72
[5671]73  LoadParam(root, "ElementCount", this, GLMenuImageScreen, setMaximum)
[9869]74  .describe("The Count of elements to load into the bar (this is only a maximum value)");
[4101]75}
76
[3357]77/**
[4836]78 *  standard deconstructor
79   @todo this deconstructor is not jet implemented - do it
[3543]80*/
[4597]81GLMenuImageScreen::~GLMenuImageScreen()
[3543]82{
[4099]83  delete this->backMat;
[4136]84  delete this->barMat;
[3394]85}
[3357]86
87/**
[7221]88  * @brief sets the background image name
[4836]89  * @param backImageName name of the backgroun-image
[3357]90 */
[7221]91void GLMenuImageScreen::setBackgroundImage (const std::string& backImageName)
[4099]92{
93  this->backMat->setDiffuseMap(backImageName);
94}
[3357]95
96/**
[7221]97 * @brief sets position of the ImageScreen
[4836]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
[3357]100*/
101void GLMenuImageScreen::setPosition(float offsetX, float offsetY)
[4099]102{
103  this->offsetX = offsetX;
104  this->offsetY = offsetY;
105}
[3357]106
[4453]107/**
[7221]108 * @brief sets size of the ImageScreen
[4836]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))
[3357]111*/
[4099]112void GLMenuImageScreen::setScale(float scaleX, float scaleY)
113{
114  this->scaleX = scaleX;
115  this->scaleY = scaleY;
116}
[3363]117
[4453]118/**
[7221]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))
[4261]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
[4099]131/**
[4836]132 * @param barImage An image for the Bar
[4099]133*/
[7221]134void GLMenuImageScreen::setBarImage(const std::string& barImage)
[4099]135{
136  this->barMat->setDiffuseMap(barImage);
137}
[3363]138
139/**
[7221]140 * @brief sets the Position and the Size of the bar
[4836]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)
[4099]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/**
[7221]156 * @brief set the maximum of countable steps
[4836]157 * @param maxValue of steps
[3363]158*/
[3368]159void GLMenuImageScreen::setMaximum(int maxValue)
[3363]160{
[3368]161  this->maxValue = maxValue;
[3363]162}
163
164/**
[7221]165 * @brief set current value
[4836]166 * @param currentValue value to set
[3363]167*/
168void GLMenuImageScreen::setValue(int currentValue)
169{
170  this->currentValue = currentValue;
171  this->draw();
172}
173
174
175/**
[7221]176 * @brief get the current value
[3363]177 */
178int GLMenuImageScreen::getValue()
179{
180  return this->currentValue;
181}
182
183
[4597]184/**
[7221]185 * @brief call this to trigger a progress event
186 *
187 * this has to redraw the progress bar and the whole image
[3363]188 */
189void GLMenuImageScreen::step ()
190{
[4834]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);
[3363]198}
[4099]199
200
201
202/**
[7221]203 * @brief draws the ImageScreen to the screenbuffer
[4099]204*/
205void GLMenuImageScreen::draw ()
206{
207  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
208
[4597]209  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n",
210            this->currentValue, this->maxValue);
[4099]211
212  /* screen size */
213  int screenWidth = GraphicsEngine::getInstance()->getResolutionX();
214  int screenHeight = GraphicsEngine::getInstance()->getResolutionY();
[4597]215
[4099]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);
[4597]227
[4104]228  float val = (float)this->currentValue/(float)this->maxValue;
[4597]229
[4099]230  if( val > barW)
231    val = barW;
232
233  GraphicsEngine::enter2DMode();
234
235  /* draw the BackGround */
236  backMat->select();
237  glBegin(GL_TRIANGLE_STRIP);
[4357]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);
[4099]242  glEnd();
[4597]243
[4100]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();
[4597]253
[4099]254  /* draw the progress bar */
255  barMat->select();
256  glBegin(GL_TRIANGLE_STRIP);
[4357]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);
[4099]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();
[4597]272
[4099]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();
[4597]281
[4099]282  */
283
284  GraphicsEngine::leave2DMode();
285
[4597]286  SDL_GL_SwapBuffers();
[4099]287}
Note: See TracBrowser for help on using the repository browser.