Back to index

extremetuxracer  0.5beta
configmode.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019  
00020  
00021 #include "configmode.h"
00022 
00023 ConfigMode::ConfigMode()
00024 {
00025        pp::Vec2d pos(0,0);
00026               
00027        mp_titleLbl = new pp::Label(pos,
00028                                    "heading", "");
00029        mp_titleLbl->alignment.center();
00030        mp_titleLbl->alignment.middle();
00031                                                         
00032        
00033        mp_cancelBtn = new pp::Button(pos,
00034                                  pp::Vec2d(300, 40),
00035                                  "button_label",
00036                                  _("Cancel") );
00037     mp_cancelBtn->setHilitFontBinding( "button_label_hilit" );
00038     mp_cancelBtn->signalClicked.Connect(pp::CreateSlot(this,&ConfigMode::cancel));
00039    
00040        mp_applyBtn = new pp::Button(pos,
00041                                  pp::Vec2d(300, 40), 
00042                                  "button_label", 
00043                                  _("Ok") );
00044     mp_applyBtn->setHilitFontBinding( "button_label_hilit" );
00045     mp_applyBtn->signalClicked.Connect(pp::CreateSlot(this,&ConfigMode::apply));
00046 }
00047 
00048 ConfigMode::~ConfigMode()
00049 {
00050        delete mp_cancelBtn;
00051        delete mp_applyBtn;
00052        delete mp_titleLbl;
00053 }
00054 
00055 void
00056 ConfigMode::loop(float timeStep)
00057 {
00058        update_audio();
00059     set_gl_options( GUI );
00060     clear_rendering_context();
00061     UIMgr.setupDisplay();
00062        
00063        drawTextandWidgets();
00064        
00065        // forces the config mode to update it's widget positions
00066        // perhaps we should call this only when the screen size changes
00067        setWidgetPositions();
00068        
00069        // calls the custom loop of the derived class (if it exists)
00070        customLoop( timeStep );
00071        
00072        // draw snow if enabled
00073        drawSnow( timeStep );
00074        
00075        theme.drawMenuDecorations();
00076        
00077        // draw ui widgets
00078     UIMgr.draw();
00079        
00080        
00081     reshape( getparam_x_resolution(), getparam_y_resolution() );
00082     winsys_swap_buffers();
00083 }
00084 
00085 void
00086 ConfigMode::drawTextandWidgets()
00087 {
00088        int w = getparam_x_resolution();
00089     int h = getparam_y_resolution();
00090 
00091        mp_cancelBtn->setPosition(pp::Vec2d(w/2-300,h/2-240));
00092        mp_applyBtn->setPosition(pp::Vec2d(w/2,h/2-240));
00093        mp_titleLbl->setPosition(pp::Vec2d(w/2,h/2+200));
00094 }
00095 
00096 bool
00097 ConfigMode::keyPressEvent(SDLKey key)
00098 {
00099        switch (key){
00100               case SDLK_ESCAPE:
00101                      cancel();
00102               return true;
00103               case SDLK_RETURN:
00104                      apply();
00105               return true;
00106               default:
00107                      return false;
00108        }
00109 }
00110 
00111 void
00112 ConfigMode::cancel()
00113 {
00114        set_game_mode( GameMode::prevmode );
00115     UIMgr.setDirty();
00116 }
00117 
00118 void
00119 ConfigMode::setTitle(const char* title)
00120 {
00121        mp_titleLbl->setText(title);
00122 }