Back to index

supertuxkart  0.5+dfsg1
base_gui.cpp
Go to the documentation of this file.
00001 //  $Id: base_gui.cpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 SuperTuxKart-Team
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 <SDL/SDL.h>
00021 
00022 #include "base_gui.hpp"
00023 #include "widget_manager.hpp"
00024 #include "world.hpp"
00025 #include "menu_manager.hpp"
00026 void
00027 BaseGUI::animateWidget(const int PREV_SELECTED_WGT, const int SELECTED_WGT)
00028 {
00029        if( SELECTED_WGT != WidgetManager::WGT_NONE )
00030        {
00031               if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
00032               {
00033                      widget_manager->darkenWgtColor( PREV_SELECTED_WGT );
00034               }
00035 
00036               widget_manager->lightenWgtColor( SELECTED_WGT );
00037               widget_manager->pulseWgt( SELECTED_WGT );
00038        }
00039 }
00040 
00041 //-----------------------------------------------------------------------------
00042 void
00043 BaseGUI::handle(GameAction action, int value)
00044 {
00045     if( m_locked ) return;
00046 
00047     // Skip on keypress, act on keyrelease only.
00048     if (value) return;
00049 
00050        int previous = widget_manager->getSelectedWgt();
00051 
00052     switch ( action )
00053     {
00054     case GA_CURSOR_LEFT:
00055               animateWidget(previous,
00056                                      widget_manager->handleLeft());
00057 
00058               break;
00059     case GA_CURSOR_RIGHT:
00060               animateWidget(previous,
00061                                      widget_manager->handleRight());
00062               break;
00063     case GA_CURSOR_UP:
00064               animateWidget(previous,
00065                                      widget_manager->handleUp());
00066               break;
00067     case GA_CURSOR_DOWN:
00068               animateWidget(previous,
00069                                      widget_manager->handleDown());
00070               break;
00071        case GA_INC_SCROLL_SPEED:
00072               widget_manager->increaseScrollSpeed();
00073               break;
00074        case GA_INC_SCROLL_SPEED_FAST:
00075               widget_manager->increaseScrollSpeed(true);
00076               break;
00077        case GA_DEC_SCROLL_SPEED:
00078               widget_manager->decreaseScrollSpeed();
00079               break;
00080        case GA_DEC_SCROLL_SPEED_FAST:
00081               widget_manager->decreaseScrollSpeed(true);
00082               break;
00083     case GA_ENTER:
00084         select();
00085         break;
00086     case GA_LEAVE:
00087         if (menu_manager->getMenuStackSize() > 1)
00088         {
00089            if(menu_manager->isCurrentMenu(MENUID_RACEMENU))
00090              world->unpause();
00091 
00092            menu_manager->popMenu();
00093         }
00094         break;
00095 
00096     default:
00097         break;
00098     }   // switch
00099 }   // handle
00100 //-----------------------------------------------------------------------------
00101 void
00102 BaseGUI::inputPointer(int x, int y)
00103 {
00104     if( m_locked ) return;
00105 
00106     const int PREV_SELECTED_WGT = widget_manager->getSelectedWgt();
00107     const int SELECTED_WGT = widget_manager->handlePointer( x, y );
00108 
00109     if( SELECTED_WGT != WidgetManager::WGT_NONE )
00110     {
00111         if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
00112         {
00113             widget_manager->darkenWgtColor( PREV_SELECTED_WGT );
00114         }
00115 
00116         widget_manager->lightenWgtColor( SELECTED_WGT );
00117         widget_manager->pulseWgt( SELECTED_WGT );
00118     }
00119 }
00120 
00121 //-----------------------------------------------------------------------------
00122 void
00123 BaseGUI::update(float dt)
00124 {
00125     widget_manager->update(dt);
00126 }   // update
00127 
00128 //-----------------------------------------------------------------------------
00129 void
00130 BaseGUI::TimeToString(const double TIME, char *s)
00131 {
00132     int min     = (int) floor ( TIME / 60.0 ) ;
00133     int sec     = (int) floor ( TIME - (double) ( 60 * min ) ) ;
00134     int tenths  = (int) floor ( 10.0f * (TIME - (double)(sec + 60* min)));
00135     sprintf ( s, "%d:%02d:%d", min,  sec,  tenths ) ;
00136 }   // TimeToString
00137 //-----------------------------------------------------------------------------
00138 void
00139 BaseGUI::inputKeyboard(SDLKey, int)
00140 {
00141        // This method is not supposed to be called since BaseGUI does not
00142        // handle low-level keyboard input.
00143        assert(false);
00144 }
00145 
00146 //-----------------------------------------------------------------------------
00147 void BaseGUI::countdown()
00148 {
00149 }
00150 /* EOF */