SoundDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D 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 Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <dialogs/SoundDialog.h>
00022 #include <graph/OptionsDisplay.h>
00023 #include <sound/Sound.h>
00024 #include <GLW/GLWTextButton.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <GLW/GLWSlider.h>
00027 
00028 SoundDialog *SoundDialog::instance_ = 0;
00029 
00030 SoundDialog *SoundDialog::instance()
00031 {
00032         if (!instance_)
00033         {
00034                 instance_ = new SoundDialog;
00035         }
00036         return instance_;
00037 }
00038 
00039 SoundDialog::SoundDialog() :
00040         GLWWindow("Sound", 10.0f, 10.0f, 300.0f, 70.0f, eSmallTitle,
00041                 "Allow the user to change sound settings")
00042 {
00043         needCentered_ = true;
00044 
00045         {
00046         GLWPanel *soundVolumePanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00047         soundVolumePanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("SOUND_VOLUME", "Sound Volume    ")), 0, SpaceRight, 10.0f);
00048         soundVolume_ = new GLWSlider(0.0f, 0.0f, 300.0f);
00049         soundVolumePanel->addWidget(soundVolume_, 0, AlignCenterLeftRight);
00050         soundVolumePanel->setLayout(GLWPanel::LayoutHorizontal);
00051         addWidget(soundVolumePanel, 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00052         }
00053 
00054         {
00055         GLWPanel *ambientSoundVolumePanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00056         ambientSoundVolumePanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("AMBIENT_VOLUME", "Ambient Volume")), 0, SpaceRight, 10.0f);
00057         ambientSoundVolume_ = new GLWSlider(0.0f, 0.0f, 300.0f);
00058         ambientSoundVolumePanel->addWidget(ambientSoundVolume_, 0, AlignCenterLeftRight);
00059         ambientSoundVolumePanel->setLayout(GLWPanel::LayoutHorizontal);
00060         addWidget(ambientSoundVolumePanel, 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00061         }
00062 
00063         {
00064         GLWPanel *musicVolumePanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00065         musicVolumePanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("MUSIC_VOLUME", "Music Volume    ")), 0, SpaceRight, 10.0f);
00066         musicVolume_ = new GLWSlider(0.0f, 0.0f, 300.0f);
00067         musicVolumePanel->addWidget(musicVolume_, 0, AlignCenterLeftRight);
00068         musicVolumePanel->setLayout(GLWPanel::LayoutHorizontal);
00069         addWidget(musicVolumePanel, 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00070         }
00071 
00072         GLWPanel *checkPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00073         noSoundBox_ = new GLWCheckBoxText(0.0f, 0.0f, LANG_RESOURCE("NO_SOUND", "No Sound"));
00074         checkPanel->addWidget(noSoundBox_, 0, SpaceRight, 10.0f);
00075         noMusicBox_ = new GLWCheckBoxText(0.0f, 0.0f, LANG_RESOURCE("NO MUSIC", "No Music"));
00076         checkPanel->addWidget(noMusicBox_);
00077         checkPanel->setLayout(GLWPanel::LayoutHorizontal);
00078         addWidget(checkPanel, 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00079 
00080         GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00081         GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this, 
00082                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00083         cancelId_ = cancelButton->getId();
00084         buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00085         GLWButton *applyButton = new GLWTextButton(LANG_RESOURCE("APPLY", "Apply"), 235, 10, 110, this,
00086                 GLWButton::ButtonFlagCenterX);
00087         applyId_ = applyButton->getId();
00088         buttonPanel->addWidget(applyButton, 0, SpaceRight, 10.0f);
00089         GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 475, 10, 55, this, 
00090                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00091         okId_ = okButton->getId();
00092         buttonPanel->addWidget(okButton);
00093         buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00094         addWidget(buttonPanel, 0, SpaceAll, 10.0f);
00095 
00096         setLayout(GLWPanel::LayoutVerticle);
00097         layout();
00098 }
00099 
00100 SoundDialog::~SoundDialog()
00101 {
00102 }
00103 
00104 void SoundDialog::display()
00105 {
00106         GLWWindow::display();
00107 
00108         soundVolume_->setCurrent(
00109                 float(OptionsDisplay::instance()->getSoundVolume()) / 1.28f);
00110         ambientSoundVolume_->setCurrent(
00111                 float(OptionsDisplay::instance()->getAmbientSoundVolume()) / 1.28f);
00112         musicVolume_->setCurrent(
00113                 float(OptionsDisplay::instance()->getMusicVolume()) / 1.28f);
00114         noSoundBox_->getCheckBox().setState(
00115                 OptionsDisplay::instance()->getNoSound());
00116         noMusicBox_->getCheckBox().setState(
00117                 OptionsDisplay::instance()->getNoMusic());
00118 }
00119 
00120 void SoundDialog::buttonDown(unsigned int id)
00121 {
00122         if (id == okId_ || id == applyId_)
00123         {
00124                 OptionsDisplay::instance()->getNoSoundEntry().setValue(
00125                         noSoundBox_->getCheckBox().getState());
00126                 OptionsDisplay::instance()->getNoMusicEntry().setValue(
00127                         noMusicBox_->getCheckBox().getState());
00128 
00129                 int volume = int(soundVolume_->getCurrent() * 1.28f);
00130                 OptionsDisplay::instance()->getSoundVolumeEntry().setValue(volume);
00131                 Sound::instance()->getDefaultListener()->setGain(float(volume) / 128.0f);
00132 
00133                 volume = int(musicVolume_->getCurrent() * 1.28f);
00134                 OptionsDisplay::instance()->getMusicVolumeEntry().setValue(volume);
00135 
00136                 volume = int(ambientSoundVolume_->getCurrent() * 1.28f);
00137                 OptionsDisplay::instance()->getAmbientSoundVolumeEntry().setValue(volume);
00138         }
00139 
00140         if (id != applyId_)
00141         {
00142                 // Only hide the window if Ok or Cancel are hit!
00143                 GLWWindowManager::instance()->hideWindow(getId());
00144         }
00145 }

Generated on Mon Feb 16 15:14:38 2009 for Scorched3D by  doxygen 1.5.3