Back to index

extremetuxracer  0.5beta
audioconfig.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 #include "audioconfig.h"
00021 
00022 #include "game_config.h"
00023 #include "ppgltk/ui_mgr.h"
00024 
00025 
00026 bps_t bps[] = {      {"8",0},
00027                                    {"16",1}};
00028                                           
00029 freq_t freqs[] = {   {"11025",0},
00030                                    {"22050",1},
00031                                    {"44100",2}};
00032 
00033 
00034 AudioConfig::AudioConfig()
00035 {
00036        setTitle(_("Audio Configuration"));
00037        pp::Vec2d pos(0,0);
00038        
00039        mp_audioBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
00040        mp_audioBox->setState( getparam_no_audio());
00041        
00042        mp_soundBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
00043        mp_soundBox->setState( getparam_sound_enabled());
00044               
00045        mp_musicBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
00046        mp_musicBox->setState( getparam_music_enabled());       
00047        
00048        mp_stereoBox = new pp::CheckBox(pos, pp::Vec2d(32, 32) );
00049        mp_stereoBox->setState( getparam_audio_stereo());
00050 
00051        //frequency
00052        std::list<freq_t>::iterator freqit;
00053        bool found=false;
00054        
00055        for (unsigned int i=0; i<sizeof(freqs)/sizeof(freq_t); i++) {
00056               m_freqList.push_back(freqs[i]);    
00057               if (freqs[i].data==getparam_audio_freq_mode()){
00058                      freqit = --m_freqList.end();
00059                      found=true;
00060               }
00061     }
00062        if(!found) freqit = m_freqList.begin();
00063        
00064        mp_freqListbox = new pp::Listbox<freq_t>( pos,
00065                                pp::Vec2d(150, 32),
00066                                "listbox_item",
00067                                m_freqList);
00068     mp_freqListbox->setCurrentItem( freqit );
00069        
00070        //bits per sample
00071        std::list<freq_t>::iterator bpsit;
00072        found=false;
00073        
00074        for (unsigned int i=0; i<sizeof(bps)/sizeof(bps_t); i++) {
00075               m_bpsList.push_back(bps[i]);       
00076               if (bps[i].data==getparam_audio_format_mode()){
00077                      bpsit = --m_bpsList.end();
00078                      found=true;
00079               }
00080     }
00081        if(!found) bpsit = m_bpsList.begin();
00082        
00083        mp_bpsListbox = new pp::Listbox<bps_t>( pos,
00084                                pp::Vec2d(150, 32),
00085                                "listbox_item",
00086                                m_bpsList);
00087     mp_bpsListbox->setCurrentItem( bpsit );
00088 
00089 }
00090 
00091 AudioConfig::~AudioConfig()
00092 {
00093        delete mp_audioBox;
00094        delete mp_soundBox;
00095        delete mp_musicBox;
00096        delete mp_stereoBox;
00097        delete mp_bpsListbox;
00098        delete mp_freqListbox;
00099 }
00100 
00101 void
00102 AudioConfig::setWidgetPositions()
00103 {
00104        int width = 500;
00105        int height = 240;
00106 
00107        pp::Vec2d pos(getparam_x_resolution()/2 - width/2,
00108                               getparam_y_resolution()/2 + height/2);
00109        
00110        pp::Font *font= pp::Font::get("button_label");
00111        
00112        font->draw(_("Sound Effects:"),pos);
00113        mp_soundBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
00114        
00115        pos.y-=40;
00116        font->draw(_("Music:"),pos);
00117        mp_musicBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
00118        
00119        pos.y-=80;
00120        font->draw(_("(needs restart)"),pos);
00121        pos.y-=40;
00122        font->draw(_("Disable Audio:"),pos);
00123        mp_audioBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
00124        
00125        pos.y-=40;
00126        font->draw(_("Stereo:"),pos);
00127        mp_stereoBox->setPosition(pp::Vec2d(pos.x+width-32,pos.y));
00128        
00129        pos.y-=40;
00130        font->draw(_("Bits Per Sample:"),pos);
00131        mp_bpsListbox->setPosition(pp::Vec2d(pos.x+width-150,pos.y));
00132        
00133        pos.y-=40;
00134        font->draw(_("Samples Per Second:"),pos);
00135        mp_freqListbox->setPosition(pp::Vec2d(pos.x+width-150,pos.y));
00136 }
00137 
00138 void
00139 AudioConfig::apply()
00140 {
00141        setparam_no_audio(bool( mp_audioBox->getState() ));
00142        setparam_sound_enabled(bool( mp_soundBox->getState() ));
00143        setparam_music_enabled(bool( mp_musicBox->getState() ));
00144        setparam_audio_stereo(bool( mp_stereoBox->getState() ));
00145        
00146        std::list<bps_t>::iterator bpsit = mp_bpsListbox->getCurrentItem();
00147        setparam_audio_format_mode((*bpsit).data);
00148               
00149        std::list<freq_t>::iterator freqit = mp_freqListbox->getCurrentItem();
00150        setparam_audio_freq_mode((*freqit).data);
00151               
00152        write_config_file();
00153        set_game_mode( GameMode::prevmode );
00154     UIMgr.setDirty();       
00155 }