/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: */ #include "glmenu_imagescreen.h" #include "stdincl.h" #include "graphics_engine.h" #include "material.h" CREATE_FACTORY(GLMenuImageScreen); using namespace std; /** \brief standard constructor */ GLMenuImageScreen::GLMenuImageScreen () { this->init(); } /** \param root The Element to load the GLMenu from */ GLMenuImageScreen::GLMenuImageScreen (TiXmlElement* root) { this->init(); this->load(root); } /** \brief Loads a GLMenu from an inputElement \param root The Element to load the GLMenu from Tags are: \li BackgroundImage STRING: the background Image \li BarImage: STRING: the Image on the Bar \li BackgroundPS: FLOAT FLOAT FLOAT FLOAT: posX posY scaleX scaleY \li BarPS: FLOAT FLOAT FLOAT FLOAT: posX posY scaleX scaleY \li ElementCount: INT: how many elements will be loaded */ void GLMenuImageScreen::load(TiXmlElement* root) { const char* string; // Model Loading string = grabParameter( root, "BackgroundImage"); if( string != NULL) this->setBackgroundImage(string); string = grabParameter(root, "BackgroundPS"); if (string != NULL) { float f1, f2, f3, f4; sscanf (string, "%f %f %f %f", &f1, &f2, &f3, &f4); this->setPosition(f1,f2); this->setScale(f3,f4); } string = grabParameter( root, "BarImage"); if (string != NULL) this->setBarImage(string); string = grabParameter(root, "BarPS"); if (string != NULL) { float f1, f2, f3, f4; sscanf (string, "%f %f %f %f", &f1, &f2, &f3, &f4); this->setBarPosScale(f1,f2,f3,f4); } string = grabParameter( root, "ElementCount"); if (string != NULL) this->setMaximum(atoi(string)); } /** \brief standard deconstructor \todo this deconstructor is not jet implemented - do it */ GLMenuImageScreen::~GLMenuImageScreen() { delete this->backMat; delete this->barMat; } /** \brief function to init the screen */ void GLMenuImageScreen::init () { this->setClassName ("GLMenuImageScreen"); // Select Our VU Meter Background Texture this->backMat = new Material("load_screen"); this->barMat = new Material("bar"); this->maxValue = 10; this->currentValue = 0; this->setPosition(0,0); this->setScale(1,1); this->setBarPosScale( .6, .75, .3, .1); // End of Background image code. } /** \brief sets the background image name \param file name of the backgroun-image */ void GLMenuImageScreen::setBackgroundImage (const char* backImageName) { this->backMat->setDiffuseMap(backImageName); } /** \brief sets position of the ImageScreen \param x offset from the top left corner in percent(0-1) of the screensize \param y offset from the top left corner in percent(0-1) of the screensize */ void GLMenuImageScreen::setPosition(float offsetX, float offsetY) { this->offsetX = offsetX; this->offsetY = offsetY; } /* \brief sets size of the ImageScreen \param scaleX the scaleing of the image into the x-direction (in percent (0-1)) \param scaleY the scaleing of the image into the y-direction (in percent (0-1)) */ void GLMenuImageScreen::setScale(float scaleX, float scaleY) { this->scaleX = scaleX; this->scaleY = scaleY; } /** \param barImage An image for the Bar */ void GLMenuImageScreen::setBarImage(const char* barImage) { this->barMat->setDiffuseMap(barImage); } /** \brief sets the Position and the Size of the bar \param barX The Position in the x-direction in percent of the screen (0-1) \param barY The Position in the y-direction in percent of the screen (0-1) \param barW The Size in the x-direction in percent of the screen (0-1) \param barH The Size in the y-direction in percent of the screen (0-1) */ void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH) { this->barX = barX; this->barY = barY; this->barW = barW; this->barH = barH; } /** \brief set the maximum of countable steps \param maximum of steps */ void GLMenuImageScreen::setMaximum(int maxValue) { this->maxValue = maxValue; } /** \brief gets the maximum of countable steps */ int GLMenuImageScreen::getMaximum() { return this->maxValue; } /** \brief set current value \param current value */ void GLMenuImageScreen::setValue(int currentValue) { this->currentValue = currentValue; this->draw(); } /** \brief get the current value */ int GLMenuImageScreen::getValue() { return this->currentValue; } /** \brief call this to trigger a progress event this has to redraw the progress bar and the whole image */ void GLMenuImageScreen::step () { this->currentValue++; this->draw(); } /** \brief draws the ImageScreen to the screenbuffer */ void GLMenuImageScreen::draw () { glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", this->currentValue, this->maxValue); /* screen size */ int screenWidth = GraphicsEngine::getInstance()->getResolutionX(); int screenHeight = GraphicsEngine::getInstance()->getResolutionY(); int imageWidth = (int)(screenWidth * this->scaleX); int imageHeight = (int)(screenHeight * this->scaleY); int offsetX = (int)(this->offsetX * screenWidth); int offsetY = (int)(this->offsetY * screenHeight); /* loadbar pos */ int barX = (int)(this->barX *screenWidth); int barY = (int)(this->barY *screenHeight); int barW = (int)(this->barW *screenWidth); int barH = (int)(this->barH *screenHeight); float val = (float)this->currentValue/(float)this->maxValue; if( val > barW) val = barW; GraphicsEngine::enter2DMode(); /* draw the BackGround */ backMat->select(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY + imageHeight); glTexCoord2i(1, 0); glVertex2i(offsetX +imageWidth, offsetY + imageHeight); glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY); glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY); glEnd(); glDisable(GL_TEXTURE_2D); /* draw white border */ glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex2i(barX - 2, barY - 2); glVertex2i(barX + barW + 2, barY - 2); glVertex2i(barX + barW + 2, barY + barH + 2); glVertex2i(barX - 2, barY + barH + 2); glColor3f(1.0, 1.0, 1.0); glEnd(); /* draw the progress bar */ barMat->select(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2i(barX, barY + barH); glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH); glTexCoord2f(0, 1); glVertex2i(barX, barY); glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY); glEnd(); /* glBegin(GL_QUADS); glColor3f(0.0, 0.0, 0.0); glVertex2i(barX, barY); glVertex2i(barX + barWidth, barY); glVertex2i(barX + barWidth, barY + barHeight); glVertex2i(barX, barY + barHeight); glColor3f(1.0, 1.0, 1.0); glEnd(); /* draw black border glBegin(GL_QUADS); glColor3f(0.0, 0.0, 0.0); glVertex2i(barX-1, barY-1); glVertex2i(barX + barWidth +1, barY-1); glVertex2i(barX + barWidth+1, barY + barHeight+1); glVertex2i(barX - 1, barY + barHeight +1); glColor3f(1.0, 1.0, 1.0); glEnd(); */ GraphicsEngine::leave2DMode(); SDL_GL_SwapBuffers(); }