home *** CD-ROM | disk | FTP | other *** search
- #include "ErrorMenu.h"
-
- #include "TextureHandler.h"
- #include "Display.h"
- #include "Renderer.h"
- //#include "font.h"
- #include "Gui.h"
- #include "System.h"
- #include "ConsoleFrontEnd.h"
-
- static void CB_EM_okButton(){
- Gui::errorMenu->close();
- }
-
- ErrorMenu::ErrorMenu():Menu("ErrorMenu"){
- //backgroundTexture=TextureHandler::getTexture("gui/menu/main_menu_background.jpg");
- errorString = "Unknown Error";
-
- TextButton* okButton = new TextButton(300, 210, 200, 25, "ok");
- okButton->setCallbackFunction(&CB_EM_okButton);
- addMenuItem(okButton);
- }
-
- ErrorMenu::~ErrorMenu(){
- // if(backgroundTexture!=NULL)
- // TextureHandler::releaseTexture(backgroundTexture);
- }
-
- bool ErrorMenu::open(){
- Input::showMouseCursor();
- Input::freeInput();
-
- if(Sound::info.var.enabled && Sound::info.var.playSamples)
- Sound::playSample(SOUND_COMPUTER_CHANNEL, Menu::errorSound);
-
- opened=true;
- mainLoop(); // waits until menu is closed again
- return true;
- }
-
- void ErrorMenu::mainLoop(){
- SDL_Event event;
-
- while(opened){
- while( SDL_PollEvent(& event) ){
- switch(event.type)
- {
- case SDL_QUIT:
- System::normalQuit();
- break;
-
- case SDL_KEYDOWN:
- handleKeyboardEvent(&event.key);
- break;
-
- case SDL_KEYUP:
- handleKeyboardEvent(&event.key);
- break;
-
- case SDL_MOUSEMOTION:
- handleMouseMotionEvent(&event.motion);
- break;
-
- case SDL_MOUSEBUTTONDOWN:
- handleMouseButtonEvent(&event.button);
- break;
-
- case SDL_MOUSEBUTTONUP:
- handleMouseButtonEvent(&event.button);
- break;
-
- default:
- break;
- } // switch
- } // while( SDL_ ...
- // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- draw();
- if(allowConsole && consoleFrontEnd->isActive){
- consoleFrontEnd->draw();
- }
- SDL_GL_SwapBuffers(); // THINKABOUTME: spΣter backgroundScene
- } // while( ! done)
-
- }
-
- void ErrorMenu::handleKeyboardEvent(SDL_KeyboardEvent* event){
- if(event->keysym.sym == SDLK_SPACE && event->type==SDL_KEYUP)
- close();
- }
- /*
- void ErrorMenu::handleMouseButtonEvent(SDL_MouseButtonEvent* event){
- if(event->type==SDL_MOUSEBUTTONUP){
- close();
- }
- }
- */
- /*
- void ErrorMenu::draw(){
- Renderer::beginDrawing();
-
- drawBackground();
- drawErrorString();
-
- Renderer::endDrawing();
- Menu::draw();
-
- }
- */
-
- void ErrorMenu::drawBackground(){
- glColor4fv(Gui::info.var.menu_backgroundColor);
- glBegin(GL_QUADS);
- glVertex2i(100, 200);
- glVertex2i(700, 200);
- glVertex2i(700, 430);
- glVertex2i(100, 430);
- glEnd();
-
- glColor4fv(Gui::info.var.menu_normalColor);
- glBegin(GL_LINE_LOOP);
- glVertex2i(100, 200);
- glVertex2i(700, 200);
- glVertex2i(700, 400);
- glVertex2i(100, 400);
- glEnd();
-
- glBegin(GL_LINE_LOOP);
- glVertex2i(100, 200);
- glVertex2i(700, 200);
- glVertex2i(700, 430);
- glVertex2i(100, 430);
- glEnd();
-
- drawScaledAndAlignedString((int)( 400 ), (int)( 396 ), 0.6f, 0.6f,
- Gui::info.var.menu_bigFont, TEXT_ALIGN_CENTER, "An Error Occurred:");
-
- drawErrorString();
- }
- /*
- void CreditsMenu::printShadowedString(int x,int y,float scale, int alignment, char* str){
- glColor4f(0.0f, 0.0f, 0.0f, 0.7f);
- drawScaledAndAlignedString(x+2, y-2, scale, scale, Gui::info.var.menu_bigFont, alignment, str);
- glColor4f(0.3f, 0.4f, 0.6f, 1.0f);
- drawScaledAndAlignedString(x, y, scale, scale, Gui::info.var.menu_bigFont, alignment, str);
- }
- */
-
- void ErrorMenu::setErrorString(char* newErrorString){
- errorString = newErrorString;
- }
-
- void ErrorMenu::drawErrorString(){
- // drawScaledAndAlignedString((int)( 400 ), (int)( 300 ), 0.8f, 0.8f,
- // Gui::info.var.menu_smallFont, TEXT_ALIGN_CENTER, errorString);
-
- int n = 43; // chars per line
-
- for(int i=0; i*n<(signed int)strlen(errorString); i++ ){
-
- char buff[256];
- strncpy(buff, errorString + i*n, n);
- buff[n] = '\0';
- drawScaledAndAlignedString((int)( 120 ), (int)( 360 - i*20 ), 1.0f, 1.0f,
- Gui::info.var.menu_smallFont, TEXT_ALIGN_LEFT, buff);
- }
-
- }
-