home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / ErrorMenu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-06  |  4.2 KB  |  168 lines

  1. #include "ErrorMenu.h"
  2.  
  3. #include "TextureHandler.h"
  4. #include "Display.h"
  5. #include "Renderer.h"
  6. //#include "font.h"
  7. #include "Gui.h"
  8. #include "System.h"
  9. #include "ConsoleFrontEnd.h"
  10.  
  11. static void CB_EM_okButton(){
  12.     Gui::errorMenu->close();
  13. }
  14.  
  15. ErrorMenu::ErrorMenu():Menu("ErrorMenu"){
  16.     //backgroundTexture=TextureHandler::getTexture("gui/menu/main_menu_background.jpg");
  17.     errorString = "Unknown Error";
  18.  
  19.     TextButton* okButton = new TextButton(300, 210, 200, 25, "ok");
  20.     okButton->setCallbackFunction(&CB_EM_okButton);
  21.     addMenuItem(okButton);
  22. }
  23.  
  24. ErrorMenu::~ErrorMenu(){
  25. //    if(backgroundTexture!=NULL)
  26. //        TextureHandler::releaseTexture(backgroundTexture);
  27. }
  28.  
  29. bool ErrorMenu::open(){
  30.     Input::showMouseCursor();
  31.     Input::freeInput();
  32.  
  33.     if(Sound::info.var.enabled && Sound::info.var.playSamples)
  34.         Sound::playSample(SOUND_COMPUTER_CHANNEL, Menu::errorSound);
  35.  
  36.     opened=true;
  37.     mainLoop();    // waits until menu is closed again
  38.     return true;
  39. }
  40.  
  41. void ErrorMenu::mainLoop(){
  42.     SDL_Event event;
  43.  
  44.     while(opened){
  45.         while( SDL_PollEvent(& event) ){
  46.             switch(event.type)
  47.             {
  48.                 case SDL_QUIT:
  49.                     System::normalQuit();
  50.                     break;
  51.  
  52.                 case SDL_KEYDOWN:
  53.                     handleKeyboardEvent(&event.key);
  54.                     break;
  55.  
  56.                 case SDL_KEYUP:
  57.                     handleKeyboardEvent(&event.key);
  58.                     break;
  59.  
  60.                 case SDL_MOUSEMOTION:
  61.                     handleMouseMotionEvent(&event.motion);
  62.                     break;
  63.  
  64.                 case SDL_MOUSEBUTTONDOWN:
  65.                     handleMouseButtonEvent(&event.button);
  66.                     break;
  67.  
  68.                 case SDL_MOUSEBUTTONUP:
  69.                     handleMouseButtonEvent(&event.button);
  70.                     break;
  71.  
  72.                 default:
  73.                     break;
  74.             } // switch
  75.         } // while( SDL_ ...
  76. //        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  77.         draw();
  78.         if(allowConsole && consoleFrontEnd->isActive){
  79.             consoleFrontEnd->draw();
  80.         }
  81.         SDL_GL_SwapBuffers();    // THINKABOUTME: spΣter backgroundScene
  82.     } // while( ! done)
  83.  
  84. }
  85.  
  86. void ErrorMenu::handleKeyboardEvent(SDL_KeyboardEvent* event){
  87.     if(event->keysym.sym == SDLK_SPACE && event->type==SDL_KEYUP)
  88.         close();
  89. }
  90. /*
  91. void ErrorMenu::handleMouseButtonEvent(SDL_MouseButtonEvent* event){
  92.     if(event->type==SDL_MOUSEBUTTONUP){
  93.         close();
  94.     }
  95. }
  96. */
  97. /*
  98. void ErrorMenu::draw(){
  99.     Renderer::beginDrawing();
  100.     
  101.     drawBackground();
  102.     drawErrorString();
  103.  
  104.     Renderer::endDrawing();
  105.     Menu::draw();
  106.  
  107. }
  108. */
  109.  
  110. void ErrorMenu::drawBackground(){
  111.     glColor4fv(Gui::info.var.menu_backgroundColor);
  112.     glBegin(GL_QUADS);
  113.         glVertex2i(100, 200);
  114.         glVertex2i(700, 200);
  115.         glVertex2i(700, 430);
  116.         glVertex2i(100, 430);
  117.     glEnd();
  118.  
  119.     glColor4fv(Gui::info.var.menu_normalColor);
  120.     glBegin(GL_LINE_LOOP);
  121.         glVertex2i(100, 200);
  122.         glVertex2i(700, 200);
  123.         glVertex2i(700, 400);
  124.         glVertex2i(100, 400);
  125.     glEnd();
  126.  
  127.     glBegin(GL_LINE_LOOP);
  128.         glVertex2i(100, 200);
  129.         glVertex2i(700, 200);
  130.         glVertex2i(700, 430);
  131.         glVertex2i(100, 430);
  132.     glEnd();
  133.  
  134.     drawScaledAndAlignedString((int)( 400 ), (int)( 396 ), 0.6f, 0.6f, 
  135.         Gui::info.var.menu_bigFont, TEXT_ALIGN_CENTER, "An Error Occurred:");
  136.  
  137.     drawErrorString();
  138. }
  139. /*
  140. void CreditsMenu::printShadowedString(int x,int y,float scale, int alignment, char* str){
  141.     glColor4f(0.0f, 0.0f, 0.0f, 0.7f);
  142.     drawScaledAndAlignedString(x+2, y-2, scale, scale, Gui::info.var.menu_bigFont, alignment, str);
  143.     glColor4f(0.3f, 0.4f, 0.6f, 1.0f);
  144.     drawScaledAndAlignedString(x, y, scale, scale, Gui::info.var.menu_bigFont, alignment, str);
  145. }
  146. */
  147.  
  148. void ErrorMenu::setErrorString(char* newErrorString){
  149.     errorString = newErrorString;
  150. }
  151.  
  152. void ErrorMenu::drawErrorString(){
  153. //    drawScaledAndAlignedString((int)( 400 ), (int)( 300 ), 0.8f, 0.8f, 
  154. //        Gui::info.var.menu_smallFont, TEXT_ALIGN_CENTER, errorString);
  155.  
  156.     int n = 43;    // chars per line
  157.  
  158.     for(int i=0; i*n<(signed int)strlen(errorString); i++ ){
  159.  
  160.         char buff[256];
  161.         strncpy(buff, errorString + i*n, n);
  162.         buff[n] = '\0';
  163.         drawScaledAndAlignedString((int)( 120 ), (int)( 360 - i*20 ), 1.0f, 1.0f, 
  164.             Gui::info.var.menu_smallFont, TEXT_ALIGN_LEFT, buff);
  165.     }
  166.  
  167. }
  168.