Back to index

supertuxkart  0.5+dfsg1
display_res_confirm.cpp
Go to the documentation of this file.
00001 //  $Id: display_res_confirm.cpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2008 Paul Elms
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include <iostream>
00021 #include <sstream>
00022 
00023 #include "display_res_confirm.hpp"
00024 #include "menu_manager.hpp"
00025 #include "widget_manager.hpp"
00026 #include "translation.hpp"
00027 #include "user_config.hpp"
00028 #include "sdldrv.hpp"
00029 
00030 
00031 #if defined(WIN32) && !defined(__CYGWIN__)
00032 #  define snprintf _snprintf
00033 #endif
00034 
00035 enum WidgetTokens
00036 {
00037     WTOK_TITLE,
00038     WTOK_APPLY_RES,
00039 
00040     WTOK_QUIT
00041 };
00042 
00043 
00044 DisplayResConfirm::DisplayResConfirm( const bool FROM_WINDOW_ ) :
00045     FROM_WINDOW (FROM_WINDOW_)
00046 {
00047     m_counter = 5; // Number of seconds in which to confirm
00048 
00049     widget_manager->switchOrder();
00050     widget_manager->addTitleWgt( WTOK_TITLE, 70, 7,
00051         _("Confirm Resolution Within 5 Seconds"));
00052 
00053     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 40, 2);
00054 
00055     widget_manager->addTextButtonWgt( WTOK_APPLY_RES, 40, 7, _("Confirm Resolution") );
00056 
00057     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 40, 2);
00058 
00059     widget_manager->addTextButtonWgt( WTOK_QUIT, 40, 7, _("Press <ESC> to Cancel") );
00060     widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML );
00061 
00062     widget_manager->layout( WGT_AREA_ALL );
00063 
00064     m_timer = SDL_AddTimer(1000,timeout,NULL);
00065     if (m_timer == NULL)
00066     {
00067         std::cerr << "Warning: Timer could not be initialised!\n";
00068     }
00069 }
00070 
00071 //-----------------------------------------------------------------------------
00072 DisplayResConfirm::~DisplayResConfirm()
00073 {
00074     widget_manager->reset();
00075 }
00076 
00077 //-----------------------------------------------------------------------------
00078 void DisplayResConfirm::select()
00079 {
00080     switch ( widget_manager->getSelectedWgt())
00081     {
00082     case WTOK_APPLY_RES:
00083         user_config->m_prev_width = user_config->m_width;
00084         user_config->m_prev_height = user_config->m_height;
00085 
00086         SDL_RemoveTimer(m_timer);
00087         menu_manager->popMenu();
00088         break;
00089     case WTOK_QUIT:
00090         SDL_RemoveTimer(m_timer);
00091         if (FROM_WINDOW)
00092         {
00093             inputDriver->toggleFullscreen();
00094             user_config->m_crashed = false;
00095             user_config->saveConfig();
00096         }
00097         menu_manager->popMenu();
00098         break;
00099     default: break;
00100     }
00101 }
00102 
00103 //-----------------------------------------------------------------------------
00104 void DisplayResConfirm::countdown()
00105 {
00106     if (m_counter > 1)
00107     {
00108         m_counter--;
00109         snprintf(m_count, MAX_MESSAGE_LENGTH, _("Confirm Resolution Within %d Seconds"), m_counter);
00110         widget_manager->setWgtText( WTOK_TITLE, m_count );
00111     }
00112     else
00113     {
00114         SDL_RemoveTimer(m_timer);
00115 
00116         // blacklist the resolution
00117         std::ostringstream o;
00118         o << user_config->m_width << "x" << user_config->m_height;
00119         user_config->m_blacklist_res.push_back (o.str());
00120 
00121         if( FROM_WINDOW )
00122         {
00123             inputDriver->toggleFullscreen();
00124             user_config->m_prev_windowed = false;
00125             user_config->m_crashed = false;
00126             user_config->saveConfig();
00127         }
00128 
00129 
00130         menu_manager->popMenu();
00131     }
00132 }
00133 //-----------------------------------------------------------------------------
00134 void DisplayResConfirm::handle(GameAction ga, int value)
00135 {
00136     switch ( ga )
00137     {
00138     case GA_LEAVE:
00139         if (value)
00140             break;
00141               SDL_RemoveTimer(m_timer);
00142         if (FROM_WINDOW)
00143         {
00144             inputDriver->toggleFullscreen();
00145             user_config->m_crashed = false;
00146             user_config->saveConfig();
00147         }
00148         menu_manager->popMenu();
00149         break;
00150 
00151     default:
00152         BaseGUI::handle(ga, value);
00153         break;
00154     }
00155 }
00156 
00157 //=============================================================================
00158 Uint32 timeout(Uint32 interval, void *param)
00159 {
00160         SDL_Event event;
00161         SDL_UserEvent userevent;
00162 
00163         userevent.type = SDL_USEREVENT;
00164         userevent.code = 0;
00165         userevent.data1 = NULL;
00166         userevent.data2 = NULL;
00167 
00168         event.type = SDL_USEREVENT;
00169         event.user = userevent;
00170 
00171         SDL_PushEvent(&event);
00172 
00173         return (interval);
00174 }
00175