Back to index

extremetuxracer  0.5beta
configuration.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 "configuration.h"
00022 
00023 #include "ppgltk/button.h"
00024 #include "ppgltk/audio/audio.h"
00025 
00026 static game_mode_t preConfigMode = NO_MODE;
00027 
00028 
00029 Configuration::Configuration()
00030 {
00031   play_music( "options_screen" );
00032        if(GameMode::prevmode==GAME_TYPE_SELECT || GameMode::prevmode == PAUSED){
00033               preConfigMode = GameMode::prevmode;
00034        }
00035        
00036        pp::Vec2d pos(0,0);
00037        
00038        mp_titleLbl = new pp::Label(pos,"heading",_("Configuration"));
00039        mp_titleLbl->alignment.center();
00040        mp_titleLbl->alignment.middle();   
00041        
00042        mp_graphicsBtn = new pp::Button(pos,
00043                                  pp::Vec2d(300, 40),
00044                                  "button_label",
00045                                  _("Graphics") );
00046     mp_graphicsBtn->setHilitFontBinding( "button_label_hilit" );
00047     mp_graphicsBtn->signalClicked.Connect(pp::CreateSlot(this,&Configuration::graphics));
00048        
00049        mp_videoBtn = new pp::Button(pos,
00050                                  pp::Vec2d(300, 40), 
00051                                  "button_label", 
00052                                  _("Video") );
00053     mp_videoBtn->setHilitFontBinding( "button_label_hilit" );
00054        mp_videoBtn->signalClicked.Connect(pp::CreateSlot(this,&Configuration::video));     
00055 
00056        mp_audioBtn = new pp::Button(pos,
00057                                  pp::Vec2d(300, 40), 
00058                                  "button_label", 
00059                                  _("Audio") );
00060     mp_audioBtn->setHilitFontBinding( "button_label_hilit" );
00061        mp_audioBtn->signalClicked.Connect(pp::CreateSlot(this,&Configuration::audio));     
00062 
00063        mp_keyboardBtn = new pp::Button(pos,
00064                                  pp::Vec2d(300, 40), 
00065                                  "button_label", 
00066                                  _("Keyboard") );
00067        mp_keyboardBtn->setHilitFontBinding( "button_label_hilit" );
00068        mp_keyboardBtn->signalClicked.Connect(pp::CreateSlot(this,&Configuration::keyboard));      
00069 
00070        mp_joystickBtn = new pp::Button(pos,
00071                                  pp::Vec2d(300, 40), 
00072                                  "button_label", 
00073                                  _("Joystick") );
00074        mp_joystickBtn->setHilitFontBinding( "button_label_hilit" );
00075        mp_joystickBtn->signalClicked.Connect(pp::CreateSlot(this,&Configuration::joystick));      
00076 
00077 
00078     mp_backBtn = new pp::Button(pos,
00079                                  pp::Vec2d(300, 40), 
00080                                  "button_label", 
00081                                  _("Back") );
00082     mp_backBtn->setHilitFontBinding( "button_label_hilit" );
00083     mp_backBtn->signalClicked.Connect(pp::CreateSlot(this,&Configuration::back));          
00084 }
00085 
00086 Configuration::~Configuration()
00087 {
00088        delete mp_graphicsBtn;
00089        delete mp_videoBtn;
00090        delete mp_audioBtn;
00091        delete mp_keyboardBtn;
00092        delete mp_joystickBtn;
00093        delete mp_backBtn;
00094        delete mp_titleLbl;
00095 }
00096 
00097 void
00098 Configuration::loop(float timeStep)
00099 {
00100        update_audio();
00101     set_gl_options( GUI );
00102     clear_rendering_context();
00103     UIMgr.setupDisplay();
00104        drawSnow(timeStep);
00105        theme.drawMenuDecorations();
00106        setWidgetPositions();
00107     UIMgr.draw();
00108     reshape( getparam_x_resolution(), getparam_y_resolution() );
00109     winsys_swap_buffers();  
00110 }
00111 
00112 void
00113 Configuration::setWidgetPositions()
00114 {
00115        int w = getparam_x_resolution();
00116     int h = getparam_y_resolution();
00117        
00118        pp::Vec2d pos(w/2,h/2+100);
00119 
00120        mp_titleLbl->setPosition(pos);
00121        
00122        pos.x-=150;
00123        pos.y-=80;
00124        mp_graphicsBtn->setPosition(pos);
00125        pos.y-=40;
00126        mp_videoBtn->setPosition(pos);
00127        pos.y-=40;
00128        mp_audioBtn->setPosition(pos);
00129        pos.y-=40;
00130        mp_keyboardBtn->setPosition(pos);
00131        pos.y-=40;
00132        mp_joystickBtn->setPosition(pos);
00133        pos.y-=60;
00134        mp_backBtn->setPosition(pos);      
00135 }
00136 
00137 bool
00138 Configuration::keyPressEvent(unsigned int key)
00139 {
00140        switch (key){
00141               case 27:
00142               case 'q':
00143                      back();
00144               return true;
00145        }      
00146        return false;
00147 }
00148 
00149 void
00150 Configuration::back()
00151 {
00152        set_game_mode( preConfigMode );
00153        preConfigMode = NO_MODE;
00154     UIMgr.setDirty();
00155 }
00156 
00157 void
00158 Configuration::graphics()
00159 {
00160        set_game_mode( CONFIG_GRAPHICS );
00161     UIMgr.setDirty();
00162 }
00163 
00164 void
00165 Configuration::video()
00166 {
00167        set_game_mode( CONFIG_VIDEO );
00168     UIMgr.setDirty();
00169 }
00170 
00171 void
00172 Configuration::audio()
00173 {
00174        set_game_mode( CONFIG_AUDIO );
00175     UIMgr.setDirty();
00176 }
00177 
00178 void
00179 Configuration::keyboard()
00180 {
00181        set_game_mode( CONFIG_KEYBOARD );
00182     UIMgr.setDirty();
00183 }
00184 
00185 void
00186 Configuration::joystick()
00187 {
00188        set_game_mode( CONFIG_JOYSTICK );
00189     UIMgr.setDirty();
00190 }